a. Derive f(n), a function giving the number of comparisons performed by the BSA in terms of the size of the list n. For simplicity, assume n equals an integer power of 2; that is, n = 2k, k E N, the natural numbers (positive integers).

icon
Related questions
Question
The Binary Search Algorithm (BSA) is described by this pseudocode:
ALGORITHM 3 The Binary Search Algorithm.
procedure binary search (x: integer, a₁, 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
m := [(i+j)/2]
if x > am then i:=m+1
else j := m
if x = a; then location := i
else location : 0
return location{location is the subscript i of the term a; equal to x, or 0 if x is not found}
a. Derive f(n), a function giving the number of comparisons performed by the BSA in
terms of the size of the list n. For simplicity, assume n equals an integer power of 2;
that is, n = 2k, k E N, the natural numbers (positive integers).
Transcribed Image Text:The Binary Search Algorithm (BSA) is described by this pseudocode: ALGORITHM 3 The Binary Search Algorithm. procedure binary search (x: integer, a₁, 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 m := [(i+j)/2] if x > am then i:=m+1 else j := m if x = a; then location := i else location : 0 return location{location is the subscript i of the term a; equal to x, or 0 if x is not found} a. Derive f(n), a function giving the number of comparisons performed by the BSA in terms of the size of the list n. For simplicity, assume n equals an integer power of 2; that is, n = 2k, k E N, the natural numbers (positive integers).
Expert Solution
steps

Step by step

Solved in 4 steps with 8 images

Blurred answer