Create an array of size one million (1,000,019). Fill it in reverse sequentially with values (e.g. array[0] should equal 1,000,018, array[1] should equal 1,000,017, 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. Start searching from the end of the array, rather than the beginning. Keep track of how long each one took, using the following criteria: Linear Search: Number of loop iterations before the target 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). Once both algorithms have been run, display the results and print which algorithm found the number first (or if there was a tie). In the rest of this assignment, you’re going to create your own methods and call them from main.

icon
Related questions
Question

Create an array of size one million (1,000,019). Fill it in reverse sequentially with values (e.g. array[0] should equal 1,000,018, array[1] should equal 1,000,017, 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. Start searching from the end of the array, rather than the beginning.

Keep track of how long each one took, using the following criteria:

  • Linear Search: Number of loop iterations before the target 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).

Once both algorithms have been run, display the results and print which algorithm found the number first (or if there was a tie).

In the rest of this assignment, you’re going to create your own methods and call them from main. 

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Hi, thanks for your detailed answer but I didn't specify that this exercise is in C++ and not in Python.  Can you please answer it in C++ (sorry!!)

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, data-structures-and-algorithms and related others by exploring similar questions and additional content below.