E Chapter 2, Problem 13E Bokmark Show all steps Modify the sequential search alg
ID: 3879286 • Letter: E
Question
E Chapter 2, Problem 13E Bokmark Show all steps Modify the sequential search algorithm of Figure 2.13 so that it works correctly even if the numbers in the reverse directory are not unique, that is, if the desired number occurs more than once. (For example, a single number may be listed separately under the husband's name and the wife's name.) Your modified algorithm should find every occurrence of NUMBER in the directory and print the name corresponding to every match. In addition, after all the names have been displayed, your algorithm should print how many occurrences were located. For example, if NUMBER occurred twice, the output of the algorithm might look something like this: Susan Doe John Doe A total of two occurrences were located Figure 2.13 Step Operation 1 Get values for NLIMBER TT and N Set the value of ito 1 and set the value of Faund to NO Pint the name of the conesponding pason, N Ese ONUMBER is not equal to T Add 1 to the value of i Print the message Somy, this number is not in the dinectory The sequential search algorithm e here to search 96 8 3 4 5 6Explanation / Answer
Get values for NUMBER, T1...T10000 and N1...N10000
Set the value of i to 1, set the value of FOUND to NO, set the value of COUNT to 0
while (i<10,000) do steps 4 through 7
if NUMBER is equal to the ith number on the list , Ti then
print the name of the corresponding person, Ni
Set the value of FOUND to YES
Add 1 to the value of COUNT
Add 1 to the value of i
if(FOUND=YES) then
Print the message "A total of (value of COUNT) occurrences were located."
else
Print the message "Sorry, this number is not in the directory"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.