DYNAMIC PROGRAMMING
PRESENTED BY
GUNDLAPALLY SATHWIKA
22D21A0525
CSE3A
TOPICS
• Introduction to Dynamic Programming
• Applications of Dynamic Programming
• Example of DP
• All Pair Shortest path algorithm
• Floyd-warshall algorithm example
• Advantages of Dynamic Programming
INTRODUCTION
• Dynamic Programming is an algorithmic technique used in computer science and mathematics to
solve complex problems by breaking them down into smaller overlapping subproblems.
• Dynamic Programming is mainly an optimization over plain recursion.
• How DP Works?
• Identify Subproblems
• Store Solutions
• Build up Solutions
• Avoid Redundancy
APPLICATIONS OF DP
1.Finding the shortest path problem
2.Knapsack problem
3.Travelling Salesman problem
4.Optimal Binary Search Tree
Example :
Let N=4
ALL PAIR SHORTEST PATHS(FLOYD-WARSHALL
ALGORITHM)
• The Floyd-Warshall algorithm is a dynamic programming algorithm used to
discover the shortest paths in a weighted graph, which includes negative weight
cycles.
• Advantages:
• It is extremely simple.
• It is easy to implement.
Example:
Consider the following graph
Steps:
Write the initial distance matrix.
It represents the distance between every pair of vertices in the form of given weights.
For diagonal elements (representing self-loops), distance value = 0.
For vertices having a direct edge between them, distance value = weight of that edge.
For vertices having no direct edge between them, distance value = ∞.
ADVANTAGES OF DYNAMIC PROGRAMMING
• Efficiency
• Optimal solutions
• Versatility
• Handles complex problems
• Memory efficiency
• Time Complexity :O(n^3)
• Space Complexity :O(n^2)
Presentation (1) (5).pptx in DAA computer

Presentation (1) (5).pptx in DAA computer

  • 1.
  • 2.
    TOPICS • Introduction toDynamic Programming • Applications of Dynamic Programming • Example of DP • All Pair Shortest path algorithm • Floyd-warshall algorithm example • Advantages of Dynamic Programming
  • 3.
    INTRODUCTION • Dynamic Programmingis an algorithmic technique used in computer science and mathematics to solve complex problems by breaking them down into smaller overlapping subproblems. • Dynamic Programming is mainly an optimization over plain recursion. • How DP Works? • Identify Subproblems • Store Solutions • Build up Solutions • Avoid Redundancy
  • 4.
    APPLICATIONS OF DP 1.Findingthe shortest path problem 2.Knapsack problem 3.Travelling Salesman problem 4.Optimal Binary Search Tree Example : Let N=4
  • 5.
    ALL PAIR SHORTESTPATHS(FLOYD-WARSHALL ALGORITHM) • The Floyd-Warshall algorithm is a dynamic programming algorithm used to discover the shortest paths in a weighted graph, which includes negative weight cycles. • Advantages: • It is extremely simple. • It is easy to implement.
  • 6.
    Example: Consider the followinggraph Steps: Write the initial distance matrix. It represents the distance between every pair of vertices in the form of given weights. For diagonal elements (representing self-loops), distance value = 0. For vertices having a direct edge between them, distance value = weight of that edge. For vertices having no direct edge between them, distance value = ∞.
  • 11.
    ADVANTAGES OF DYNAMICPROGRAMMING • Efficiency • Optimal solutions • Versatility • Handles complex problems • Memory efficiency • Time Complexity :O(n^3) • Space Complexity :O(n^2)