Title: Graphs Trees
1Chapter 15
Graphs Trees Networks
2(No Transcript)
3 Example
X Y
Z
T 5 VERTICES 6 EDGES
S
4 Collection List
Set  ArrayList LinkedList
SortedSet Â
HashSet
TreeSet
5(No Transcript)
6(No Transcript)
7(No Transcript)
8 X Y
Z
T X, Y, T, Z, S has length 4. Shortest path from
X to S ?
S In general, how can the smallest
path between 2 vertices be determined?
9(No Transcript)
10 X Y
Z
T X, Y, T, Z, X is a cycle. Y, T, S, Z, T, Y is
not a cycle.
S Is Y, Z, T, S, Z, X, Y
a cycle?
11 Collection List
Set  ArrayList LinkedList
SortedSet Â
HashSet
TreeSet This undirected graph is
acyclic.
12(No Transcript)
13(No Transcript)
14(No Transcript)
15(No Transcript)
16(No Transcript)
17(No Transcript)
18(No Transcript)
19(No Transcript)
20(No Transcript)
21 Collection List
Set  ArrayList LinkedList
SortedSet Â
HashSet
TreeSet
22(No Transcript)
23(No Transcript)
24(No Transcript)
25(No Transcript)
26(No Transcript)
27(No Transcript)
28(No Transcript)
29(No Transcript)
30(No Transcript)
31 x v
Y
Z
T
S Assume the
vertices are entered in alphabetical
order. Perform a breadth-first iteration from S.
32(No Transcript)
33(No Transcript)
34(No Transcript)
35(No Transcript)
36(No Transcript)
37(No Transcript)
38(No Transcript)
39 X V
Y
Z
T
S
40Assume the edges are inserted into the graph as
follows S, T (Same as T, S) S, Z T, Y T,
Z V, Y V, Z X, Y X, Z Perform a breadth-first
iteration from S.
41 queue Vertex returned by next( ) S
T, Z S Z, Y T Y, V, X Z V,
X Y X V
X
42Note For a breadth-first iteration of a directed
graph, the algorithm is the same, but neighbor
takes into account the direction of the
arrow.
A
B C
D For a breadth-first iteration starting
at A, the neighbors of A are B and C, but not D.
43(No Transcript)
44 Collection List
Set  ArrayList LinkedList
SortedSet Â
HashSet
TreeSet
45(No Transcript)
46A Stack!
47(No Transcript)
48(No Transcript)
49 X V
Y
Z
T
S
50Assume the edges are inserted into the graph as
follows S, T // Same as T, S S, Z T, Y T,
Z V, Y V, Z X, Y X, Z Perform a depth-first
iteration from S.
51 Stack Vertex returned by next( ) S
Z, T S X, V, T Z Y, V, T X V,
T Y T
V T Top of stack is leftmost.
52(No Transcript)
53(No Transcript)
54(No Transcript)
55(No Transcript)
56(No Transcript)
57(No Transcript)
58(No Transcript)
59(No Transcript)
60(No Transcript)
61(No Transcript)
62(No Transcript)
63(No Transcript)
64(No Transcript)
65(No Transcript)
66(No Transcript)
67(No Transcript)
68(No Transcript)
69(No Transcript)
70(No Transcript)
71(No Transcript)
72(No Transcript)
73(No Transcript)
74(No Transcript)
75(No Transcript)
76(No Transcript)
77(No Transcript)
78(No Transcript)
79(No Transcript)
80(No Transcript)
81(No Transcript)
82(No Transcript)
83(No Transcript)
84(No Transcript)
85(No Transcript)
86(No Transcript)
87(No Transcript)
88(No Transcript)
89(No Transcript)
90(No Transcript)
91(No Transcript)
92(No Transcript)
93(No Transcript)
94(No Transcript)
95(No Transcript)
96(No Transcript)
97(No Transcript)
98(No Transcript)
99(No Transcript)
100(No Transcript)
101(No Transcript)
102(No Transcript)
103(No Transcript)
104(No Transcript)
105(No Transcript)
106(No Transcript)
107(No Transcript)
108A collection in which order is unimportant A
linked list
109(No Transcript)
110(No Transcript)
111(No Transcript)
112(No Transcript)
113(No Transcript)
114(No Transcript)
115(No Transcript)
116(No Transcript)
117(No Transcript)
118(No Transcript)
119(No Transcript)
120(No Transcript)
121(No Transcript)
122(No Transcript)
123(No Transcript)
124(No Transcript)
125(No Transcript)
126(No Transcript)
127(No Transcript)
128(No Transcript)
129(No Transcript)
130(No Transcript)
131(No Transcript)
132(No Transcript)
133(No Transcript)
134(No Transcript)
135(No Transcript)
136(No Transcript)
137(No Transcript)
138(No Transcript)
139(No Transcript)
140(No Transcript)
141(No Transcript)
142(No Transcript)
143(No Transcript)
144(No Transcript)