Consider the following algorithm, which takes as input a

Chapter 3, Problem 12E

(choose chapter or problem)

Get Unlimited Answers
QUESTION:

Problem 12E

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, …, ai for j  i and mij = 0 otherwise.

initialize M so that mij = a, if j  i and mij = 0 otherwise

for i := 1 to n

for j := i + 1 to n

for k := i + 1 to j

mij := min(mij, ak)

return M = {mij}{mij is the minimum term of ai, ai+1, …, aj}

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.]

Questions & Answers

QUESTION:

Problem 12E

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, …, ai for j  i and mij = 0 otherwise.

initialize M so that mij = a, if j  i and mij = 0 otherwise

for i := 1 to n

for j := i + 1 to n

for k := i + 1 to j

mij := min(mij, ak)

return M = {mij}{mij is the minimum term of ai, ai+1, …, aj}

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.]

ANSWER:

Solution:

Step 1

In this problem we need to show that the given algorithm uses  comparisons to compute the matrix M.

Add to cart


Study Tools You Might Need

Not The Solution You Need? Search for Your Answer Here:

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back