Question: C++ only please. Write a program that randomly generates a list of 1000 numbers; make a copy to be used for both sorting algorithms. Please
Write a program that randomly generates a list of 1000 numbers; make a copy to be used for both sorting algorithms. Please note that you should seed the random number generator with a number that changes each time you run your program (a combination of PID and Time should help). Please also remember that you need to seed the random number only once (executed only one time). Sorting Part Sort the list once using the Selection Sort algorithm and once using the Insertion Sort algorithm. For each iteration, your program should keep track of 1. Number of key comparisons 2. Number of swaps At the end of each sort, your program must display the numbers mentioned in 1 and 2, above, for each algorithm. Searching Part: You also implement a recursive binary-search algorithm, using one of the sorted lists generated above I-This function stays in a loop prompting the user to enter a number to be searched. 2- Search for the first occurrence of the search number 3-During each search, you keep track of the number of comparisons. 4. It prints this number when the search is over s If the user enters a "O" (number zero), the search program terminates. Your main program should: Prompt the user with the number of times these algorithms should run (say 5 times). 2) Loop for the given number of times and each time: a. Generate an array of 1000 random numbers and make a c opy, so each copy is used by each algorithm. b. Run the 2 sorting algorithms and collect the aforementioned information. Print total number of key comparisons and swaps for each 3) Call the search function. 5) Terminate method. 4) Display your name
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
