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).](https://content.bartleby.com/qna-images/question/fa06b614-497d-40f0-b077-f4b4fca47baf/9d4dc3ed-836e-4bc6-b9c4-0511abd24a0f/5i8r6du_thumbnail.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 4 steps with 8 images

Knowledge Booster
Similar questions
- 4. Given the following recursive definitionseq(1) = seq(2) = 1seq(n) = 2 ∗ seq(n − 1) + 3 ∗ seq(n − 2)implement the corresponding program and use it to calculate seq(5).How many invocations are made to the function seq when calculating seq(5)?arrow_forwardExercise: List the following functions by increasing order of growth. Here are the functions: f.(n) = n" f2(n) = n" f3(n) = (;) f4(n) = V2vn fs(n) = („",) fo(n) = 20ogn)* f;(n) = n5(log n)² f3 (n) = n* (")arrow_forwardGiven two sorted arrays, write a function to merge them into a single sorted array. What is the time complexity of your solution?arrow_forward
arrow_back_ios
arrow_forward_ios