Professional Documents
Culture Documents
01/11/2022 3
More Information
• Textbook
• Introduction to Algorithms 3rd ,Cormen,
Leiserson, Rivest and Stein, The MIT Press,
• Fundamentals of Computer Algorithms,
2nd, Sartaj Sahni, Ellis Horowitz,
Sanguthevar Rajasekaran
• Others
• Introduction to Design & Analysis
Computer Algorithm 3rd,
Sara Baase, Allen Van Gelder, Adison-
Wesley, 2000.
• Algorithms, Richard Johnsonbaugh, Marcus Schaefer, Prentice
Hall, 2004.
• Introduction to The Design and Analysis of Algorithms 2nd
Edition, Anany Levitin, Adison-Wesley, 2007.
SATPAL SINGH KUSHWAHA
01/11/2022 4
Course Objectives
• CS1501.1 Analyse the running times of algorithms using asymptotic analysis.
• CS1501.2 Demonstrate and Design algorithms using divide-and-
conquer paradigm to solve business problems hence enhance skills.
• CS1501.3 Illustrate the concept of greedy and dynamic-programming approach
to solve real life problems to enhance entrepreneurship capabilities.
• CS1501.4 Demonstrate the concept of backtracking and branch &
bound algorithms.
• CS1501.5 Synthesize and analyse various advanced algorithms concept such as
graphs, string matching, approximation algorithms and complexity classes to
enhance employability.
n
T (n) aT f (n)
b
where, a ≥ 1, b > 1, and f(n) > 0
Case 1: if f(n) = O(nlogba -) for some > 0, then: T(n) = (nlogba)
af(n/b) ≤ cf(n) for some c < 1 and all sufficiently large n, then:
T(n) = (f(n))
regularity condition
7
Idea of master theorem
Recursion tree:
f (n) f (n)
a
f (n/b) f (n/b) … f (n/b) a f (n/b)
h = logbn a
f (n/b2) f (n/b2) … f (n/b2) a2 f (n/b2)
…
#leaves = ah
…
…
CASE 1: The weight increases
…
…
…
Θ(f(n)).
To make sure the root actually does more work you need the
af(n/b)≤cf(n)
This says that f(n) (the amount of work done in the root) needs to be at least as big as
the sum of the work done in the lower levels. (The recurrence is called aa times on
n/b of the input.)
Idea of master theorem
Recursion tree:
f (n) f (n)
a
f (n/b) f (n/b) … f (n/b) a f (n/b)
h = logbn a
f (n/b2) f (n/b2) … f (n/b2) a2 f (n/b2)
…
CASE 3: The weight decreases
…
T(n) = 2T(n/2) + n
a = 2, b = 2, log22 = 1
T(n) = (nlgn)
19
Examples
T(n) = 2T(n/2) + n2
a = 2, b = 2, log22 = 1
Compare n with f(n) = n2
f(n) = (n1+) Case 3 verify regularity cond.
a f(n/b) ≤ c f(n)
2 n2/4 ≤ c n2 c = ½ is a solution (c<1)
T(n) = (n2)
20
Examples (cont.)
T(n) = 2T(n/2) + n
a = 2, b = 2, log22 = 1
T(n) = (n)
21
Examples
a = 3, b = 4, log43 = 0.793
a = 2, b = 2, log22 = 1
23
Examples
a = 8, b = 4, log48 = 2
24
Exercises
1. T(n) = 3T(n/5) + n
• 2. T(n) = 2T(n/2) - n
• 3. T(n) = 0.5T(n/2) + 1
• 4. T(n) = T(n/2) + n
But regularity condition not satisfied
So no solution using master theorem
• 5. T(n) = T(n/2) + 1