[CS112] Data Structure Recitation (Section 4, 15) Changkyu Song - - PowerPoint PPT Presentation

cs112 data structure recitation
SMART_READER_LITE
LIVE PREVIEW

[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


slide-1
SLIDE 1

[CS112] Data Structure Recitation

(Section 4, 15)

Changkyu Song cs1080@cs.rutgers.edu Office Hours: Tue 10:30~12:30 p.m. @ Hill 206

slide-2
SLIDE 2

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

slide-3
SLIDE 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; }

slide-4
SLIDE 4

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; }

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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 =

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T …

slide-14
SLIDE 14

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –

slide-15
SLIDE 15

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –

slide-16
SLIDE 16

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –

slide-17
SLIDE 17

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –

slide-18
SLIDE 18

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … DFS 1st – 2nd – 3rd – 4th – … n+1th –

slide-19
SLIDE 19

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 –

slide-20
SLIDE 20

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 –

slide-21
SLIDE 21

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … BFS

slide-22
SLIDE 22

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –

slide-23
SLIDE 23

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –

slide-24
SLIDE 24

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –

slide-25
SLIDE 25

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –

slide-26
SLIDE 26

Section 4, 15

[CS112] Recitation

#3 DFS vs. BFS

S 2 3 1 n T … BFS 1st – 2nd – 3rd – … nth – n+1th –

slide-27
SLIDE 27

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 …

… … …

slide-28
SLIDE 28

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!

slide-29
SLIDE 29

Section 4, 15

[CS112] Recitation

#4 hasPath

slide-30
SLIDE 30

Section 4, 15

[CS112] Recitation

#5

slide-31
SLIDE 31

Section 4, 15

[CS112] Recitation

#5

slide-32
SLIDE 32

Section 4, 15

[CS112] Recitation

#5

slide-33
SLIDE 33

Section 4, 15

[CS112] Recitation

Q & A