Its Al About Data Structure and Algorithm Analysis
Size: 1.09 MB
Language: en
Added: May 28, 2019
Slides: 21 pages
Slide Content
Sunawar Khan
Islamia University of Bahawalpur
Bahawalnagar Campus
Analysis of Algorithm
ناخ رونس Algorithm Analysis
Counting Sort
Linear Time Sorting
Bucket Sort
Radix Sort
Contents
ناخ رونس Algorithm Analysis
Greedy Method v/s Dynamic Programing
•Both are used for Optimization problem. It required minimum or
maximum results.
•In Greedy Method:-Always follow a function until you find the optimal
result whether it is maximum or minimum.
•Prims algorithm for MST
•Dijkstra Algorithm for finding shortest path.
ناخ رونس Algorithm Analysis
Greedy Method v/s Dynamic Programing
•In Dynamic programing we will try to find all possible solution and
then we’ll pick the best solution which is optimal.
•It is time consuming as compared to greedy method.
•It use recursive formulas for solving problem.
•It follows the principal of optimality.
ناخ رونس Algorithm Analysis
Greedy V/S Dynamic
Greedy TechniqueDynamic Technique
•It gives local “Optimal Solution”
•Print in time makes “local optimization”
•More efficient as compared to dynamic programing
•Example:-Fractional Knapsack
•It gives “Global Optimal Solution”
•It makes decision “ smart recursion ”
•Less efficient as compared too greedy technique
•Example:-0/1 Knapsack
ناخ رونس Algorithm Analysis
Principle of Optimality
•Principle of optimality says that a problem can be solved by sequence
of decisions to get the optimal solution.
•It follows MemoizationProblem
ناخ رونس Algorithm Analysis
Running Example
•If we wannafind out the fib(5)
fib (5)
fib(3)
fib(1) fib(2)
fib(0) fib(1)
fib(4)
fib(2)
fib(0) fib(1)
fib(3)
fib(1) fib(2)
fib(0) fib(1)
ناخ رونس Algorithm Analysis
What?
•It is a strategy in designing of algorithm which is used when problem
breaks down into recurring small problems.
•It is typically applicable to optimization problems
•In such problems there can be many solution, each solution has a
value and we wish to find a solution with the optimal value.
ناخ رونس Algorithm Analysis
Elements of Dynamic Programming
•Simple Subproblems
•We should be able to break the original problem to small subproblems that
have the same structure
•Optimal substructure of problem
•The optimal solution to the problem contains within solution to its
subproblems.
•Overlapping Subproblems
•There exist some places where we solve the same subproblem more than once
ناخ رونس Algorithm Analysis
Steps to design Dynamic Programming Algo
•Characterize optimal substructure
•Recursively define the value of an optimal solution
•Compute the vale bottomUp
•(if needed) constraints an optimal solution
ناخ رونس Algorithm Analysis
Applications
•Matrix Chain Multiplication
•Optimal Binary Search Tree
•All Pairs Shortest Path Problems
•Travelling Salesperson Problem
•0/1 Knapsack Problem
•Reliability Design
ناخ رونس Algorithm Analysis
Matrix Chain Multiplication
13x1505x8989x0303x34
1234
1
0
2
0
3
0
4
0
m[1,1] m[2, 2]m[3, 3]m[4, 4]
m
A CB D