Assignment 6A: Linear Search vs. Binary Search. In the lecture class, we have repeatedly claimed that binary search is faster than linear search on a sorted array. But don't take our word for it –...


LANGUAGE IS C++


searching and sorting while using arrays and nested for loops.


Assignment 6A: Linear Search vs. Binary Search. In the lecture class, we have repeatedly<br>claimed that binary search is faster than linear search on a sorted array. But don't take our word<br>for it – let's try to prove it by comparing the two!<br>In this lab, you will create an array of size one million (1,000,000). Fill it sequentially with<br>values (e.g. array[0] should equal 0, array[1] should equal 1, etc). Then the computer should<br>select a random target number between 0 and array size – 1. You should then search the array<br>for this value twice – once with a linear search algorithm, and then with a binary search<br>algorithm. Keep track of how long each one took, using the following criteria:<br>Linear Search: Number of loop iterations beſore the larget number was found<br>Binary Search: Number of midpoints chosen (a.k.a “guesses

Extracted text: Assignment 6A: Linear Search vs. Binary Search. In the lecture class, we have repeatedly claimed that binary search is faster than linear search on a sorted array. But don't take our word for it – let's try to prove it by comparing the two! In this lab, you will create an array of size one million (1,000,000). Fill it sequentially with values (e.g. array[0] should equal 0, array[1] should equal 1, etc). Then the computer should select a random target number between 0 and array size – 1. You should then search the array for this value twice – once with a linear search algorithm, and then with a binary search algorithm. Keep track of how long each one took, using the following criteria: Linear Search: Number of loop iterations beſore the larget number was found Binary Search: Number of midpoints chosen (a.k.a “guesses") taken before the target number was found Once both algorithms have been run, display the results and print which algorithm found the number first (or if there was a tie). Sample Output #1: Comparing Linear Search and Binary Search: Our target is 307620 Linear Search: 307621 loop(s) Binary Search: 20 guess(es) Binary Search is faster this time! Sample Output #2: Comparing Linear Search and Binary Search: Our target is 1 Linear Search: 2 loop(s) Binary Search: 19 guess (es) Linear Search is faster this time!

Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here