[关闭]
@w1024020103 2017-05-13T17:57:05.000000Z 字数 1017 阅读 964

Lecture 29: DFS vs. BFS, Shortest Paths

CS61B


Summary So Far

Rechability

image_1bftugks978alhn7cvj09s3i9.png-138.7kB

BFS uses lots of memory for VERY WIDE GRAPH. One vertex connected to 1,000,000 vertices: because it puts lots of stuff on a queue.

DFS uses lots of memory for a spindly graph, because a giant
sequence of recursive in Java uses memory linear in # of recursive calls.

image_1bftukd8q58b8ocn7i9cv12im.png-58.7kB

Graph problems so far

image_1bftv46olqrlhq1qen18k7hm513.png-152.2kB

quiz:
image_1bftvajp71uq71bd6hjlt0be4a1g.png-88kB

Dijkstra’s Algorithm

Goal: find the shortest path from the source vertex s to every other vertex.

image_1bfu0riee16ro1tlmdr7f12ceq1t.png-145.6kB

SPT edge count

image_1bfu0vmlntbhu476lv1m9q105l2n.png-119.5kB

Dijkstra's Algorithm

image_1bfu13ias15tbn1m137d1et14j134.png-104.7kB

Dijkstra's demo

Dijkstra's runtime

image_1bfu7ijjctfcpar13sa1isrj453h.png-92kB

Implementation

32.JPG-86.8kB

33.JPG-91.9kB

Graph Problems so far

image_1bfu7m0ljo3e1g9b8rf1i6n8114m.png-110kB

Dijkstra's algorithm will find the shortest path from the source vertex to every other vertexes, this will waste a lot of memory in the specific situation:

Video:
Graphs: Dijkstra's Algorithm

Dijkstra Algorithm Example

Shortest Path using Dijkstra's Algorithm

dijkstras-shortest-path-algorith

DijkstraSP.java
image_1bfu7n1q21mentb1nqoq4eh7453.png-461.2kB

自己试着做一遍:

image_1bfvvq2e514kc1e2e1bel8hq1g5um.png-178.6kB

A*

we don't want to find the shortest path from vertex to every other vertex, but only want to find one target.

image_1bg0i24tljpt1ivc10t14tmo3b9.png-462.9kB

D(denver, NYC) = d(denver, v) + h(v):

37.JPG-101.2kB

image_1bg0i5s839ttkj9c1110dlf712.png-331.4kB

Impact of heuristic quality

image_1bg0ipqvdlrs1dsksd9fou1e4n1f.png-287.3kB

当h(v)不正确的时候,会得不到正确的答案,这里把h(v)正确叫做:admissible.

39.JPG-79.6kB

A* vs Dijkstra

image_1bg0it0ghdpq1frkkbn1fud1l7c28.png-107.9kB

Graph problem runtime

41.JPG-100.9kB

Extra: A* Properties, Iterative DFS, Kevin Bacon

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注