Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following question and justify your answers Exercise I (50 points) Binary Search Consider the algorithm binarySearch(A, p. r. x: the description of

Please answer the following question and justify your answers image text in transcribed
Exercise I (50 points) Binary Search Consider the algorithm binarySearch(A, p. r. x: the description of this algorithm is provided below. Inputs: - a sorted arrayA - index p of the first element - index r of last element - an element x to search Output index of element x in Sequence A if x exists in A -I if x does not exist in Sequence A - Algorithm description int binarySearch (A, p, r, x) if (r >= 1) midpoint (p r)/2: if A[midpoint] x return midpoint; if A[midpoint] >x return binarySearch (A, p, midpoint-1, x): else return binarySearch (A, midpoint+l, r, x) return -1; The objective of this exercise is to derive the time complexity (running) time of the binary search. (If l) (6 points) Let A (2, 5, 9, 13, 18, 27, 34, 35, 39, 56, 63, 68, 71, 101). Assume that the index of the interested, you could read about binary search on Wikipedia) first element is I a. Execute manually binarySearch(A.I, A.length, 63). What is the output? b. Execute manually binarySearch(A.I, A.length, 27). What is the output? c. Execute manually binarySearch(A,I, A.length, 2). What is the output? d. Execute manually binarySearch(A,I, A.length, 101). What is the output? 2) (2 points) Which operation should you count to determine the running time T(n) of the binary search in a sequence A of length n? 3) (12 points) Let us count the comparisons ((if A(midpoint]x)and (if A (nidpoint] >x) Express the running time T(n) as a recurrence relation. 4) (12 points) Solve the recurrence relation T(n) using the recursion-tree method 5) (8 points) Solve the recurrence relation T(n) using the substitution method 6) (10 points) Solve the recurrence relation T(n) using the master method

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

Step: 3

blur-text-image

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions