Divide And Conquer-Complexity of Algorithms-Assignment, Exercises of Advanced Algorithms

This assignment was given by Manju Nripendra at West Bengal State University for Theory of Complexity and Algorithms course. It includes: Divide, Conquer, Algorithm, Psuedo, Code, Array, Paradigm, Asymptotic, Expression, Master, Method

Typology: Exercises

2011/2012

Uploaded on 07/17/2012

padmaghira
padmaghira 🇮🇳

3.2

(5)

53 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Divide-and-conquer
1. Describe a divide-and-conquer algorithm to find the minimum of a
set of nnumbers. Your algorithm should clearly describe how the
problem is divided into subproblems. Either give some psuedo-code
or describe your algorithm clearly in words. Assume that the set is
stored in an array A= [A[1], . . . , A[n]].
(Only a divide-and-conquer algorithm will be accepted here. Of course
you can find the minimum in time O(n), but the point is to understand
the divide-and-conquer paradigm.)
What is the running time of your algorithm?
2. Use the Master Method to find an asymptotic expression for T(n).
(Assume that T(n) = cfor nd, for some constants c > 0 and
d1.)
(a) T(n) = 2T(n/2) + log n
(b) T(n) = 7T(n/3) + n2
(c) T(n) = 9T(n/3) + n3log n
(d) T(n) = 16T(n/2) + (nlog n)4
(e) T(n) = 4T(n/2) + n2
(f) T(n) = 2T(n/2) + 10n
(g) T(n) = 8T(n/2) + 1000n2
(h) T(n) = 3T(n/3) + n
(i) T(n) = 2T(n/2) + nlog n
(j) T(n) = 3T(n/2) + n2
(k) T(n) = T(n/2) + 2n
3. Suppose that a queue has Npeople in it, where each person has a
different height from one another. At the front of the queue, you can
see Pdifferent people, and from the rear of the queue you can see
Rdifferent people (this is because of the differences in heights, tall
people block people shorter than themselves).
How many queues satisfy this property? Let Q(N, P, R) denote the
number of queues with this property. You want to find an expression
for Q(N, P, R) (given in terms of N , P, and R).
Hints:
1
docsity.com
pf2

Partial preview of the text

Download Divide And Conquer-Complexity of Algorithms-Assignment and more Exercises Advanced Algorithms in PDF only on Docsity!

Divide-and-conquer

  1. Describe a divide-and-conquer algorithm to find the minimum of a set of n numbers. Your algorithm should clearly describe how the problem is divided into subproblems. Either give some psuedo-code or describe your algorithm clearly in words. Assume that the set is stored in an array A = [A[1],... , A[n]].

(Only a divide-and-conquer algorithm will be accepted here. Of course you can find the minimum in time O(n), but the point is to understand the divide-and-conquer paradigm.)

What is the running time of your algorithm?

  1. Use the Master Method to find an asymptotic expression for T (n). (Assume that T (n) = c for n ≤ d, for some constants c > 0 and d ≥ 1.)

(a) T (n) = 2T (n/2) + log n (b) T (n) = 7T (n/3) + n^2 (c) T (n) = 9T (n/3) + n^3 log n (d) T (n) = 16T (n/2) + (n log n)^4 (e) T (n) = 4T (n/2) + n^2 (f) T (n) = 2T (n/2) + 10n (g) T (n) = 8T (n/2) + 1000n^2 (h) T (n) = 3T (n/3) +

n (i) T (n) = 2T (n/2) + n log n (j) T (n) = 3T (n/2) + n^2 (k) T (n) = T (n/2) + 2n

  1. Suppose that a queue has N people in it, where each person has a different height from one another. At the front of the queue, you can see P different people, and from the rear of the queue you can see R different people (this is because of the differences in heights, tall people block people shorter than themselves). How many queues satisfy this property? Let Q(N, P, R) denote the number of queues with this property. You want to find an expression for Q(N, P, R) (given in terms of N, P, and R).

Hints:

docsity.com

(a) First consider the case where one of P and R is equal to 1, i.e. the tallest person is standing at one end of the line. Find an expression for Q(N, P, 1) in terms of N and P. (First figure out for what values of N and P is this non-zero?)

(b) Second, note that Q(N, P, R) = Q(N, R, P ), i.e. it doesn’t matter what you consider the “front” and “rear” of the queue. (c) What happens when both P ≥ 2 and R ≥ 2? This means that the tallest person in the group is somewhere in the “middle” of the queue (i.e. is not on the end). This effectively divides the queue into two parts (which overlap on this common tallest person). In this case you want to find an expression for Q(N, P, R) in terms of (various values of) Q(N ′, P, 1) and Q(N ′′, 1 , R)(= Q(N ′′, R, 1) from the second hint) for appropriate values of N ′^ and N ′′. This last part is why this problem has a “divide-and-conquer” style of solution to it, if not exactly fitting into the Divide-and- Conquer type of problems we have discussed.

docsity.com