Problem

a. Here is pseudocode for a program that inputs a value n from the user and then inserts n...

a. Here is pseudocode for a program that inputs a value n from the user and then inserts n random numbers, ensuring that there are no duplicates:

Implement this program with your own linear search routine and add wrapper code that will time how long it takes to run. Test the program for different values of n. Depending on the speed of your system, you may need to input large values for n so that the program takes at least one second to run. Here is a sample that indicates how to calculate the difference in time (time.h is a library that should be available on your version of C++):

b. Next, create a second program that has the same behavior except that it uses an STL set to store the numbers instead of a vector:

Time your new program with the same values of n that you used in the vector version. What do the results tell you about the Big-O run time of the find() function for the set compared with linear search through the vector? Note that the find() function is really redundant because insert has no effect if the element is already in the set. However, use the find() function anyway to create a program comparable to the vector algorithm.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 19