CSC 172 DATA STRUCTURES - PowerPoint PPT Presentation

About This Presentation
Title:

CSC 172 DATA STRUCTURES

Description:

CSC 172 DATA STRUCTURES Traversing graphs Depth-First Search like a post-order traversal of a tree Breath-First Search Less like tree traversal Traversing graphs ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 23
Provided by: Thadd2
Category:
Tags: csc | data | structures | depth | first | search

less

Transcript and Presenter's Notes

Title: CSC 172 DATA STRUCTURES


1
CSC 172 DATA STRUCTURES
2
Traversing graphs
  • Depth-First Search
  • like a post-order traversal of a tree
  • Breath-First Search
  • Less like tree traversal

3
Traversing graphs
  • Depth-First Search
  • like a post-order traversal of a tree
  • Breath-First Search
  • Less like tree traversal
  • Priority-First Search
  • Good for Shortest Path
  • Dijkstra's Algorithm

4
Breadth-First Search
  • Unweighted Shortest Path
  • Starting vertex has level 0 (anchor vertex)
  • Visit (mark) all vertices that are only one edge
    away
  • mark each vertex with its level
  • One edge away from level 0 is level 1
  • One edge away from level 1 is level 2
  • Etc. . . .

5
Example
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
6
Example
0
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
7
Example
0
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
8
Example
0
1
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
9
Example
0
1
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
10
Example
2
0
1
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
11
Example
2
0
1
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
12
Example
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
13
Example
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
N
O
P
M
14
Example
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
4
N
O
P
M
15
Example
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
4
N
O
P
M
16
Example
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
4
N
O
P
M
17
Example
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
4
N
O
P
M
18
Example
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
4
5
N
O
P
M
19
Example
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
4
5
N
O
P
M
20
BFS Tree
2
3
0
1
B
C
D
A
F
G
H
E
J
K
L
I
4
5
N
O
P
M
21
Dijkstra's Algorithm
  • //
  • for each Vertex v
  • v.dist infinity
  • v.known false

22
Dijkstra's Algorithm
  • while (there is an unknown vertex)
  • v delMin() // get the next one off the
    queue
  • v.known true
  • for each Vertex w adjacent to v
  • if (!w.known)
  • if (v.dist dist_v2w lt w.dist)
  • w.dist vdist dist_v2w
  • enqueue(w)
Write a Comment
User Comments (0)
About PowerShow.com