117k views
2 votes
Consider the following algorithm, which takes as input asequence of n integers a1, a2, . . . , an and produces as outputa matrix M = {mij } where mij is the minimum termin the sequence of integers ai, ai+1, . . . , aj for j ? i andmij = 0 otherwise.initialize M so that mij = ai if j ? i and mij = 0otherwisefor i := 1 to nfor j := i + 1 to nfor k := i + 1 to jmij := min(mij, ak)return M= {mij } {mij is the minimum term ofai, ai+1, . . . , aj }a) Show that this algorithm uses O(n3) comparisons to compute the matrix M.

User Glarkou
by
4.5k points

1 Answer

2 votes

Answer and Explanation:

The answer is attached below

Consider the following algorithm, which takes as input asequence of n integers a1, a-example-1
Consider the following algorithm, which takes as input asequence of n integers a1, a-example-2
Consider the following algorithm, which takes as input asequence of n integers a1, a-example-3
Consider the following algorithm, which takes as input asequence of n integers a1, a-example-4
Consider the following algorithm, which takes as input asequence of n integers a1, a-example-5
User Viyancs
by
4.8k points