Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The sequential search algorithm of Figure 2.13 doesn\'t work when the numbers in

ID: 3879273 • Letter: T

Question

The sequential search algorithm of Figure 2.13 doesn't work when the numbers in the reverse directory are not unique.
For example, if Raj is listed with a number of 1234 and Maria also has the number 1234, the algorithm would only print the first person found and then stop.
Modify the algorithm so that it prints EVERY occurrence of NUMBER in the directory along with the name (Both Raj and Maria would print).
2) (2 points)
Modify your improved algorithm from #1 so that it also prints out the number of occurrences found. (In the case of Raj and Maria sharing the number 1234, the algorithm would print that there were 2 occurrences) on. ×@The Sequentia ×LA-Assignment /DInvitation toexeSharedwith mGw y/Downloads/GMichael%20Schneider%20Judith%20Gersting-Invitation%20to%20Computer%20Science-Cour Chapter 2Algorithm 1 FIGURE 2.13 Step Operation 1Get values for NUMBER., Thoao and N,.N.00 Set the value of i to 1 and set the value of Found to NO While botdFound = NO)and (i 10,000) do Steps 4 through 7 If NUMBER is equal to the ith number on the list, T, then Print the name of the corresponding person, N Set the value of Found to YES Else (NUMBER is not equal to T) Add 1 to the value of i 7 8 If (found = NO)then Print the message Sis umber is not in the direc 10 Stop The sequential search algorithm (which is not actually a valid telephone number according to the North American Numbering Plan that covers the United States, Canada, and many Caribbean islands). In all likelihood, a communications company located in

Explanation / Answer

Answer:

1) we need to remove (Found = NO) condition from while loop to work with not unique numbers.

Step       Operation

1      Get values for Number, T1, . . . , T10,000 and N1, . . . , N10,000

2      Set the value of i to 1 and value of Found to NO

3      While (i10,000) do steps 4 through 7

4                      If NUMBER is equal to the ith number on the list, Ti then

5                                      Print the name of the corresponding person, Ni

6                                      Set the value of Found to YES

Else (NUMBER is not equal to Ti)

7                                      Add 1 to the value of i

8      If(Found = NO) then

9                      Print the message ‘Sorry, this number is not in the directory’

10   Stop

2) We need to add a count variable and increment when ever we find a match

Step       Operation

1      Get values for Number, T1, . . . , T10,000 and N1, . . . , N10,000

2      Set the value of i to 1 and value of Found to NO

3      Set value of count to 0

4      While (i10,000) do steps 4 through 7

5                      If NUMBER is equal to the ith number on the list, Ti then

6                                      Print the name of the corresponding person, Ni

7                                      Set the value of Found to YES

8                                      Add 1 to the value of count

Else (NUMBER is not equal to Ti)

9                                      Add 1 to the value of i

10   If(Found = NO) then

11                   Print the message ‘Sorry, this number is not in the directory’

12   Else

13                   Print the message ‘There were’ + count + ‘occurences’

14   Stop

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote