Determine all the steps used to search for 9 in the list 2, 3, 5, 7, 8, 10, 12,
ID: 3008905 • Letter: D
Question
Determine all the steps used to search for 9 in the list 2, 3, 5, 7, 8, 10, 12, 13 using the Linear Search Algorithm on page 194 of the text. List, in order of execution, all the steps that change an assignment of the value of a variable.
A) i:= 1, i:= 2, i:= 3, i:= 4, i:= 5, i:= 6, location:= 0
B) i:= 1, i:= 2, i:= 3, i:= 4, i:= 5, i:= 6, location:= 9
C) i:= 1, i:= 2, i:= 3, i:= 4, i:= 5, i:= 6, i:= 7, i:= 8, location:= 0
D) i:= 1, i:= 2, i:= 3, i:= 4, i:= 5, i:= 6, i:= 7, i:= 8, location:= 9
E) i:= 1, i:= 2, i:= 3, i:= 4, i:= 5, i:= 6, i:= 7, i:= 8, i:= 9, location:= 0
Explanation / Answer
note : only question allowed per submission and these are five different questions with inadequate problem statement for the rest 4.
hence i will give you the solution of first and you can build accordingly.
1. Suppose you have list of 2, 3, 5, 7, 8, 10, 12, 13 and you have to find position of 9 and return the position
a. we start with assuming position of 9 to be 1 (the first element)
b. we begin searching and comparison to check we actually found out of 9
c. so 9 is not equal to 2 hence we move forward.
d. similarly 9 is not equal to 3. hence again move forward.
e. in a similar way we go on searchingeach element, if we find 9 we return position of 9
f. else return the position 0f 9 as 0.(as 0 repesents , element is not found)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.