UNIT III GREEDY AND DYNAMIC PROGRAMMING

Session – 22

Syllabus 

Introduction - Greedy: Huffman Coding Knapsack Problem - Minimum Spanning Tree (Kruskals Algorithm). Dynamic Programming: 0/1 Knapsack Problem - Travelling Salesman Problem – Multistage Graph- Forward path and backward path.

Introduction 

It is used when the solution can be recursively described in terms of solutions to subproblems (optimal substructure).

Algorithm finds solutions to subproblems and stores them in memory for later use.  More efficient than “brute-force methods”, which solve the same subproblems over and over again. 



Characteristics: 1. Optimal substructure: Optimal solution to problem consists of optimal solutions to subproblems 2. Overlapping subproblems: Few subproblems in total, many recurring instances of each 3. Bottom up approach: Solve bottom-up, building a table of solved subproblems that are used to solve larger ones

MULTISTAGE GRAPH Dynamic programming is an algorithm design method that can be used when the solution to a problem may be viewed as the result of a sequence of decisions.  Minimum spanning of multistage graph using dynamic programming 

 Forward Approach  Backward Approach

a. 

Forward Approach: Approach:

Spanning a multiple stage graph using following considerations ◦ Identify source and destination nodes. ◦ Find all possible paths to reach destination from source and sum of weights of adjacent nodes. ◦ The path giving the least weight will be the minimum spanning path.

Identifying source and destination nodes. Source node -> S Destination node -> D The possible ways to connect S & D d(S,D) = min { 1+d(A,D); 2+d(F,D);5+d(C,D)}

(1)

d(A,D) = min{4+d(B,D) ;9+d(G,D) } = min{ 4 + 18 ; 9 + 13 } = min{ 22;22} d(A,D) = 22

(2)

d(F,D) = min{ 9 + d(B,D) ; 5 + d(G,D) ; 16 + d(E,D) } = min{ 9 + d(B,D) ; 5 + d(G,D) ; 16 + d(E,D) } = min{ 9 + 18 ; 5 + 13 ; 16 + 2} = min{ 27 ; 18 ; 18} d(F,D) = 18

(3)

d(C,D) = min{ 2 + d(E,D) } = min{ 2 + 2} = min{ 4} d(C,D) = 4

(4)

substitution of 2,3,4 in 1 gives d(S,D) = min { 1 + d(A,D) ; 2 + d(F,D) ; 5 + d(C,D) } d(S,D) =

min { 1 + 22 ; 2 + 18 ; 5 + 4 }

d(S,D) =

min { 23 ; 20 ; 9 } =

9

Hence according to Forward Approach minimum spanning path from S to D is S ->C ->E ->D

b. Backward Approach: Approach: 

Backward Approach is just the reverse of forward approach, here Source node and the next node is considered at every stage.

Source node S to next nodes A, F and C d(S,A) = 1

d(S,F) = 2

d(S,C) = 5

Source node S to next nodes B, G and E d(S,B) = min{ 1 + d(A,B) ; 2 + d(F,B)} = min{ 1 + 4 ; 2 + 9} = min{ 5 ; 11} d(S,B) = 5 d(S,G) = min{ 1 + d(A,G) ; 2 + d(F,G)} = min{ 1 + 11 ; 2 + 5 } = min{ 12 ; 7} d(S,G) = 7 d(S,E) = min{ 2 + d(F,E) ; 5 + d(C,E)} = min{ 1 + 16 ; 5 + 2} = min{ 17 ; 7} d(S,E) = 7 d(S,D) = min{ 5 + d(B,D) ; 7 + d(G,D) ; 7 + d(E,D)} = min{ 5 + 18 ; 7 + 13 ; 7 + 2} = min{ 23 ; 20 ; 9} d(S,D) = 9 Hence according to Backward Approach minimum spanning path from S to D is S -> C -> E -> D

Worksheet No. 22

UNIT III GREEDY AND DYNAMIC PROGRAMMING ...

UNIT III. GREEDY AND DYNAMIC PROGRAMMING. Session – 22 ... The possible ways to connect S & D d(S,D) = min { 1+d(A,D); 2+d(F,D);5+d(C,D)}. (1) d(A,D) ...

927KB Sizes 0 Downloads 179 Views

Recommend Documents

UNIT III GREEDY AND DYNAMIC PROGRAMMING ...
subproblems. Best choice does depend on choices so far. Many subproblems are repeated in solving larger problems. This repetition results in great savings.

UNIT III 2marks.pdf
Program. Flowchart. Pseudo code. Decision table. 7. What is decision table? A decision table is a table containing the selection of conditions to be tested and ...

Dynamic programming
Our bodies are extraordinary machines: flexible in function, adaptive to new environments, .... Moreover, the natural greedy approach, to always perform the cheapest matrix ..... Then two players take turns picking a card from the sequence, but.

Unit – III / 1 Unit – III Overvoltages Sources of over ... -
At the monitoring location shown, the initial change in voltage will not go to zero because of the ... Switching of grounded-wye transformer may also result transient voltages due to the .... XL′ represents the series-resonant condition.

Dynamic Programming
Dynamic programming (DP) is a mathematical programming (optimization) .... That is, if you save 1 dollar this year, it will grow to 1 + r dollars next year. Let kt be ...

Unit III - Structure & Function of Government - Bureaucracy.pdf ...
Page 1 of 2. AP US Government – Exam Study Guide. Unit III: Structure & Function of Government. BUREAUCRACY. 1. What is the size of the federal bureaucracy? How is it organized and what role does it play in. making and implementing public policy? 2

UNIT III MPI new.pdf
If an interrupt has been requested, the 8086 processes it by performing the following series of steps: a) Pushes the content of the flag register onto the stack to ...

UNIT –3 PARALLEL PROGRAMMING
In the following code fragment, the directives indicate that the outer two loops are ... iii) Using a completely new programming language for parallel programming (e.g. Ada). ... execution of the user code beyond the end of the parallel construct.

UNIT –3 PARALLEL PROGRAMMING
Page 24. Parallel Algorithms &. Parallel Programming. Check Your Progress 3. 1) (a) syntax for parallel directive : #pragma omp parallel [set of clauses].

Programming skills-III (OOCP)
d. Generate a complete list of all names, addresses and telephone numbers. e. End of the computation. (2) Write a program that returns the size in bytes of a file entered on the command line. (3) You are the owner of a hardware store and need to keep

Reference Sheet for CO120.3 Programming III - GitHub
GBB. B d˜rief en enum type th—t represents fl—gs for renderingF. B. B i—™h ˜it represents — different fl—gF …se ˜itwise —nd. B to ™he™k if — fl—g is setF. BG enum render•fl—g {. GBB „he —m˜ient fl—g @˜it HAF BG

III" "III "III "III III" MI" III III" |ll
Jun 28, 2002 - received, and any other external data to perform an action or to move to ...... DVD-RAM, hard disk drive, magnetic tape or any other magnetic ...

III" "III "III "III III" MI" III III" |ll
Jun 28, 2002 - tomer service information to cell phone users may prompt a user With the question “What happened to ..... case, the speech application may de?ne a global variable, such as “GENDER,” that holds a value such as .... (VOIP) connecti

PDF Dynamic Programming and Optimal Control, Vol. I ...
I, 4th Edition, read online Dynamic Programming and Optimal Control, Vol. .... been instrumental in the recent spectacular success of computer Go programs.