Download presentation
Presentation is loading. Please wait.
1
Flooding © 2018
2
Flooding If the spot on the drawing is not empty return
Color the spot using c Create a to-do list with spot as its element While the to-do list is not empty Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
3
Example
4
Suppose spot is ( 6, 12 ) spot on drawing is not empty, so no flooding to perform
5
Suppose spot is ( 7, 7 ) spot on drawing is empty, so there is flooding to perform
6
Flood drawing starting at spot ( 7, 7 ) using c
7
Flood drawing starting at spot ( 7, 7 ) using c
8
Flood drawing starting at spot ( 7, 7 ) using c
9
Paint spot spot (7,7) c
10
Create to-do list spot (7,7) c to-do list
11
Add spot to to-do list spot (7,7) c to-do list (7,7)
12
Loop while to-do list is not empty
spot (7,7) c to-do list (7,7)
13
Loop while to-do list is not empty
spot (7,7) c to-do list (7,7) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
14
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
15
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
16
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list (6,7) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
17
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list (6,7) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
18
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list (6,7) (8,7) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
19
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list (6,7) (8,7) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
20
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list (6,7) (8,7) (7,6) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
21
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list (6,7) (8,7) (7,6) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
22
Loop while to-do list is not empty
spot (7,7) c v (7,7) to-do list (6,7) (8,7) (7,6) (7,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
23
Loop while to-do list is not empty
spot (7,7) c v (6,7) to-do list (8,7) (7,6) (7,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
24
Loop while to-do list is not empty
spot (7,7) c v (6,7) to-do list (8,7) (7,6) (7,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
25
Loop while to-do list is not empty
spot (7,7) c v (6,7) to-do list (8,7) (7,6) (7,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
26
Loop while to-do list is not empty
spot (7,7) c v (6,7) to-do list (8,7) (7,6) (7,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
27
Loop while to-do list is not empty
spot (7,7) c v (6,7) to-do list (8,7) (7,6) (7,8) (6,6) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
28
Loop while to-do list is not empty
spot (7,7) c v (6,7) to-do list (8,7) (7,6) (7,8) (6,6) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
29
Loop while to-do list is not empty
spot (7,7) c v (6,7) to-do list (8,7) (7,6) (7,8) (6,6) (6,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
30
Loop while to-do list is not empty
spot (7,7) c v (8,7) to-do list (7,6) (7,8) (6,6) (6,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
31
Loop while to-do list is not empty
spot (7,7) c v (8,7) to-do list (7,6) (7,8) (6,6) (6,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
32
Loop while to-do list is not empty
spot (7,7) c v (8,7) to-do list (7,6) (7,8) (6,6) (6,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
33
Loop while to-do list is not empty
spot (7,7) c v (8,7) to-do list (7,6) (7,8) (6,6) (6,8) (9,7) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
34
Loop while to-do list is not empty
spot (7,7) c v (8,7) to-do list (7,6) (7,8) (6,6) (6,8) (9,7) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
35
Loop while to-do list is not empty
spot (7,7) c v (8,7) to-do list (7,6) (7,8) (6,6) (6,8) (9,7) (8,6) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
36
Loop while to-do list is not empty
spot (7,7) c v (8,7) to-do list (7,6) (7,8) (6,6) (6,8) (9,7) (8,6) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
37
Loop while to-do list is not empty
spot (7,7) c v (8,7) to-do list (7,6) (7,8) (6,6) (6,8) (9,7) (8,6) (8,8) y Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
38
Loop while to-do list is not empty
spot (7,7) c v (7,6) to-do list (7,8) (6,6) (6,8) (9,7) (8,6) (8,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
39
Loop while to-do list is not empty
spot (7,7) c v (7,6) to-do list (7,8) (6,6) (6,8) (9,7) (8,6) (8,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
40
Loop while to-do list is not empty
spot (7,7) c v (7,6) to-do list (7,8) (6,6) (6,8) (9,7) (8,6) (8,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
41
Loop while to-do list is not empty
spot (7,7) c v (7,6) to-do list (7,8) (6,6) (6,8) (9,7) (8,6) (8,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
42
Loop while to-do list is not empty
spot (7,7) c v (7,6) to-do list (7,8) (6,6) (6,8) (9,7) (8,6) (8,8) (7,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
43
Loop while to-do list is not empty
spot (7,7) c v (7,6) to-do list (7,8) (6,6) (6,8) (9,7) (8,6) (8,8) (7,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
44
Loop while to-do list is not empty
spot (7,7) c v (7,8) to-do list (6,6) (6,8) (9,7) (8,6) (8,8) (7,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
45
Loop while to-do list is not empty
spot (7,7) c v (7,8) to-do list (6,6) (6,8) (9,7) (8,6) (8,8) (7,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
46
Loop while to-do list is not empty
spot (7,7) c v (6,6) to-do list (6,8) (9,7) (8,6) (8,8) (7,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
47
Loop while to-do list is not empty
spot (7,7) c v (6,6) to-do list (6,8) (9,7) (8,6) (8,8) (7,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
48
Loop while to-do list is not empty
spot (7,7) c v (6,6) to-do list (6,8) (9,7) (8,6) (8,8) (7,5) (6,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
49
Loop while to-do list is not empty
spot (7,7) c v (6,8) to-do list (9,7) (8,6) (8,8) (7,5) (6,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
50
Loop while to-do list is not empty
spot (7,7) c v (6,8) to-do list (9,7) (8,6) (8,8) (7,5) (6,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
51
Loop while to-do list is not empty
spot (7,7) c v (6,8) to-do list (9,7) (8,6) (8,8) (7,5) (6,5) (5,8) (6,9) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
52
Loop while to-do list is not empty
spot (7,7) c v (9,7) to-do list (8,6) (8,8) (7,5) (6,5) (5,8) (6,9) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
53
Loop while to-do list is not empty
spot (7,7) c v (9,7) to-do list (8,6) (8,8) (7,5) (6,5) (5,8) (6,9) (10,7) (9,6) (9,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
54
Loop while to-do list is not empty
spot (7,7) c v (8,6) to-do list (8,8) (7,5) (6,5) (5,8) (6,9) (10,7) (9,6) (9,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
55
Loop while to-do list is not empty
spot (7,7) c v (8,6) to-do list (8,8) (7,5) (6,5) (5,8) (6,9) (10,7) (9,6) (9,8) (8,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
56
Loop while to-do list is not empty
spot (7,7) c v (8,8) to-do list (7,5) (6,5) (5,8) (6,9) (10,7) (9,6) (9,8) (8,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
57
Loop while to-do list is not empty
spot (7,7) c v (8,8) to-do list (7,5) (6,5) (5,8) (6,9) (10,7) (9,6) (9,8) (8,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
58
Loop while to-do list is not empty
spot (7,7) c v (7,5) to-do list (6,5) (5,8) (6,9) (10,7) (9,6) (9,8) (8,5) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
59
Loop while to-do list is not empty
spot (7,7) c v (7,5) to-do list (6,5) (5,8) (6,9) (10,7) (9,6) (9,8) (8,5) (7,4) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
60
Loop while to-do list is not empty
spot (7,7) c v (6,5) to-do list (5,8) (6,9) (10,7) (9,6) (9,8) (8,5) (7,4) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
61
Loop while to-do list is not empty
spot (7,7) c v (6,5) to-do list (5,8) (6,9) (10,7) (9,6) (9,8) (8,5) (7,4) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
62
Loop while to-do list is not empty
spot (7,7) c v (5,8) to-do list (6,9) (10,7) (9,6) (9,8) (8,5) (7,4) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
63
Loop while to-do list is not empty
spot (7,7) c v (5,8) to-do list (6,9) (10,7) (9,6) (9,8) (8,5) (7,4) (4,8) (5,9) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
64
Loop while to-do list is not empty
spot (7,7) c v (6,9) to-do list (10,7) (9,6) (9,8) (8,5) (7,4) (4,8) (5,9) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
65
Loop while to-do list is not empty
spot (7,7) c v (6,9) to-do list (10,7) (9,6) (9,8) (8,5) (7,4) (4,8) (5,9) (6,10) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
66
Loop while to-do list is not empty
spot (7,7) c v (10,7) to-do list (9,6) (9,8) (8,5) (7,4) (4,8) (5,9) (6,10) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
67
Loop while to-do list is not empty
spot (7,7) c v (10,7) to-do list (9,6) (9,8) (8,5) (7,4) (4,8) (5,9) (6,10) (11,7) (10,6) (10,8) Pop an element from the to-do list and assign it to v If v’s left is empty, paint it and add to to-do list If v’s right is empty, paint it and add to to-do list If v’s above is empty, paint it and add to to-do list If v’s below is empty, paint it and add to to-do list
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.