Create (in C++) 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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 11PE
icon
Related questions
Question

Create (in C++) 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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning