FADML 02 PPC Recursive Def To Algo PDF
FADML 02 PPC Recursive Def To Algo PDF
ALGORITHM DESIGN
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
First Problem: Largest of a Set of Numbers
Sequential Comparison
Finding Largest: Recursive Formulation
Largest: Analysis
Proof of Correctness Complexity Analysis
Comparison Tournament
2nd Problem: Largest and Smallest
Sequential Comparison
Largest and Smallest: Recursive Definition
Largest & Smallest: Choice of Split
Tournament Based Analysis & Design
3rd Problem: Largest and Second Largest
Sequential Comparison
Largest and 2nd Largest: Recursive Formulation
Largest and Next: Tournament
Tournaments & Sorting
Final Algorithms & Data Structuring
Algorithms + Data Structures = Progams
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
Piṅgala’s Numbers (3rd Century BC)
The Chandaḥśāstra presents the first known description of a binary numeral system in
connection with the systematic enumeration of meters with fixed patterns of short and long
syllables. The discussion of the combinatorics of meter corresponds to the binomial
theorem. Halāyudha's commentary includes a presentation of the Pascal's triangle (called
meruprastāra). Piṅgala's work also contains the Fibonacci numbers, called mātrāmeru.
(later Bharata Muni (100 BC), Virahanka (700 AD), Hemachandra (1150 AD) – all before
Fibonacci 1200 AD)
Use of zero is sometimes ascribed to Piṅgala due to his discussion of binary numbers,
usually represented using 0 and 1 in modern discussion, but Piṅgala used light (laghu) and
heavy (guru) rather than 0 and 1 to describe syllables. As Piṅgala's system ranks binary
patterns starting at one (four short syllables—binary "0000"—is the first pattern), the nth
pattern corresponds to the binary representation of n-1 (with increasing positional values).
Piṅgala is thus credited with using binary numbers in the form of short and long syllables
(the latter equal in length to two short syllables), a notation similar to Morse code.
Piṅgala used the Saṁskṛta word śūnya explicitly to refer to zero.
Mātrāmeru or Fibonacci Numbers
Analyzing the Recursion Structure
Memoization
Finalizing the Algorithm
Variations
Evaluation of Fibonacci-like Recurrences
Evaluation Algorithm
Memoization Data Structure
Coin Selection Problem
First Recursive Definition
Example
Improved Recursive Definition
Alternative Recursive Definition
Example
Traversal and Potential Pruning
Finalizing the Algorithm
Special Case
Summary
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?