Data Structures in Java
Session 16 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3134
Data Structures in Java Session 16 Instructor: Bert Huang - - PowerPoint PPT Presentation
Data Structures in Java Session 16 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3134 Announcements Homework 4 due next class Midterm grades posted. Avg: 79/90 Remaining grades: hw4, hw5, hw6 25% Final
Session 16 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3134
Graphs Trees
Linked Lists
Linked List Tree Graph
are adjacent
weights along the path (1 if unweighted)
class called a directed acyclic graph (DAG)
every pair of vertices
pair of vertices
Web
transportation
Inference
matrix
1 2 3 4 5
1 2 3 4 5 1 2 3 4 5
1 1 1 1 1 1 1 1 1 1
neighbors
1 2 3 4 5
1
2 3
2
1 4
3
1 4
4
2 3 5
5
4
v ∈ V U ∪ V U ∩ V U ⊂ V (vi, vj) ∈ E
nodes such that for each edge , is before in the ordering.
depend on other tasks being completed.
(vi, vj) ∈ E vi vj
Buy Groceries Cook Dinner Taxes Buy Stamps Mail Tax Form Mail Postcard Go to ATM Fix Computer Look up recipe
Mail recipe to Grandma
indegree means # of incoming edges
to 1.
neighbors.
Buy Groceries Cook Dinner Taxes Buy Stamps Mail Tax Form Mail Postcard Go to ATM Fix Computer Look up recipe
Mail recipe to Grandma
ATM comp grocer- ies recipe stamps taxes cook grand- ma post- card mail taxes 2 1 1 1 2 2 1 2
graph
edges
the shortest (weighted) path from s to every other vertex in G.
travel
∈
116th Broad. 96th Broad. 72nd Broad. Times Square Grand Central 59th Lex. 86th Lex. Penn Station Port Auth. 59th Broad. 125th and 8th 145th and 8th 168th Broad.
nodes (level 2)
116th Broad. 96th Broad. 72nd Broad. Times Square Grand Central 59th Lex. 86th Lex. Penn Station Port Auth. 59th Broad. 125th and 8th 145th and 8th 168th Broad.
168th Broad. 145th Broad. 125th 8th 59th Broad. Port Auth. 116th Broad. 96th Broad. 72nd Broad. Times Sq. Penn St. 86th Lex. 59th Lex. Grand Centr.
dist prev
source
when edges have different weights
using that edge
Algorithm
node v (all non-source nodes are initially infinite)
distance
known
through v is cheaper than the best path so far to w
72nd Broad. Times Square Penn Station Port Auth. 59th Broad.
5 12 10 4 7 2 6
59th Broad. Port Auth. 72nd Broad Times Sq. Penn St. inf inf inf inf ? ? ? ? home
works.
shortest paths we know
greedily adding the shortest neighbor correct?
w through v, but there exists an even shorter path
inside our known set to outside.
s u v w ?
... ...
decreaseKeys (the # of neighbors of node)
deleteMin once per vertex