Download presentation
Presentation is loading. Please wait.
1
More Recursion
2
Binary Strings "" 3 steps to go "0" "1" 2 steps to go "00" "01" "10"
"11" 1 step to go "000" "001" "010" "011" "100" "101" "110" "111" done
3
Binary Strings
4
Towers Of Hanoi 3 Pegs & Stack of disks Get from one peg to another
Can only move one disk at a time Big disks can not be on top of small disks
5
Decomposition To move 3 disks from A to C
Move top 2 to B Move last to C Move 2 from B to C
6
Towers Of Hanoi 3 disks = 7 moves N disks = 2n – 1 moves
7
N-Queens Eight Queens Each must be on own row/col/diagonal
8
Representation Single array : what col is queen in?
9
Code Do not need to copy – moving queen overwrites old move
10
Flood Fill Flood Fill Color starting square Try to color square above
Try to color square below Try to color square to left Try to color square to right
11
Shared Data Flood fill works on one copy of data
Array passed as memory addresses Every recursive call uses same array
12
Path Finding Find a path… If goal, done = return 0
If bad square return Else Mark square Ask left how far Ask right how far Ask up how far Ask down how far Return 1 + shortest of neighbors
13
Path Finding
14
Path Finding Want to explore different paths Each path needs own array
Need to copy current maze before marking move
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.