Unit V - DAA - Notes
Unit V - DAA - Notes
Deemed to be University
Core Values:
• Faith in God
• Moral Uprightness
• Love of Fellow Beings
• Social Responsibility
• Pursuit of Excellence
2
Excellence and Service
CHRIST
Deemed to be University
MISSION :
1. Imparts core and contemporary knowledge in the areas of Computation and
Information Technology
2. Promotes the culture of research and facilitates higher studies
3. Acquaints the students with the latest industrial practices, team building and
entrepreneurship
4. Sensitizes the students to serve for environmental, social & ethical needs of
society through lifelong learning.
3
Excellence and Service
CHRIST
Deemed to be University
4
Excellence and Service
CHRIST
Deemed to be University
5
Excellence and Service
CHRIST
Deemed to be University
6
Excellence and Service
CHRIST
Deemed to be University
DESIGN AND ANALYSIS OF ALGORITHMS (CS533P)
UNIT DETAILS HOURS
I INTRODUCTION AND FUNDAMENTALS OF THE ANALYSIS OF ALGORITHM EFFICIENCY: 8
Introduction, Notion of Algorithm, Fundamentals of Algorithmic Solving, Important Problem
Types, Fundamentals of the Analysis Framework, Mathematical Analysis of Non-recursive
Algorithm, Mathematical Analysis of Recursive Algorithm and examples, Empirical Analysis of
Algorithms and Algorithm Visualization.
II ALGORITHM DESIGN TECHNIQUES: Brute Force and Exhaustive Search: Selection Sort, Bubble 11
Sort, Sequential Search and Brute-force string matching, Travelling Salesman Problem, Knapsack
Problem, Assignment Problem.
Decrease and Conquer: Insertion Sort and Topological Sorting and Fake Coin Problem, Russian
Peasant Multiplication, Josephus Problem.
III ALGORITHM DESIGN TECHNIQUES: Divide and conquer: Merge sort, Quick Sort, Binary Tree 10
Traversals and Related Properties and Multiplication of Large Integers and Strassen’s Matrix
Multiplication.
Transform and Conquer: Pre-sorting, Notion of Heap and Heapsort, Horner’s Rule and Binary
Exponentiation.
IV ALGORITHM DESIGN TECHNIQUES: Space and Time Trade - Offs: Sorting by Counting, 8
Horspool’s and Boyer - Moore Algorithm for String Matching, Hashing.
Dynamic Programming: Knapsack Problem, Warshall’s and Floyd’s Algorithm.
Greedy Techniques: Prim’s Algorithm, Kruskal’s Algorithm, Dijkstra’s Algorithm.
V ALGORITHM DESIGN TECHNIQUES: Limitations of Algorithm Power: Decision Trees, P, NP and 8
NP Complete Problems, Challenges in Numerical Algorithms.
Backtracking: n-Queen’s Problem, Hamiltonian Circuit problem and Subset-Sum problem.
Branch and Bound: Assignment problem, Knapsack problem and Traveling salesman problem.
TOTAL HOURS: 45
7
Excellence and Service
CHRIST
Deemed to be University
Study Materials
TEXT BOOKS
T1. AnanyLevitin, “Introduction to the Design and Analysis of Algorithm”, 3/e,
Pearson Education Asia, Reprint 2012.
T2. Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser, “Data
Structures and Algorithms in Java”, 6/e, Wiley, 2014.
REFERENCE BOOKS
R1. T. H Cormen, C E Leiserson, R L Rivest and C Stein: “Introduction to
Algorithms”, 3rd Edition, The MIT Press, 2014.
R2. Ellis Horowitz, SartajSahni and SanguthevarRajasekaran, Computer Algorithms,
Second Edition, Universities Press, 2007.
R3. Richard Neapolitan, “Foundations of Algorithms”, 5/e, Jones & Bartlett
Learning, 2014.
R4. Richard Johnsonbaugh, Marcus Schaefer, “Algorithms”, Pearson Education, 2009.
R5. Clifford A Shaffer, “Data Structures and Algorithm Analysis in Java”, 3rd
Edition, Courier Corporation, 2014.
OTHER RESOURCES
● NPTEL Course: https://onlinecourses.nptel.ac.in/noc22_cs71/preview
8
Excellence and Service
CHRIST
Deemed to be University
COURSE PREREQUISITES
• Computer Programming
• Data Structure and Algorithms
9
Excellence and Service
CHRIST
Deemed to be University
10
Excellence and Service
CHRIST
Deemed to be University
11
Excellence and Service
CHRIST
Deemed to be University
Lower Bounds
Lower bound: an estimate on a minimum amount of work needed to
solve a given problem
Examples:
● number of comparisons needed to find the largest element in a set of
n numbers
● number of comparisons needed to sort an array of size n
● number of comparisons necessary for searching in a sorted array
● number of multiplications needed to multiply two n-by-n matrices
Lower Bounds
We can look at the efficiency of an algorithm two ways. We can
establish its asymptotic efficiency class (say, for the worst case) and
see where this class stands with respect to the hierarchy of
efficiency classes.
● For example, selection sort, whose efficiency is quadratic, is a
reasonably fast algorithm,
● whereas the algorithm for the Tower of Hanoi problem is very
slow because its efficiency is exponential.
Lower bounds means estimating the minimum amount of work
needed to solve the problem. We present several methods for
establishing lower bounds and illustrate them with specific
examples.
1. Trivial Lower Bounds
2. Information-Theoretic Arguments
3. Adversary Arguments
13
4. Problem Reduction Excellence and Service
CHRIST
Deemed to be University
● Tight lower bound: there exists an algorithm with the same efficiency
as the lower bound
● problem reduction
Examples
● finding max element
● polynomial evaluation
● sorting
● element uniqueness
● Hamiltonian circuit existence
Conclusions
● may and may not be useful
● be careful in deciding how many elements must be processed (min-max)
Decision Trees
Decision tree —model algorithms that use comparisons:
● internal nodes represent comparisons
● leaves represent outcomes
● How many orderings of 2 elements? Of 3? Of n?
● Tree for 3-element insertion sort [insert b in a, then c into ab]
abc
yes no
a<b
abc bac
yes no yes no
b< c a<c
P, NP, NP Complete
Basic Concepts
- Classifying Problems
- Tractable and non-tractable
- Optimization and Decision Problems
- Problem Classes
-P
- NP
- NP Complete
Possible answers:
● yes (give examples)
● no
○ because it’s been proved that no algorithm exists at all
(e.g., Turing’s halting problem)
○ because it’s been be proved that any algorithm takes
exponential time
● unknown
Class P
P: the class of decision problems that are solvable in O(p(n)) time,
where p(n) is a polynomial of problem’s input size n
Examples:
● searching
● element uniqueness
● graph connectivity
● graph acyclicity
Class NP
NP (nondeterministic polynomial): class of decision problems whose
proposed solutions can be verified in polynomial time = solvable by a
nondeterministic polynomial algorithm
● All the problems in P can also be solved in this manner (no guessing is
necessary), so we have:
P NP
● Big question: Is P = NP ? Or is P ⊂ NP ?
○ Answer unknown. Current approach: focus on hardest NP problems
NP problems
NP-complete
problem
NP-complete
problem
known
NP-complete
problem
candidate
for NP -
completeness
P = NP ? Dilemma Revisited
● If P = NP then every problem in NP (including all NP-complete
problems) could be solved in polynomial time
● If a polynomial-time algorithm for just one NP-complete problem is
discovered, then every problem in NP can be solved in polynomial
time, i.e., P = NP
NP problems
NP-complete
problem
BackTracking
N-Queens Problem
● PresortMode(A[0..n − 1])
//Computes the mode of an array by sorting it first
//Input: An array A[0..n − 1] of orderable elements
//Output: The array’s mode
sort the array A
i ←0 //current run begins at position i
modefrequency ←0 //highest frequency seen so far
while i ≤ n − 1 do
runlength←1; runvalue←A[i]
while i + runlength ≤ n − 1 and A[i + runlength]= runvalue
runlength←runlength + 1
if runlength > modef requency
modef requency ←runlength; modevalue←runvalue
i ←i + runlength
return modevalue
THANK YOU