Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain how to find the recurrence of the following code. Why is the answer T(6n/7) + O(1) and how I can solve a similar

Please explain how to find the recurrence of the following code. Why is the answer T(6n/7) + O(1) and how I can solve a similar question?

What is the recurrence for the worst-case runtime of the algorithm below?

The following algorithm takes as input a sorted array of integers A. left and right represent the left and right indicies of the array that is being searched. The parameter x represents an integer. The algorithm Search searches whether or not x is in the array A. If x is in the array, it returns the index of x. If x is not in the array, it returns -1. The function floor(a) returns the integer part of a. The initial call to Search is Search( A, 1, n, x ).

int Search(A,left,right,x) { numelements = right - left + 1;

if (numelements < 20) {

for (i = 0; i < numelements; i++){

if (A[left + i] == x) return (left + i);

}

return (-1);

} else {

split = floor(numelements * 1/7) + left;

if (A[split] == x) return(split);

if (A[split] > x) return(Search(A,left,split-1,x));

if (A[split] < x) return(Search(A,split,right,x)); } }

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_2

Step: 3

blur-text-image_3

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

4. Employ strategies to make your audience hungry for information

Answered: 1 week ago

Question

LO3 Discuss the steps of a typical selection process.

Answered: 1 week ago