Consider the following algorithm which takes as input a


Question: Consider the following algorithm, which takes as input a sequence of n integers a1, a2,...,an and produces as output a matrix M = {mij } where mij is the minimum term in the sequence of integers ai, ai+1,...,aj for j ≥ i and mij = 0 otherwise.

procedure bit count (S: bit string)
count := 0
while S ≠ 0
count := count + 1
S := S Λ (S - 1)
return count {count is the number of 1s in S}

a) Show that this algorithm uses O(n3) comparisons to compute the matrix M.

b) Show that this algorithm uses (n3) comparisons to compute the matrix M. Using this fact and part (a), conclude that the algorithms uses (n3) comparisons.

[Hint: Only consider the cases where i ≤ n/4 and j ≥ 3n/4 in the two outer loops in the algorithm.]

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Consider the following algorithm which takes as input a
Reference No:- TGS02364015

Now Priced at $10 (50% Discount)

Recommended (93%)

Rated (4.5/5)