logo

Crowdly

Browser

Add to Chrome

Recall binary search: BinarySearch(a[0..n-1], k) lo ← 0 hi ← n-1 WH...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Recall binary search:

BinarySearch(a[0..n-1], k)

lo ← 0

hi ← n-1

WHILE lo < hi

        mid ← (lo+hi) DIV 2

        IF a[mid] = k

                RETURN mid

        IF a[mid] < k

                lo ← mid+1

        IF a[mid] > k

                hi ← mid-1

RETURN -1;

where DIV is division discarding any remainder to return a whole number.

 

Given the following array:

 

01234567891011121314
BCFGJKMNPQSTUWY

 

How many values in the array will be examined in a binary search for the key K?

More questions like this

Want instant access to all verified answers on moodle4.city.ac.uk?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome