// return index i such that A[i] = x, return -1 if x is not found int...

70.2K

Verified Solution

Question

Programming

// return index i such that A[i] = x, return -1 if x is notfound

int mysearch(A, left, right, x) {

//add statements

}

(a) (10 pts) Given a sorted array A of size n, i.e. data hasbeen sorted. Give a Divide and Conquer recursive “mysearch”algorithm which first tests the element at position n/4 forequality with some value x, and then possibly checks the element atposition 3n/4. The result is either discovering x or reducing theset size to a fraction of the original.

(b) (5 points) Give the recurrence equation of mysearchalgorithm.

(c) (5 points) Give the best-case and worst-case runtimecomplexity of mysearch algorithm? Explain your answer

(d) (5 points) What is the average-case runtime complexity ofmysearch algorithm? Explain your answer. Show transcribed imagetext // return index i such that A[i] = x, return -1 if x is notfound int mysearch(A, left, right, x) { //add statements }

Answer & Explanation Solved by verified expert
3.5 Ratings (423 Votes)
a Following is the implementation in Cincludeusing namespace std return index i such that Ai x return 1 if x is not foundint mysearchint A int left int right int x Base case The search    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students