Some applications moving around washington
This presentation is the property of its rightful owner.
Sponsored Links
1 / 12

Some Applications: Moving Around Washington PowerPoint PPT Presentation


  • 40 Views
  • Uploaded on
  • Presentation posted in: General

Some Applications: Moving Around Washington. What’s the fastest way from Seattle to Spokane?. Answer:. Use Dijkstra!. Some Applications: Communication in Washington. What’s the cheapest inter-city network?. New problem for today. 4. 7. 9. 2. 1. 5. Spanning Tree.

Download Presentation

Some Applications: Moving Around Washington

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Some applications moving around washington

Some Applications:Moving Around Washington

What’s the fastest way from Seattle to Spokane?

Answer:

Use Dijkstra!


Some applications communication in washington

Some Applications:Communication in Washington

What’s the cheapest inter-city network?

New problem for today


Spanning tree

4

7

9

2

1

5

Spanning Tree

Spanning tree: a subset of the edges from a connected graph that…

  • touches all vertices in the graph (spans the graph)

  • forms a tree (is connected and contains no cycles)

    Minimum spanning tree: the spanning tree with the least total edge cost.

Which is the minimum? (the middle)


Two different algorithms

Two Different Algorithms

Prim’s Algorithm

Almost identical to Dijkstra’s

Kruskals’s Algorithm

Completely different!

One node, grow greedily

Forest of MSTs,

Union them together.

I wonder how to union…


Prim s algorithm for minimum spanning trees

Prim’s Algorithm for Minimum Spanning Trees

A node-oriented greedy algorithm (builds an MST by greedily adding nodes)

Select a node to be the “root” and mark it as known

While there are unknown nodes left in the graph

Select the unknown node n with the smallest cost from some known node m

Mark n as known

Add (m, n) to our MST

Update cost of all nodes adjacent to n

Cost == edge weight only.

Use priority queue

Runtime:

Proof:

Same as Dijkstra: O(ElogV)

Same as Dijkstra


Prim s algorithm in action

2

2

3

B

A

F

H

2

1

1

4

10

9

G

4

C

8

2

D

E

7

Prim’s Algorithm In Action

Start with A


Kruskal s algorithm for minimum spanning trees

Kruskal’s Algorithm for Minimum Spanning Trees

An edge-oriented greedy algorithm (builds an MST by greedily adding edges)

Initialize all vertices to unconnected

While there are still unmarked edges

Pick the lowest cost edge e = (u, v) and mark it

If u and v are not already connected, add e to the minimum spanning tree and connect u and v

Sound familiar?

Maze use random edge order.Otherwise the same!


Kruskal s algorithm in action

2

2

3

B

A

F

H

2

1

1

4

10

9

G

4

C

8

2

D

E

7

Kruskal’s Algorithm In Action


Play at home with prim

Play at Home with Prim

1

F

6

A

B

H

7

5

3

2

11

12

9

C

G

4

10

13

D

4

E

  • Starting at node A, find the MST using Prim’s method.

  • (continue on next slide)


Play at home with kruskal

Play at Home with Kruskal

1

F

6

A

B

H

7

5

3

2

11

12

9

C

G

4

10

13

D

4

E

  • Now find the MST using Kruskal’s method.

  • Under what conditions will these methods give the same result?

  • What data structures should be used for Kruskal’s? Running time?


Proof of correctness

Proof of Correctness

We already showed this finds a spanning tree:

That was part of our definition of a good maze.

Proof by contradiction that Kruskal’s finds the minimum:

Assume another spanning tree has lower cost than Kruskal’s

Pick an edge e1 = (u, v) in that tree that’s not in Kruskal’s

Kruskal’s tree connects u’s and v’s sets with another edge e2

But, e2 must have at most the same cost as e1!

So, swap e2 for e1 (at worst keeping the cost the same)

Repeat until the tree is identical to Kruskal’s: contradiction!

QED: Kruskal’s algorithm finds a minimum spanning tree.

(contradicts that other tree is better)


Kruskal s implementation

Kruskal’s Implementation

Initialize all vertices to unconnected

While there are still unmarked edges

Pick the lowest cost edge e = (u, v) and mark it

If u and v are not already connected, add e to the minimum spanning tree and connect u and v

E * deleteMin

2E * find + + V * union

What data structures?

Running time?

Priority queue + disjoint sets

O( ElogE + E~O(1)) = O(ElogE) = O(ElogV)b/c log E < logV2 = 2logV


  • Login