Harvard University Programming Recurrences Question

Question 2: Recurrences
(a) Below is the pseudo-code for two algorithms: Practicel(A,s,f) and Practice2(A,s,f), which take as
input a sorted array A, indexed from s to f. The algorithms make a call to Bsearch(A,s,f,k) which we
saw in class. Determine the worst-case runtime recurrence for each algorithm: Ti(n) and T2(n). Show that
Ti(n) is O(log n)?) and T2(n) is O(n log n).
Practicel(A,s,f)
if s< q1 = [(8 + f)/2] if BSearch(A,s,q1,1) = true return true else return Practicel(A, q1+1, f) else return false Practice2(A,s,f) if s < f if BSearch(A,s+1,f,1) = true return true else return Practice2(A, s, f-1) else return false to each of the following, or state that it does not apply: . (b) Apply the master theorem T(n) = T(n/3) + n log n • T(n) = 16T(n/4) + n1.5 log n T(n) = 4T(n/16) + Vn. = . (c) The recursive algorithm below takes as input an array A of distinct integers, indexed between s and f, and an integer k. The algorithm returns the index of the integer k in the array A, or -1 if the integer k is not contained within A. Complete the missing portion of the algorithm in such a way that you make three recursive calls to subarrays of approximately one third the size of A. • Write and justify a recurrence for the runtime T(n) of the above algorithm. • Use the recursion tree to show that the algorithm runs in time O(n). 2 FindK(A,s,f,k) if s < f if f =s +1 if k = A[s] return s if k = A[f] return f else ql = [(2s + f)/3] q2 = [(q1+1+1)/2] to be continued. else to be continued.

Calculate your order
275 words
Total price: $0.00

Top-quality papers guaranteed

54

100% original papers

We sell only unique pieces of writing completed according to your demands.

54

Confidential service

We use security encryption to keep your personal data protected.

54

Money-back guarantee

We can give your money back if something goes wrong with your order.

Enjoy the free features we offer to everyone

  1. Title page

    Get a free title page formatted according to the specifics of your particular style.

  2. Custom formatting

    Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.

  3. Bibliography page

    Don’t pay extra for a list of references that perfectly fits your academic needs.

  4. 24/7 support assistance

    Ask us a question anytime you need to—we don’t charge extra for supporting you!

Calculate how much your essay costs

Type of paper
Academic level
Deadline
550 words

How to place an order

  • Choose the number of pages, your academic level, and deadline
  • Push the orange button
  • Give instructions for your paper
  • Pay with PayPal or a credit card
  • Track the progress of your order
  • Approve and enjoy your custom paper

Ask experts to write you a cheap essay of excellent quality

Place an order