+ All Categories
Home > Engineering > Class warshal2

Class warshal2

Date post: 19-Jul-2015
Category:
Upload: debarati-das
View: 252 times
Download: 1 times
Share this document with a friend
Popular Tags:
15
Warshall’s Algorithm & Dynamic Programming BY DEBARATI DAS ( CS-52)
Transcript
Page 1: Class warshal2

Warshall’s Algorithm&

Dynamic Programming

BY

DEBARATI DAS ( CS-52)

Page 2: Class warshal2

Key Points OF Discussion

1

• FB vs Google+ (graph types)

• Transitive Closure

2

• Explanation of Warshall Algorithm

• Complexity Analysis

3• Applications of Warshall Algorithm

Page 3: Class warshal2

FB Vs Google+

Page 4: Class warshal2

Transitive Closure

1• What is Transitivity ?

• Express it in a graph :

2

• What is Transitive Closure ?

• Express as a Matrix :

• How can we find Transitive Closure of A Graph ?

Page 5: Class warshal2

Finding Transitive Closure

• Involves searching for the shortest path starting at every vertex.

• If you start at ith vertex, after traversal you get columns containing 1 in the ith row.

• Clearly it has a disadvantage (?)

DFS Implementation

• It involves finding the shortest path and improving the estimate on the path every single time, till its optimal.

• However, this fails in case of negative cycles.

Basic Point of The Warshall

Algorithm

Page 6: Class warshal2

Warshall Algorithm : Visitation

Example

Page 7: Class warshal2

Warshall Algorithm : Weighted

Example

Page 8: Class warshal2

Warshall Algorithm, brief

Page 9: Class warshal2

Complexity Analysis :

In this Bottom up Dynamic approach,

D0 -> 0

D1 -> n2 problems , every problem is a value in a cell.

n2xn where n2 denotes subproblems and n is no of matrices

So,total number of problems that need to be solved are n3

Therefore Time complexity is O(n3)

Space Complexity :

D1->D0

D2->D1

D3->D2

At any point of time you need two matrices so O(n2)

Page 10: Class warshal2

Applications of Warshall Algorithm

1. Shortest Path in Directed Graphs

2. Optimal Routing

3. Check if a graph is Bipartite

4. Pathfinder Networks

5. Inversion of Real Networks

(Gauss Jordan Method)

Page 11: Class warshal2

Key Questions

1

• What is the difference between D&C and DP ?

• What is Dynamic Programming ?

• Why is it called “Dynamic” ?

2

• What is Space Time Trade off ?

• How is it implemented by DP ?

• What are the applications of DP ?

• What is a non optimizable problem ?

3

• What is transitive Closure ?

• Warshall Algorithm discussion

Page 12: Class warshal2

Fibonacci Series : An illustration

fib(5)

fib(4) fib(3)

fib(3) fib(2) fib(2) fib(1)

fib(2) fib(1) fib(1) fib(0) fib(1) fib(0)

fib(1) fib(0)

6

5

21

3

4

Page 13: Class warshal2

Divide and Conquer vs D.P

Clearly If We use Divide and Conquer, We face

OVER LAP.

Mostly values are calculated again and again,

so even though access of function is O(1) , the

total time complexity is exponential or O(2n).

INSTEAD if we used DP. We would store each

value in a table and access when required.

DP Time complexity becomes O(n)

Page 14: Class warshal2

Why is it called “Dynamic

Programming” ?

Page 15: Class warshal2

Dynamic Programming : Basic Idea

Avoid calculating the same thing twice by keeping a table of known results, which we fill up as subinstances are solved.

Dynamic programming is a bottom-up / top down technique

Bottom up dynamic programming evaluates by computing all

function values in order, starting at lowest and using previously

computed values.

Can MERGE SORT Be solved using DP ?


Recommended