guys...could I ask for your help, I was given a programming assignment but I cant seem to understand the problem

heres the problem: write a program that creates an array of 100 random integers in the range from 1 to 200 and, then use a sequential search to search the array 100 times using randomly generated targets in the same range. at the end of the program, display the statistics of the number of searches it has completed, the number of successful searches, the percentage of successful searches and finally l the average number of test per search.


what i don't seem to understand is the is the use of the sequential search....should I generate one random number then search if it is in the array?? should i search the number a hundred times then after that generate another number to be searched or should I generate many random numbers and search it in the array? A successful search could be attained by searching the array just once...why do I have to search it a hundred times?

Recommended Answers

All 2 Replies

I think your professor means he wants you to search the array with 100 randomly generated numbers (a new random number to find for each search).

The only meaning I can get out of sequential search is just what you'd expect an unordered search to look like:
does elt 0 match? no... does elt 1 match? no... does elt 2 match? ...

You could always ask your professor for clarification.

Hope this helps.

I think you generate 100 random numbers in the range 1 to 200, and store them in an array.

Then you do 100 searches, each time generating a new random number, and using this newly generated random number to check if it is in the array (of random numbers created previously). You need to check :

a) that the (new) random number is in the array that you created previously
b) how many tests were required to find the random number in the array. I.e., you had to test array element 0, array element 1, array element 2, etc...
c) how many times out of the 100 newly generated random numbers did you find a match. I.e., if you only generate 50 new numbers that match those previously generated in the array, then you have a 50% success rate...
d) the number of searches completed...well you are only searching 100 times regardless, so I think this means the number of tests or comparisons used. That is, suppose that each time you search you had to go through the entire array of 100 elements, then you would have searched for a match 100*100, or 10,000 times.

But again, check with the prof to make sure!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.