(a) Suppose we want to check if a sorted sequence A contains an element v. For this, we can use Binary Search. Binary Search compares the value at the midpoint of the sequence A with v and eliminates half of the sequence from further consideration. The Binary Search algorithm repeats this procedure, halving the size of the remaining portion of the sequence each time. Write a recurrence for the running time of Binary search and solve this recurrence. (b) Ternary Search is a generalization of Binary Search that can be used to find an element in an array. It divides the array with n elements into three parts and determines, with two comparisons, which part may contain the value we are searching for. For instance, initially, the array is divided into three thirds by taking mid1= [¹¹] and mid2 [2(n-¹)]. Write a recurrence for the running time of Ternary search and solve this recurrence. =

icon
Related questions
Question
3.
Binary search.
(a) Suppose we want to check if a sorted sequence A contains an element v. For this, we can use Binary
Search. Binary Search compares the value at the midpoint of the sequence A with v and eliminates
half of the sequence from further consideration. The Binary Search algorithm repeats this procedure,
halving the size of the remaining portion of the sequence each time. Write a recurrence for the running
time of Binary search and solve this recurrence.
(b) Ternary Search is a generalization of Binary Search that can be used to find an element in an array. It
divides the array with n elements into three parts and determines, with two comparisons, which part
may contain the value we are searching for. For instance, initially, the array is divided into three thirds
by taking mid1 = ["¹] and mid2 = [²(n-¹)]. Write a recurrence for the running time of Ternary
search and solve this recurrence.
Transcribed Image Text:3. Binary search. (a) Suppose we want to check if a sorted sequence A contains an element v. For this, we can use Binary Search. Binary Search compares the value at the midpoint of the sequence A with v and eliminates half of the sequence from further consideration. The Binary Search algorithm repeats this procedure, halving the size of the remaining portion of the sequence each time. Write a recurrence for the running time of Binary search and solve this recurrence. (b) Ternary Search is a generalization of Binary Search that can be used to find an element in an array. It divides the array with n elements into three parts and determines, with two comparisons, which part may contain the value we are searching for. For instance, initially, the array is divided into three thirds by taking mid1 = ["¹] and mid2 = [²(n-¹)]. Write a recurrence for the running time of Ternary search and solve this recurrence.
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer