Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question # 5 . By now you should be convinced that binary search requires fewer comparisons than linear search in both the worst case and

Question #5. By now you should be convinced that binary search requires fewer comparisons than linear search in both the worst case and the average case. However, keep in mind that binary search assumes that the elements are already in sorted order; if theyre not sorted, then it would take time to sort them before applying binary search, and sorting is a slow operation.
Whereas the number of operations in the worst case to conduct binary search on a collection of N items is approximately
log
2
log
2
N, the number of operations required to sort N items is
log
2
Nlog
2
N, i.e., the value of N times its base-2 logarithm.
Assume you have an unsorted collection of N =15 items, and you know you will need to make at least 10 searches and are concerned about the worst case. How would you determine whether it would be better to conduct 10 linear searches, or if it would be better to first sort the elements (which you only need to do once) and then conduct 10 binary searches?
In making this decision, follow these steps:
First, calculate the number of operations it would require to conduct 10 linear searches in the worst case.
Then, calculate the number of operations it would require to sort the elements once; for simplicity, round
log
2
15
log
2
15 up to 4.
Last, calculate the number of operations it would require to conduct 10 binary searches in the worst case.
Use the results of these three calculations to determine the answer.
Show the results of your calculations for steps 1-3 and then explain your answer in step 4.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions