Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The binarySearch algorithm of Section 5.2.2 first checks whether the target is equal to the current middle entry, before proceeding to the left or right

The binarySearch algorithm of Section 5.2.2 first checks whether the target is equal to the current middle entry, before proceeding to the left or right halves if required. There is another variant of binary search which postpones the equality check until the very end. This version is presented belowwe call it lazy binary search:

(a) Trace this algorithm on the example array of Section 5.2.2 with 19 as the target. How many comparisons does it make?

(b) Trace the algorithm on this array with 26 as the target. What is the number of comparisons made?

(c) How many comparisons does this algorithm makes in general for an array of size n? Give an exact figure, not big O.

(d) Under what conditions is it preferable to use this version instead of the original binary search version?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions