Multiple choices 47/50
(Choose 1 answer)
(See picture)
A. 3
B. 2
C. None of the other choices is correct
D. 4
Next
E. 5
Use the binary search algorithm to find the location of 10 in the sequence {1, 4, 5, 7, 8, 10, 12). How many iterations are needed?
ALGORITHM The Binary Search Algorithm.
procedure binary search (x: integer, a1, a2,..., an: increasing integers)i:= 1 {i is left endpoint of search interval}j:= n {j is right endpoint of search interval)while i < j begin end m:= [(i + j)/2]if xa, then i := m+1 else j := m if x = a; then location := i else location:= 0 (location is the subscript of the term equal to x, or 0 if x is not found)
1
2
3
4
5
6
7
8
9
10
11
12 13 14 15
16 17
18
19 20 21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 42
43
44
45 46 47 48
49 50