Given an array s s1 s2 sn and n 2d for some d ge 1 we


Given an array s =(s[1], s[2], . . . , s[n]), and n = 2^d for some d ≥ 1. We want to find the minimum and maximum values in s. We do this by comparing elements of s.

(a) The "obvious" algorithm makes 2n - 2 comparisons. Explain.

(b) Can we do it better? Carefully specify a more efficient divide-and-conquer algorithm.

(c) Let T(n) = the number of comparisons your algorithm makes. Write a recurrencerelation for T(n).

(d) Show that your recurrence relation has as its solution T(n) = 3n/2 - 2.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Given an array s s1 s2 sn and n 2d for some d ge 1 we
Reference No:- TGS01244426

Now Priced at $10 (50% Discount)

Recommended (94%)

Rated (4.6/5)