Question

QUESTION 11 What is the runtime of Binary Search? a. O(n) b. Onlogn) c. Of(logn)) d. Odlogn)11

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer : d. O(log n)

Lets eloberate this , Binary search performed on sorted array and the sorted array is divided into half repeatedly. We will search for the value in the left half if the value is less than middle element or on the right half if searching value is greater than middle value. If the value is less than middle element then left half will be divided into two halfs...After every iteration the length of the searching space id going to be reduced .

At first iteration length  of the array is n

At second iteration length of the array is n/2

At third iteration length of the array is n/22 (n/4 )

At fourth iteration length of the array is n/23 (n/8)

After  kth iteration length of the array is n/2k

after k divisions length of the array is 1

lets put this into equation ...

n/2k = 1

n = 2k

log2(n) = log2(2k) ----->after appliying log on both sides

log2(n) = k log2(2) ----> loga(a) = 1

k = log2(n)   

Add a comment
Know the answer?
Add Answer to:
11 QUESTION 11 What is the runtime of Binary Search? a. O(n) b. Onlogn) c. Of(logn))...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT