0 Up votes0 Down votes

4 views17 pagesNov 01, 2010

© Attribution Non-Commercial (BY-NC)

PDF, TXT or read online from Scribd

Attribution Non-Commercial (BY-NC)

4 views

Attribution Non-Commercial (BY-NC)

- Steve Jobs
- Wheel of Time
- NIV, Holy Bible, eBook
- NIV, Holy Bible, eBook, Red Letter Edition
- Cryptonomicon
- The Woman Who Smashed Codes: A True Story of Love, Spies, and the Unlikely Heroine who Outwitted America's Enemies
- Contagious: Why Things Catch On
- Crossing the Chasm: Marketing and Selling Technology Project
- Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are
- Zero to One: Notes on Start-ups, or How to Build the Future
- Console Wars: Sega, Nintendo, and the Battle that Defined a Generation
- Dust: Scarpetta (Book 21)
- Hit Refresh: The Quest to Rediscover Microsoft's Soul and Imagine a Better Future for Everyone
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution
- Crushing It!: How Great Entrepreneurs Build Their Business and Influence—and How You Can, Too
- Make Time: How to Focus on What Matters Every Day
- Algorithms to Live By: The Computer Science of Human Decisions
- Wild Cards

You are on page 1of 17

CLRS Section 25.1

Assumes

no negative

weight edges

Θ |V |3 log |V | .

Needs priority queues

Only assumes no negative

weight cycles.

First version is Θ |V |4 .

3

Repeated squaring reduces to Θ |V | log |V | .

1

The All-Pairs Shortest Paths Problem

function w : E → R, (R is the set of real numbers),

determine the length of the shortest path (i.e., dis-

tance) between all pairs of vertices in G. Here we

assume that there are no cycles with zero or negative

cost.

a 20 b a −20 b

6 e 3 e

12 8 4 4 5

5 3 4

4

17 10

d c d c

2

Solution 1: Using Dijkstra’s Algorithm

gorithm to each vertex (as the source) of the digraph.

This gives a

time algorithm, where n = |V | and e = |E|.

D’s algorithm runs in Θ(n log n + e)time yielding

a Θ(n2 log n + ne) final algorithm. For dense

graphs this is Θ(n3) time.

3

Solution 2: Dynamic Programming

problem into subproblems

subproblem in terms of optimal solutions to some

subsubproblems?

compute the optimal solution in a bottom-up

fashion?

4

Solution 2: Input and Output Formats

matrix with the weights of the edges:

0

if i = j,

wij = w(i, j) if i 6= j and (i, j) ∈ E,

∞ if i 6= j and (i, j) ∈

/ E.

is the length of the shortest path from vertex i to j.

5

Step 1: How to Decompose the Original Problem

to solve.

pressed in terms of the optimal solutions to sub-

problems with smaller sizes.

6

Step 1: Decompose in a Natural Way

(m)

• Define dij to be the length of the shortest path

from i to j that contains at most m edges.

(m)

Let D (m) be the n × n matrix [dij ] .

(n−1)

• dij is the true distance from i to j (see next

page for a proof this conclusion).

7

(n−1)

dij = True Distance from i to j

contains at most n − 1 edges.

a shortest path can have no cycles (if there were a

cycle, we could remove it and lower the length of the

path).

(since a longer path must contain some vertex twice,

that is, contain a cycle).

8

A Recursive Formula

(m)

Consider a shortest path from i to j of length dij .

i - - ... - j i - - ... - k - j

wkj

d(m−1)

ij d(m−1)

ik

Case 1: at most m − 1 edges Case 2: exactly m edges

shortest path shortest path

(m) (m−1) (m−1)

Then dij = dij = dij + wjj .

Case 2: It has m edges. Let k be the vertex before j

on a shortest path.

(m) (m−1)

Then dij = dik + wkj .

(m) (m−1)

dij = min dik + wkj .

1≤k≤n

9

Step 3: Bottom-up Computation of D (n−1)

h i

• Bottom: D (1) = wij , the weight matrix.

using

(m) (m−1)

dij = min dik + wkj .

1≤k≤n

10

Example: Bottom-up Computation of D (n−1)

Example

3

1 2

8 11

4 4

4 3

7

0 3 8 ∞

(1)

∞ 0 4 11

D =

∞ ∞ 0 7

4 ∞ ∞ 0

11

Example: Computing D (2) from D (1)

(2) (1)

dij = min dik + wkj .

1≤k≤4

3

1 2

8 11

4 4

4 3

7

0 3 7 14

(2)

15 0 4 11

D =

11 ∞ 0 7

4 7 12 0

12

Example: Computing D (3) from D (2)

(3) (2)

dij = min dik + wkj

1≤k≤4

3

1 2

8 11

4 4

4 3

7

0 3 7 14

(3)

15 0 4 11

D =

11 14 0 7

4 7 11 0

D (3) gives the distances between any pair of vertices.

13

The Algorithm for Computing D (n−1)

for m = 1 to n − 1

for i = 1 to n

for j = 1 to n

{

min = ∞;

for k = 1 to n

{

(m−1)

new = dik + wkj ;

if (new < min) min = new;

}

(m)

dij = min;

}

14

Comments on Solution 2

reduced down to Θ(n2)?

the solution?

tion using Dijkstra’s algorithm. Can we improve

this?

15

Repeated Squaring

i

calculate x2 . How many multiplications are needed?

2 4 2 2 2i 2i−1 2i−1

x = x·x, x = x ·x , ..., x =x ·x

distance

< n.

2dlog2 ne

In particular, this implies that D = D (n−1).

2dlog2 ne

We can calculate D using “repeated squar-

ing” to find

2dlog2 ne

D (2), D (4), D (8), . . . , D

16

We use the recurrence relation:

h i

• Bottom: D (1) = wij , the weight matrix.

(s+t) (s) (s)

dij = min dik + dkj .

1≤k≤n

similar to recurrence relation we proved earlier this

lecture).

2i 2i−1

Given this relation we can calculate D from D

in O(n3) time. We can therefore calculate all of

2 dlog 2 ne

D (2), D (4), D (8), . . . , D = D (n)

in O(n3 log n) time, improving our running time.

17

- 00-08-049Uploaded byShourya Mukherjee
- reflections - kuta wsUploaded byapi-302577842
- Maths 8-2 M.C.Q.sUploaded byQadir Rafique
- (MG 39)DijkstraAlgorithmUploaded byDinh Hoai Khanh
- Rank Numbers for Bent LaddersUploaded byPeter Richter
- 51204677-nullUploaded bySumit Ray
- Dijk StraUploaded byAbsk
- ITED 106 SyllabusUploaded byClay Delgado
- grade 2 sorico math unit 1 3 2013-2014Uploaded byapi-233707670
- Intra Domain Traffic EngineeringUploaded byJovanni Ivan Jabat
- Graph Theory SeminarUploaded byPuneet Patil
- Nguyen Viet AnhUploaded bynxc_51
- 09EM26Uploaded byMukunthan RB
- MELJUN CORTES CSCI09 - Discrete Structures 2Uploaded byMELJUN CORTES, MBA,MPA
- Slides 4Uploaded bymcclaink06
- NR 311303 Operations ResearchUploaded bySrinivasa Rao G
- 39901270-VTU-ADA-lab-programsUploaded byanmolbabu
- 10033_ftp (1)Uploaded bycamelia
- HW1Uploaded byAshish Mehta
- Ray Tracing & PracticeUploaded byRizka
- Greedy MethodUploaded byAhmed Khalil
- Solver file.xlsxUploaded byMohammad Mizanur Rahman Nayan
- an-planarUploaded byJothika Suresh
- dargar2013.pdfUploaded byFiandjafar
- A _ Topic _ Divide and Conquer _ GeeksforGeeksUploaded byNiraj Kumar
- PhvUploaded byssreenus
- IntroductionUploaded byniteshaul
- Chapter 15 Worked SolutionsUploaded byH
- japanese lesson study conclusionsUploaded byapi-281761290
- 5Cycle Systems - Dissertation - John AsplundUploaded byAnonymous901

- Conservation of Momentum collisions.pptxUploaded byMona
- CSO Cheat SheetUploaded byFreshyAndMessy
- Public System Management.......Uploaded byOlusegun Olasunkanmi Pat
- Bevacizumab-Induced Bowel PerforationUploaded byhoangducnam
- Dwight Wilhelm - Censorship in ArgentinaUploaded byFederico
- Providences of the Great War - W.A. Spicer (1923).pdfUploaded bytitact
- EENTUploaded byteresapimentel
- Cerebro spinal Fluid Analysis in Childhood Bacterial Meningitis.pdfUploaded bylynharee
- Oakes FullChapterUploaded byCSF1
- 273555443-PRIMARY-ENG-PAPER-1-pdf.pdfUploaded byAgata Dziedzic-Kallidou
- Shiva Maanasa PujaUploaded byjai
- PapUploaded byEnrico Le Noci
- Forced Normalization - Clinical and Therapeutic RelevanceUploaded byjuan_bacha_1
- 99669028_FEA_HW3_HVIET_3Uploaded byHuynh Quoc Viet
- english i syllabus - 2013-2014Uploaded byapi-232022522
- Corn Cob as an Oil Adsorbent CompleteUploaded byRez Apego
- Free SAT Math Level 2 Subject TestUploaded byMirza Muqadam
- Presentation to be made at the institutional investors / analysts [Company Update]Uploaded byShyam Sunder
- Yes, We Have Noticed the Skulls _ Slate Star CodexUploaded bySunshine Frankenstein
- (Solid Mechanics and Its Applications 216) M. Reza Eslami (auth.)-Finite Elements Methods in Mechanics-Springer International Publishing (2014).pdfUploaded byJonatasPereiraSilva
- Shikha Sharma EssayUploaded byRavi Tej
- Indian Constitution1Uploaded bySwarup Mishra
- The Purple Cloud - M. P. ShielUploaded bypoisonknees
- Profit Driven Digital MarketingUploaded bySike Thedeviant
- Applebaum (Encyclopedia of the Scientific Revolution Vol. 1800) (Garland)Uploaded byMarcelo Silvano de Camargo
- 70-Article Text-121-1-10-20190110Uploaded byHerma Safitri
- The Writ of Amparo a Comparative Review by CodalUploaded byRobert Atkinson
- FETH 1.01 CheatsUploaded byGigi Ang
- Austerlitz RulebookUploaded byTheEnglishAssassin
- Catalytic Pyrolysis of Cellulose, Hemicellulose and Lignin Model CompoundsUploaded byÊnio Bruce

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.