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.
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.
Step by step
Solved in 4 steps with 2 images
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!!)