Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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. Numbe 2. Number of swaps r of key comparisons 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 - 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 "" (number zero), the search program terminates. Your main program should: I) 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 copy, so each copy is used by each algorithm. b. Run the 2 sorting algorithms and collect the aforementioned information. c. Print total number of key comparisons and swaps for each method. 3) Call the search function 4) Display your name 5) Terminate

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions