[CS112] Data Structure Recitation (Section 4, 15) Changkyu Song - - PowerPoint PPT Presentation
[CS112] Data Structure Recitation (Section 4, 15) Changkyu Song - - PowerPoint PPT Presentation
[CS112] Data Structure Recitation (Section 4, 15) Changkyu Song cs1080@cs.rutgers.edu Office Hours: Tue 10:30~12:30 p.m. @ Hill 206 [CS112] Recitation #1 Weighted Adjacency Link List 1 W:0.2 W:0.7 2 3 3 1 2 2 3 T T 1 T T 1
Section 4, 15
[CS112] Recitation
#1 Weighted Adjacency Link List
1 2 3
W:0.2 W:0.7
1 2 3 1 2 3
T w:0.2 T w:0.7 T w:0.2 T w:0.7 F F F F F
1 2 3
T w:0.2 T w:0.7 T w:0.2 T w:0.7
null null null
1 1 2 3
Section 4, 15
[CS112] Recitation
#1 Weighted Adjacency Link List
1 2 3
W:0.2 W:0.7
1 2 3
T w:0.2 T w:0.7 T w:0.2 T w:0.7
null null null
1 1 2 3
T w:0.2
2
class Edge { Node* neighbor; float weight; Edge* next; }
Section 4, 15
[CS112] Recitation
#1 Weighted Adjacency Link List
1 2 3
W:0.2 W:0.7
1 2 3
T w:0.2 T w:0.7 T w:0.2 T w:0.7
null null null
1 1 2 3
T w:0.2
2
n + 3 x 2e
n: # of nodes e: # of edges
1 2 3 1 2 3
class Edge { Node* neighbor; float weight; Edge* next; }
Section 4, 15
[CS112] Recitation
#1 Weighted Adjacency Link List
1 2 3
W:0.2 W:0.7
1 2 3 1 2 3
T w:0.2 T w:0.7 T w:0.2 T w:0.7 F F F F F
1 2 3
T w:0.2 T w:0.7 T w:0.2 T w:0.7
null null null
1 1 2 3
n + 3 x 2e
n: # of nodes e: # of edges
n2
Section 4, 15
[CS112] Recitation
#1 Weighted Adjacency Link List
1 2 3
W:0.2 W:0.7
1 2 3 1 2 3
T w:0.2 T w:0.7 T w:0.2 T w:0.7 F F F F F
1 2 3
T w:0.2 T w:0.7 T w:0.2 T w:0.7
null null null
1 1 2 3
n + 3 x 2e
n: # of nodes e: # of edges
n2 n2 < n + 3 x 2e
Section 4, 15
[CS112] Recitation
#1 Weighted Adjacency Link List
1 2 3
W:0.2 W:0.7
n + 3 x 2e
n: # of nodes e: # of edges
n2 n2 < n + 3 x 2e (n2 - n)/(3x2) < e min{e} = (n2 - n)/(3x2) + 1
Section 4, 15
[CS112] Recitation
#2 Complement Graph
1 2 3 1 2 3 1 2 3
T T T T F F F F F
1 2 3
T T T T
null null null
1 1 2 3
G =
Section 4, 15
[CS112] Recitation
#2 Complement Graph
1 2 3 1 2 3 1 2 3
F F F F T T T T T
1 2 3 Gc =
T T
null
2 3
T T
null
2 3
T
null
1
Section 4, 15
[CS112] Recitation
#2 Complement Graph
1 2 3 1 2 3
T T T T F F F F F
1 2 3
T T T T
null null null
1 1 2 3
Section 4, 15
[CS112] Recitation
#2 Complement Graph
1
2
3
1 2 3
F F F F T T T T T
1 2 3 1 2 3
T T T T F F F F F
Section 4, 15
[CS112] Recitation
#2 Complement Graph
1
2
3
1 2 3
F F F F T T T T T
1 2 3
T T
null
2 3
T T
null
2 3
T
null
1
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T …
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … DFS
S 2 3 1 n T … S 2 3 1 n T …
…
S 2 3 1 n T … S 2 3 1 n T … S 2 3 1 n T … S 2 3 1 n T …
… … … 1st – 2nd – 3rd – 4th – … n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … DFS 2nd search is dependent to the 1st choice. Permutation of (n) = n x (n-1) x (n-2) x (n-3) … x 1 = n! 1st – 2nd – 3rd – 4th – … n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … BFS
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … BFS
S 2 3 1 n T … S 2 3 1 n T …
…
S 2 3 1 n T … S 2 3 1 n T … S 2 3 1 n T …
1st – 2nd – 3rd – … nth – n+1th –
S 2 3 1 n T …
… … …
Section 4, 15
[CS112] Recitation
#3 DFS vs. BFS
S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th – n+1nd search is dependent to the 1st choice. Permutation of (n) = n x (n-1) x (n-2) x (n-3) … x 1 = n!
Section 4, 15
[CS112] Recitation
#4 hasPath
Section 4, 15
[CS112] Recitation
#5
Section 4, 15
[CS112] Recitation
#5
Section 4, 15
[CS112] Recitation
#5
Section 4, 15