Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(10 points) Consider the problem of finding the index l (with 1ln ) of a key, k, in an array A[1n] such that A[l]=k. Suppose
(10 points) Consider the problem of finding the index l (with 1ln ) of a key, k, in an array A[1n] such that A[l]=k. Suppose that A[1n] is sorted. Write the pseudocode of an algorithm, called find-in-halves, solving this problem using the divide an conquer technique: find-in-halves looks for k in the middle cell mid of the array A[ij]. If k=A[ mid ], it returns the index, mid, for this cell. Otherwise it compares k with the value of the middle cell, A[ mid ]. If k is smaller, it makes a recursive call looking for k in the first half of the array A[i..(mid1)]. If k is larger, make a recursive call looking for k in the second half of the array A[(mid+1)..j]. If k is not in A[ij], find-in-halves, it returns 1. The initial call is find-in-halves (A[1n]). (5 points) Follow step-by-step the pseudocode in question 2 for the array A[235711] and key=4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started