You are on page 1of 29

INTRODUCTION TO ANALYSIS OF

ALGORITHMS

Partha P Chakrabarti
Indian Institute of Technology Kharagpur
Overview
 Algorithms and Programs Sample Problems:
 Pseudo-Code 1. Finding the Largest
 Algorithms + Data Structures = Programs
2. Largest and Smallest
 Initial Solutions + Analysis + Solution
Refinement + Data Structures = Final 3. Largest and Second Largest
Algorithm 4. Fibonacci Numbers
 Use of Recursive Definitions as Initial 5. Searching for an element in an ordered
Solutions
/ unordered List
 Recurrence Equations for Proofs and
Analysis 6. Sorting
 Solution Refinement through Recursion 7. Pattern Matching
Transformation and Traversal 8. Permutations and Combinations
 Data Structures for saving past
9. Layout and Routing
computation for future use
10. Shortest Paths
Time and Space Complexity of an Algorithm
Time Complexity is an estimate of the How do we develop a measure that can be
Execution Time of an Algorithm
used to determine the time efficiency of an
 Varies for individual computer
architectures, compilers used to algorithm independently and compare
implement the algorithm various algorithms for the same problem
 Varies as size of input varies, as well as across input sizes?
for different inputs of the same size, etc.
Space Complexity is an estimate of the
Memory Requirement of a Program
 Depends on how code and data are
stored in different architectures and what
happens when function calls are made,
handling of global and local variables,
etc.
 Access speeds of data also affect Time
Complexity
Conversion of High Level Programs
Computer Architecture, Sample Instruction Set
Another Instruction Set with Format
Number Representation
Asymptotic Analysis of Algorithms
 All data is stored in finite sized locations ASYMPTOTIC ANALYSIS
bounded by a constant.  An approximate measure that tries to
 All instructions take finite amount of time estimate the growth pattern of the execution
that is bounded by a constant. time of an algorithm with respect to
 If the number of instructions executed increased input / output size.
are around the same, but speeds of the  We wish to analyze upper and lower limits
computer are different, then their of this growth.
comparative execution times will be  We wish to look at Worst Case, Average
bounded by a constant. Case Growth Performance of the algorithm
 To make it computer independent, we
assume that each operation of an
algorithm takes unit time.
 We are interested to compare algorithms
when they take large amounts of time.
Approximation of Growth
Order of Growth
Order of Growth: Graphically
Notations for Order of Growth
Formal Definitions of Asymptotic Notations
Asymptotic Solutions to Recurrences
 Max  Coins

 Searching in an Unordered List


 Max and Min

 Sorting by Max Removal  Searching in an Ordered List


Master Theorem
Master Theorem, Examples
Master Theorem: Corollary
Master Theorem & Recursion Tree
Refined Statement of Master Theorem
Examples
Types of Analysis
Upper Bounds
Lower Bounds
Lower Bounding Methods
Optimal Algorithm
Summary
Algorithm Design by Recursion Transformation
 Algorithms and Programs 1. Initial Solution
a. Recursive Definition – A set of Solutions
 Pseudo-Code b. Inductive Proof of Correctness
 Algorithms + Data Structures = Programs c. Analysis Using Recurrence Relations
2. Exploration of Possibilities
 Initial Solutions + Analysis + Solution a. Decomposition or Unfolding of the Recursion Tree
Refinement + Data Structures = Final b. Examination of Structures formed
Algorithm c. Re-composition Properties
3. Choice of Solution & Complexity Analysis
 Use of Recursive Definitions as Initial a. Balancing the Split, Choosing Paths
Solutions b. Identical Sub-problems
 Recurrence Equations for Proofs and 4. Data Structures & Complexity Analysis
Analysis a. Remembering Past Computation for Future
b. Space Complexity
 Solution Refinement through Recursion 5. Final Algorithm & Complexity Analysis
Transformation and Traversal a. Traversal of the Recursion Tree
b. Pruning
 Data Structures for saving past
6. Implementation
computation for future use a. Available Memory, Time, Quality of Solution, etc
Overview of Algorithm Design
1. Initial Solution 1. Core Methods
a. Recursive Definition – A set of Solutions
a. Divide and Conquer
b. Inductive Proof of Correctness
c. Analysis Using Recurrence Relations b. Greedy Algorithms
2. Exploration of Possibilities c. Dynamic Programming
a. Decomposition or Unfolding of the Recursion Tree d. Branch-and-Bound
b. Examination of Structures formed e. Analysis using Recurrences
c. Re-composition Properties f. Advanced Data Structuring
3. Choice of Solution & Complexity Analysis 2. Important Problems to be addressed
a. Balancing the Split, Choosing Paths
b. Identical Sub-problems a. Sorting and Searching
4. Data Structures & Complexity Analysis b. Strings and Patterns
a. Remembering Past Computation for Future c. Trees and Graphs
b. Space Complexity d. Combinatorial Optimization
5. Final Algorithm & Complexity Analysis 3. Complexity & Advanced Topics
a. Traversal of the Recursion Tree
a. Time and Space Complexity
b. Pruning
b. Lower Bounds
6. Implementation
a. Available Memory, Time, Quality of Solution, etc c. Polynomial Time, NP-Hard
d. Parallelizability, Randomization
Thank you
Any Questions?

You might also like