SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler offline
R
G
P
V
द
े
B
u
n
k
e
r
s
R
G
P
V
द
े
B
u
n
k
e
r
s
ADA Unit — 3: Dynamic Programming
and Its Applications
1. Concept of Dynamic Programming
Dynamic Programming (DP) is a powerful algorithmic technique used to solve complex
problems by breaking them down into smaller overlapping subproblems. It is a method of
solving problems with optimal substructure, where the solution to the main problem can be
constructed from the optimal solutions of its subproblems. DP is particularly useful for
optimization problems, where the goal is to find the best solution among many possible
solutions. This topic explores the fundamental concepts of dynamic programming, its working
principles, and its significance in algorithm design.
1.1 Overlapping Subproblems
In dynamic programming, many problems can be divided into smaller subproblems that are
solved independently. Interestingly, these subproblems often share common sub-subproblems.
The key idea is to avoid redundant calculations by storing the solutions to subproblems and
reusing them when necessary. This technique is known as memoization or tabulation, and it
significantly improves the time complexity of the algorithm.
1.2 Optimal Substructure
The optimal substructure property is a fundamental characteristic of problems that can be
efficiently solved using dynamic programming. It states that the optimal solution to a problem
contains the optimal solutions of its subproblems. By leveraging this property, we can build the
solution to the main problem by combining the solutions of its subproblems, thus arriving at the
overall optimal solution.
1.3 Steps in Dynamic Programming
The process of solving a problem using dynamic programming involves the following steps:
R
G
P
V
द
े
B
u
n
k
e
r
s
1. Identify the problem's characteristics to determine if it exhibits overlapping subproblems
and optimal substructure.
2. Formulate the recurrence relation: Express the problem's solution in terms of solutions to
smaller subproblems.
3. Choose a suitable method: Decide whether to use a top-down approach (memoization)
or a bottom-up approach (tabulation).
4. Implement the solution: Write the code for the DP algorithm and handle base cases and
boundary conditions.
2. 0/1 Knapsack Problem
The 0/1 knapsack problem is a classical optimization problem widely studied in the field of
computer science and mathematics. The problem involves a knapsack (or a backpack) with a
limited carrying capacity and a set of items, each with a weight and a value. The goal is to
determine the combination of items to include in the knapsack, such that the total weight does
not exceed the knapsack's capacity, and the total value of the selected items is maximized. This
topic delves into the formulation of the 0/1 knapsack problem, approaches to solve it using
dynamic programming, and variations of the problem.
2.1 Formulation of the Problem
Given n items, each with a weight wᵢ and a value vᵢ, and a knapsack with a maximum capacity
W, the 0/1 knapsack problem can be formally stated as follows:
Maximize Σᵢ (vᵢ * xᵢ)
Subject to Σᵢ (wᵢ * xᵢ) ≤ W
where xᵢ is a binary variable that indicates whether item i is included (xᵢ = 1) or excluded (xᵢ = 0)
from the knapsack.
R
G
P
V
द
े
B
u
n
k
e
r
s
2.2 Dynamic Programming Approach
The dynamic programming approach to solving the 0/1 knapsack problem involves constructing
a DP table to store the maximum value that can be obtained with varying capacities of the
knapsack and considering different subsets of items. The steps to solve the problem are as
follows:
1. Create a 2D DP table of size (n + 1) × (W + 1), where n is the number of items, and W is
the maximum knapsack capacity.
2. Initialize the first row and the first column of the DP table to zero since the knapsack's
capacity is zero or there are no items to select.
3. Iterate through each item and each possible capacity of the knapsack.
4. For each combination of item i and knapsack capacity j, calculate the maximum value
that can be obtained:
a. If the weight of item i (wᵢ) is greater than the current knapsack capacity (j), set the
DP value to the value obtained by considering the previous item's value for the
same capacity: DP[i][j] = DP[i-1][j].
b. Otherwise, consider whether it is beneficial to include item i in the knapsack.
Choose the maximum between including item i (DP[i][j] = vᵢ + DP[i-1][j-wᵢ]) and
excluding item i (DP[i][j] = DP[i-1][j]).
5. The value in DP[n][W] represents the maximum value that can be obtained by including
items in the knapsack without exceeding its capacity.
2.3 Variations of the Knapsack Problem
The knapsack problem has several variations, each with its own set of constraints and
objectives:
2.3.1 Fractional Knapsack Problem
In this variation, the items can be divided (fractional parts) to fill the knapsack. The goal remains
the same - to maximize the total value of the included items while staying within the knapsack's
capacity. The fractional knapsack problem can be efficiently solved using a greedy algorithm.
R
G
P
V
द
े
B
u
n
k
e
r
s
2.3.2 Bounded Knapsack Problem
The bounded knapsack problem is an extension of the 0/1 knapsack problem, where there are a
limited number of each item available. The task is to find the optimal combination of items while
respecting their individual quantities.
2.3.3 Multiple Knapsack Problem
In this variant, there are multiple knapsacks, each with its own capacity constraint. The
challenge is to distribute the items among the knapsacks to maximize the total value.
3. Multistage Graph
A multistage graph is a directed graph consisting of multiple stages or levels, with edges only
allowed between consecutive stages. Multistage graphs are commonly used to model
decision-making processes, where decisions are made at each stage, and the goal is to find the
optimal path or sequence of decisions. This topic explores multistage graphs, their
representation, and how dynamic programming can be applied to solve problems associated
with these graphs.
3.1 Representation of Multistage Graph
A multistage graph is typically represented as a directed acyclic graph (DAG) with multiple
layers or stages. Each stage represents a set of vertices, and edges are only allowed between
vertices of consecutive stages. Edges are weighted to represent the cost, value, or any relevant
metric associated with transitioning from one vertex to another.
3.2 Applications of Multistage Graphs
Multistage graphs find applications in various fields, including:
● Project Management: Representing project tasks and dependencies to optimize
scheduling.
R
G
P
V
द
े
B
u
n
k
e
r
s
● Network Design: Optimizing routing and resource allocation in communication
networks.
● Manufacturing: Planning production schedules and optimizing resource utilization.
3.3 Solving Multistage Graph Problems with Dynamic
Programming
Dynamic programming is an ideal technique to solve problems related to multistage graphs
because of the overlapping subproblems and optimal substructure properties. The general
approach involves the following steps:
1. Define the stages and vertices of the multistage graph.
2. Formulate the problem as a path-finding or decision-making problem within the graph.
3. Set up a DP table to store intermediate results for each vertex at each stage.
4. Initialize the DP table with base cases (usually the final stage) where the solution is
known.
5. Recursively fill in the DP table from the final stage to the initial stage using the optimal
substructure property.
6. Derive the final solution from the DP table.
4. Reliability Design
Reliability design is an important aspect of engineering and system design, where the goal is to
create systems that can maintain their functionality and performance even in the presence of
component failures. Reliability design problems aim to maximize the overall system reliability by
making smart decisions about redundancy and component selection. Dynamic programming is
often used to address reliability design problems efficiently.
4.1 Modeling Reliability
Reliability is a measure of a system's ability to perform its intended function without failure over
a specified time period. It is typically represented as a probability, ranging from 0 to 1. The
higher the reliability value, the more dependable the system is.
R
G
P
V
द
े
B
u
n
k
e
r
s
4.2 Components and Systems
In reliability design, systems are composed of various components. Each component has its
own reliability, which indicates the probability of functioning without failure. Components can be
arranged in parallel, series, or other configurations, affecting the overall reliability of the system.
4.3 Formulating Reliability Design as a Dynamic Programming
Problem
Reliability design problems can be framed as dynamic programming problems by considering
the reliability of different system configurations. The following steps outline the process:
1. Identify the system's components and their individual reliabilities.
2. Define the different configurations that the system can have, based on the arrangement
of components.
3. Formulate a recursive relationship that represents the system's reliability in terms of its
components' reliabilities.
4. Set up a DP table to store the intermediate reliability values for different system
configurations.
5. Fill in the DP table using the recurrence relation, considering the optimal substructure
property.
6. Derive the final solution from the DP table, representing the system's optimal reliability
and the corresponding configuration.
5. Floyd-Warshall Algorithm
The Floyd-Warshall algorithm is a widely used technique for finding the shortest paths between
all pairs of vertices in a weighted graph. Unlike some other algorithms like Dijkstra's algorithm,
the Floyd-Warshall algorithm can handle graphs with negative edge weights and is particularly
useful for dense graphs where the number of edges is close to the maximum possible.
R
G
P
V
द
े
B
u
n
k
e
r
s
5.1 Problem Definition
Given a weighted graph G(V, E), where V is the set of vertices and E is the set of edges with
associated weights, the goal of the Floyd-Warshall algorithm is to find the shortest distance
between all pairs of vertices in the graph.
5.2 Working Principle of Floyd-Warshall Algorithm
The Floyd-Warshall algorithm employs dynamic programming to solve the shortest path problem
for all pairs of vertices. It maintains a 2D DP table to store the shortest distance between each
pair of vertices. Initially, the DP table is populated with the weights of the edges between the
corresponding vertices.
5.3 Dynamic Programming Approach
The algorithm proceeds iteratively by considering all vertices as intermediate vertices in the path
from one vertex to another. The steps to compute the shortest distances using dynamic
programming are as follows:
1. Create a 2D DP table, initially set to the graph's adjacency matrix (with direct edge
weights between vertices).
2. Iterate through all vertices (k) and consider them as possible intermediate vertices in the
paths between other pairs of vertices (i and j).
3. For each pair of vertices (i, j), check if the path from i to j through vertex k is shorter than
the direct path from i to j. If it is shorter, update the DP table with the new shortest
distance: DP[i][j] = min(DP[i][j], DP[i][k] + DP[k][j]).
4. After the iterations are complete, the DP table will contain the shortest distances
between all pairs of vertices.
5.4 Detecting Negative Cycles
One important feature of the Floyd-Warshall algorithm is its ability to detect negative cycles in
the graph. A negative cycle is a cycle in the graph where the sum of edge weights is negative.
The algorithm can identify the presence of such cycles by checking for negative values on the
main diagonal of the DP table after the iterations are complete. If there are negative values on
the diagonal, the graph contains at least one negative cycle.
R
G
P
V
द
े
B
u
n
k
e
r
s
Conclusion
Dynamic programming is a versatile and powerful technique that finds numerous applications in
algorithm design, particularly for optimization and decision-making problems. In this study
material, we explored the concept of dynamic programming, the 0/1 knapsack problem,
multistage graphs, reliability design, and the Floyd-Warshall algorithm. Each of these topics
plays a significant role in computer science and engineering, providing valuable tools to tackle
real-world challenges.
As you progress through your studies, remember to practice solving problems related to these
topics to gain a deeper understanding and master the art of dynamic programming. Analyzing
and designing algorithms is an essential skill for computer scientists and engineers, and it
opens up exciting possibilities for problem-solving and innovation. Good luck in your academic
journey, and may you excel in your pursuit of knowledge and excellence! In the next unit, we will
continue exploring other important topics related to the "Analysis & Design of Algorithms" to
broaden our understanding and problem-solving skills.
If you have any further questions or need additional clarification on any topic, feel free to reach
out. Happy learning!
Note: The document provides a detailed explanation of the topics. Each topic can be further
expanded with more examples, proofs, and complexities. If you need additional details or any
specific aspects emphasized, please let us know, and We'll be glad to expand the content
accordingly.

Mais conteúdo relacionado

Semelhante a ADA Unit — 3 Dynamic Programming and Its Applications.pdf

Dynamic programming prasintation eaisy
Dynamic programming prasintation eaisyDynamic programming prasintation eaisy
Dynamic programming prasintation eaisyahmed51236
 
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdfADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdfRGPV De Bunkers
 
educational course/tutorialoutlet.com
educational course/tutorialoutlet.comeducational course/tutorialoutlet.com
educational course/tutorialoutlet.comjorge0043
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesNirmalavenkatachalam
 
Advanced Data Structures 2006
Advanced Data Structures 2006Advanced Data Structures 2006
Advanced Data Structures 2006Sanjay Goel
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithmNikitagupta123
 
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...ijaia
 
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...gerogepatton
 
Unit 1 - Optimization methods.pptx
Unit 1 - Optimization methods.pptxUnit 1 - Optimization methods.pptx
Unit 1 - Optimization methods.pptxssuser4debce1
 
LNCS 5050 - Bilevel Optimization and Machine Learning
LNCS 5050 - Bilevel Optimization and Machine LearningLNCS 5050 - Bilevel Optimization and Machine Learning
LNCS 5050 - Bilevel Optimization and Machine Learningbutest
 
A Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingA Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingEditor IJCTER
 
An Introduction to the Finite Element Method
An Introduction to the Finite Element MethodAn Introduction to the Finite Element Method
An Introduction to the Finite Element MethodMohammad Tawfik
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And ConquerUrviBhalani2
 
CHAPTER 6 System Techniques in water resuorce ppt yadesa.pptx
CHAPTER 6 System Techniques in water resuorce ppt yadesa.pptxCHAPTER 6 System Techniques in water resuorce ppt yadesa.pptx
CHAPTER 6 System Techniques in water resuorce ppt yadesa.pptxGodisgoodtube
 
Analysis of Algorithm II Unit version .pptx
Analysis of Algorithm  II Unit version .pptxAnalysis of Algorithm  II Unit version .pptx
Analysis of Algorithm II Unit version .pptxrajesshs31r
 

Semelhante a ADA Unit — 3 Dynamic Programming and Its Applications.pdf (20)

Dynamic programming prasintation eaisy
Dynamic programming prasintation eaisyDynamic programming prasintation eaisy
Dynamic programming prasintation eaisy
 
KMAP PAPER (1)
KMAP PAPER (1)KMAP PAPER (1)
KMAP PAPER (1)
 
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdfADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
 
educational course/tutorialoutlet.com
educational course/tutorialoutlet.comeducational course/tutorialoutlet.com
educational course/tutorialoutlet.com
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
Advanced Data Structures 2006
Advanced Data Structures 2006Advanced Data Structures 2006
Advanced Data Structures 2006
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
 
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
 
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
A BI-OBJECTIVE MODEL FOR SVM WITH AN INTERACTIVE PROCEDURE TO IDENTIFY THE BE...
 
Unit 1 - Optimization methods.pptx
Unit 1 - Optimization methods.pptxUnit 1 - Optimization methods.pptx
Unit 1 - Optimization methods.pptx
 
LNCS 5050 - Bilevel Optimization and Machine Learning
LNCS 5050 - Bilevel Optimization and Machine LearningLNCS 5050 - Bilevel Optimization and Machine Learning
LNCS 5050 - Bilevel Optimization and Machine Learning
 
A Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingA Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic Programming
 
Real-Time Face Tracking with GPU Acceleration
Real-Time Face Tracking with GPU AccelerationReal-Time Face Tracking with GPU Acceleration
Real-Time Face Tracking with GPU Acceleration
 
CUDA Accelerated Face Recognition
CUDA Accelerated Face RecognitionCUDA Accelerated Face Recognition
CUDA Accelerated Face Recognition
 
An Introduction to the Finite Element Method
An Introduction to the Finite Element MethodAn Introduction to the Finite Element Method
An Introduction to the Finite Element Method
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
 
CHAPTER 6 System Techniques in water resuorce ppt yadesa.pptx
CHAPTER 6 System Techniques in water resuorce ppt yadesa.pptxCHAPTER 6 System Techniques in water resuorce ppt yadesa.pptx
CHAPTER 6 System Techniques in water resuorce ppt yadesa.pptx
 
Analysis of Algorithm II Unit version .pptx
Analysis of Algorithm  II Unit version .pptxAnalysis of Algorithm  II Unit version .pptx
Analysis of Algorithm II Unit version .pptx
 

Último

UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 

Último (20)

UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 

ADA Unit — 3 Dynamic Programming and Its Applications.pdf

  • 2. R G P V द े B u n k e r s ADA Unit — 3: Dynamic Programming and Its Applications 1. Concept of Dynamic Programming Dynamic Programming (DP) is a powerful algorithmic technique used to solve complex problems by breaking them down into smaller overlapping subproblems. It is a method of solving problems with optimal substructure, where the solution to the main problem can be constructed from the optimal solutions of its subproblems. DP is particularly useful for optimization problems, where the goal is to find the best solution among many possible solutions. This topic explores the fundamental concepts of dynamic programming, its working principles, and its significance in algorithm design. 1.1 Overlapping Subproblems In dynamic programming, many problems can be divided into smaller subproblems that are solved independently. Interestingly, these subproblems often share common sub-subproblems. The key idea is to avoid redundant calculations by storing the solutions to subproblems and reusing them when necessary. This technique is known as memoization or tabulation, and it significantly improves the time complexity of the algorithm. 1.2 Optimal Substructure The optimal substructure property is a fundamental characteristic of problems that can be efficiently solved using dynamic programming. It states that the optimal solution to a problem contains the optimal solutions of its subproblems. By leveraging this property, we can build the solution to the main problem by combining the solutions of its subproblems, thus arriving at the overall optimal solution. 1.3 Steps in Dynamic Programming The process of solving a problem using dynamic programming involves the following steps:
  • 3. R G P V द े B u n k e r s 1. Identify the problem's characteristics to determine if it exhibits overlapping subproblems and optimal substructure. 2. Formulate the recurrence relation: Express the problem's solution in terms of solutions to smaller subproblems. 3. Choose a suitable method: Decide whether to use a top-down approach (memoization) or a bottom-up approach (tabulation). 4. Implement the solution: Write the code for the DP algorithm and handle base cases and boundary conditions. 2. 0/1 Knapsack Problem The 0/1 knapsack problem is a classical optimization problem widely studied in the field of computer science and mathematics. The problem involves a knapsack (or a backpack) with a limited carrying capacity and a set of items, each with a weight and a value. The goal is to determine the combination of items to include in the knapsack, such that the total weight does not exceed the knapsack's capacity, and the total value of the selected items is maximized. This topic delves into the formulation of the 0/1 knapsack problem, approaches to solve it using dynamic programming, and variations of the problem. 2.1 Formulation of the Problem Given n items, each with a weight wᵢ and a value vᵢ, and a knapsack with a maximum capacity W, the 0/1 knapsack problem can be formally stated as follows: Maximize Σᵢ (vᵢ * xᵢ) Subject to Σᵢ (wᵢ * xᵢ) ≤ W where xᵢ is a binary variable that indicates whether item i is included (xᵢ = 1) or excluded (xᵢ = 0) from the knapsack.
  • 4. R G P V द े B u n k e r s 2.2 Dynamic Programming Approach The dynamic programming approach to solving the 0/1 knapsack problem involves constructing a DP table to store the maximum value that can be obtained with varying capacities of the knapsack and considering different subsets of items. The steps to solve the problem are as follows: 1. Create a 2D DP table of size (n + 1) × (W + 1), where n is the number of items, and W is the maximum knapsack capacity. 2. Initialize the first row and the first column of the DP table to zero since the knapsack's capacity is zero or there are no items to select. 3. Iterate through each item and each possible capacity of the knapsack. 4. For each combination of item i and knapsack capacity j, calculate the maximum value that can be obtained: a. If the weight of item i (wᵢ) is greater than the current knapsack capacity (j), set the DP value to the value obtained by considering the previous item's value for the same capacity: DP[i][j] = DP[i-1][j]. b. Otherwise, consider whether it is beneficial to include item i in the knapsack. Choose the maximum between including item i (DP[i][j] = vᵢ + DP[i-1][j-wᵢ]) and excluding item i (DP[i][j] = DP[i-1][j]). 5. The value in DP[n][W] represents the maximum value that can be obtained by including items in the knapsack without exceeding its capacity. 2.3 Variations of the Knapsack Problem The knapsack problem has several variations, each with its own set of constraints and objectives: 2.3.1 Fractional Knapsack Problem In this variation, the items can be divided (fractional parts) to fill the knapsack. The goal remains the same - to maximize the total value of the included items while staying within the knapsack's capacity. The fractional knapsack problem can be efficiently solved using a greedy algorithm.
  • 5. R G P V द े B u n k e r s 2.3.2 Bounded Knapsack Problem The bounded knapsack problem is an extension of the 0/1 knapsack problem, where there are a limited number of each item available. The task is to find the optimal combination of items while respecting their individual quantities. 2.3.3 Multiple Knapsack Problem In this variant, there are multiple knapsacks, each with its own capacity constraint. The challenge is to distribute the items among the knapsacks to maximize the total value. 3. Multistage Graph A multistage graph is a directed graph consisting of multiple stages or levels, with edges only allowed between consecutive stages. Multistage graphs are commonly used to model decision-making processes, where decisions are made at each stage, and the goal is to find the optimal path or sequence of decisions. This topic explores multistage graphs, their representation, and how dynamic programming can be applied to solve problems associated with these graphs. 3.1 Representation of Multistage Graph A multistage graph is typically represented as a directed acyclic graph (DAG) with multiple layers or stages. Each stage represents a set of vertices, and edges are only allowed between vertices of consecutive stages. Edges are weighted to represent the cost, value, or any relevant metric associated with transitioning from one vertex to another. 3.2 Applications of Multistage Graphs Multistage graphs find applications in various fields, including: ● Project Management: Representing project tasks and dependencies to optimize scheduling.
  • 6. R G P V द े B u n k e r s ● Network Design: Optimizing routing and resource allocation in communication networks. ● Manufacturing: Planning production schedules and optimizing resource utilization. 3.3 Solving Multistage Graph Problems with Dynamic Programming Dynamic programming is an ideal technique to solve problems related to multistage graphs because of the overlapping subproblems and optimal substructure properties. The general approach involves the following steps: 1. Define the stages and vertices of the multistage graph. 2. Formulate the problem as a path-finding or decision-making problem within the graph. 3. Set up a DP table to store intermediate results for each vertex at each stage. 4. Initialize the DP table with base cases (usually the final stage) where the solution is known. 5. Recursively fill in the DP table from the final stage to the initial stage using the optimal substructure property. 6. Derive the final solution from the DP table. 4. Reliability Design Reliability design is an important aspect of engineering and system design, where the goal is to create systems that can maintain their functionality and performance even in the presence of component failures. Reliability design problems aim to maximize the overall system reliability by making smart decisions about redundancy and component selection. Dynamic programming is often used to address reliability design problems efficiently. 4.1 Modeling Reliability Reliability is a measure of a system's ability to perform its intended function without failure over a specified time period. It is typically represented as a probability, ranging from 0 to 1. The higher the reliability value, the more dependable the system is.
  • 7. R G P V द े B u n k e r s 4.2 Components and Systems In reliability design, systems are composed of various components. Each component has its own reliability, which indicates the probability of functioning without failure. Components can be arranged in parallel, series, or other configurations, affecting the overall reliability of the system. 4.3 Formulating Reliability Design as a Dynamic Programming Problem Reliability design problems can be framed as dynamic programming problems by considering the reliability of different system configurations. The following steps outline the process: 1. Identify the system's components and their individual reliabilities. 2. Define the different configurations that the system can have, based on the arrangement of components. 3. Formulate a recursive relationship that represents the system's reliability in terms of its components' reliabilities. 4. Set up a DP table to store the intermediate reliability values for different system configurations. 5. Fill in the DP table using the recurrence relation, considering the optimal substructure property. 6. Derive the final solution from the DP table, representing the system's optimal reliability and the corresponding configuration. 5. Floyd-Warshall Algorithm The Floyd-Warshall algorithm is a widely used technique for finding the shortest paths between all pairs of vertices in a weighted graph. Unlike some other algorithms like Dijkstra's algorithm, the Floyd-Warshall algorithm can handle graphs with negative edge weights and is particularly useful for dense graphs where the number of edges is close to the maximum possible.
  • 8. R G P V द े B u n k e r s 5.1 Problem Definition Given a weighted graph G(V, E), where V is the set of vertices and E is the set of edges with associated weights, the goal of the Floyd-Warshall algorithm is to find the shortest distance between all pairs of vertices in the graph. 5.2 Working Principle of Floyd-Warshall Algorithm The Floyd-Warshall algorithm employs dynamic programming to solve the shortest path problem for all pairs of vertices. It maintains a 2D DP table to store the shortest distance between each pair of vertices. Initially, the DP table is populated with the weights of the edges between the corresponding vertices. 5.3 Dynamic Programming Approach The algorithm proceeds iteratively by considering all vertices as intermediate vertices in the path from one vertex to another. The steps to compute the shortest distances using dynamic programming are as follows: 1. Create a 2D DP table, initially set to the graph's adjacency matrix (with direct edge weights between vertices). 2. Iterate through all vertices (k) and consider them as possible intermediate vertices in the paths between other pairs of vertices (i and j). 3. For each pair of vertices (i, j), check if the path from i to j through vertex k is shorter than the direct path from i to j. If it is shorter, update the DP table with the new shortest distance: DP[i][j] = min(DP[i][j], DP[i][k] + DP[k][j]). 4. After the iterations are complete, the DP table will contain the shortest distances between all pairs of vertices. 5.4 Detecting Negative Cycles One important feature of the Floyd-Warshall algorithm is its ability to detect negative cycles in the graph. A negative cycle is a cycle in the graph where the sum of edge weights is negative. The algorithm can identify the presence of such cycles by checking for negative values on the main diagonal of the DP table after the iterations are complete. If there are negative values on the diagonal, the graph contains at least one negative cycle.
  • 9. R G P V द े B u n k e r s Conclusion Dynamic programming is a versatile and powerful technique that finds numerous applications in algorithm design, particularly for optimization and decision-making problems. In this study material, we explored the concept of dynamic programming, the 0/1 knapsack problem, multistage graphs, reliability design, and the Floyd-Warshall algorithm. Each of these topics plays a significant role in computer science and engineering, providing valuable tools to tackle real-world challenges. As you progress through your studies, remember to practice solving problems related to these topics to gain a deeper understanding and master the art of dynamic programming. Analyzing and designing algorithms is an essential skill for computer scientists and engineers, and it opens up exciting possibilities for problem-solving and innovation. Good luck in your academic journey, and may you excel in your pursuit of knowledge and excellence! In the next unit, we will continue exploring other important topics related to the "Analysis & Design of Algorithms" to broaden our understanding and problem-solving skills. If you have any further questions or need additional clarification on any topic, feel free to reach out. Happy learning! Note: The document provides a detailed explanation of the topics. Each topic can be further expanded with more examples, proofs, and complexities. If you need additional details or any specific aspects emphasized, please let us know, and We'll be glad to expand the content accordingly.