You are on page 1of 18

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Graph Algorithms
APSP and Shortest Paths Applications

Dr. Shahbaz Khan


Department of Computer Science and Engineering,
Indian Institute of Technology Roorkee
shahbaz.khan@cs.iitr.ac.in
Feedback

2
Feedback

3
Feedback

4
Feedback

5
MATRIX MULTIPLICATION

Use Divide and Conquer for

MATRIX MULTIPLICATION
What is the cost of Matrix Multiplication?

STRASSEN’s Algorithm

PROBLEM: Given two NxN matrices A and B, compute its product A x B


Naive: O(n^3)
AxB= a b e f ae+bg af+bh P5+P4-P2+P6 P1+P2
c d g h ce+dg cf+dh P3+P4 P1+P5-P4-P7
P1 = a x (f-h)
P2 = (a+b) x h
P3 = (c+d) x e T(n) = 7T(n/2) + O(n^2)
P4 = d x (g-e)
P5 = (a+d)x(e+h) T(n) = O(n^2.81)
P6 = (b-d)x(g+h)
P7 = (a-c)x(e+f)
6
Feedback

7
Feedback

8
Feedback

9
11
Money Making Machine

Given a set of exchange rates among certain currencies,


can you make a profit making some exchanges?
Starting from one unit of currency C and perform a series of
barters which result in having >1 unit of C.

USE-> EUR-> CAD-> USD


= 0.741 x1.366 x 0.995
= 1.0071

12
Shortest Monotonic Path

Given a directed graph G=(V,E) having positive edge weights, a


monotonic path is one whose subsequent edge weights are either
strictly increasing or strictly decreasing (strictly implies equal weights
of adjacent edges are not permitted).

Compute all the shortest monotonic paths from a give source s.

15

You might also like