QUESTION IMAGE
Question
which statement about the following pseudocode is correct?
1 start
2 declarations
3 string author
4 num size = 6
5 string stocked_authorssize = \christie\, \davis\, \dexter\, \doyle\, \grimes\
6 num index
7 string matchfound
8 matchfound =
o\
9 index = 0
10 output \enter the last name of the desired author: \
11 input author
12 while index < size
13 if author = stocked_authorsindex then
14 matchfound = \yes\
15 output \good news: books by \, author, \are available.\
16 endif
17 index = index + 1
18 endwhile
19 if matchfound =
o\ then
20 output \sorry, but we dont stock books by \, author
21 endif
22 stop
a. line 9 of this program will initialize a flag variable.
b. this program will perform a binary search.
c. the loop that begins on line 12 will exit when the users desired author is found in the array.
d. this program will compare each element in stocked_authors with the variable author.
- Option a: Line 9 initializes
indexto 0, not a flag variable (the flag ismatchFoundinitialized at line 8). So a is incorrect. - Option b: The program uses a linear search (checks elements one by one in order), not binary search (which requires a sorted list and dividing the search space). So b is incorrect.
- Option c: The loop (line 12) runs while
index < SIZE, so it will iterate through all elements (even if a match is found early) because there's nobreakor exit condition other thanindexreachingSIZE. So c is incorrect. - Option d: The loop (line 12 - 18) iterates through each index of
STOCKED_AUTHORS, and theifstatement (line 13) compares theauthorinput withSTOCKED_AUTHORS[index]for each element. So d is correct.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
d. This program will compare each element in STOCKED_AUTHORS with the variable author.