Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 1: Solution
1. Prove the following.
(a) n Z, if n is odd then n2 is odd.
Solution:
Direct Proof. If n is odd we have n = 2k + 1 for some integer
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 3: Solution
1. Solve the following recurrences.
(a) T (n) = T (n/2) + O(n)
Solution:
T (n) = T (n/2) + O(n)
cn + T (n/2)
cn
+ T (n/4)
= cn +
2
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 4
Due: Monday, February 24, 2014 (during TA Office hours)
Note: Collaboration on homeworks is encouraged. However, you should think about the pr
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 2: Solution
1. Prove the following.
(a) (Optional ) a, b, c Z, if a2 + b2 = c2 , then a or b is even.
n
X
n(n + 1)(n + 2)
(b) (Optional ) n 0,
i
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 4: Solution
1. An inversion in an array A[1 . . n] is a pair of indices (i, j) such that i < j and A[i] > A[j].
The number of inversions in an n
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 6: Solution
1. We saw in class that after inserting an element in any AVL tree, we require a maximum of
one (single or double) rotation to resto
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 2
Due: Friday, February 07, 2014 (in class)
Note: Collaboration on homeworks is encouraged. However, you should think about the problems
yoursel
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 1
Due: Wednesday, January 29, 2014 (in class)
Note: Collaboration on homeworks is encouraged. However, you should think about the problems
yours
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 6
Due: Monday, April 07, 2014
Note: Collaboration on homeworks is encouraged. However, you should think about the problems
yourself before discu
Lahore University of Management Sciences
CMPE 510: Design & Analysis of Algorithms (Spring 2013-2014)
Homework 3
Due: Friday, February 14, 2014 (in class)
Note: Collaboration on homeworks is encouraged. However, you should think about the problems
yoursel