Professional Documents
Culture Documents
Backtracking
Backtracking
Backtracking
Solving a maze
Coloring a map
Solving a puzzle
Backtracking (animation)
dead end
?
dead end
start
dead end
dead end
dead end
?
success!
7
Terminology I
A tree is composed of nodes
Terminology II
parent
children
children
9
10
11
12
Data structures
13
int map[][];
void createMap() {
map = new int[7][];
map[0] = new int[] {
map[1] = new int[] {
map[2] = new int[] {
map[3] = new int[] {
map[4] = new int[] {
map[5] = new int[] {
map[6] = new int[] {
}
1
4
2 3
5
1,
0,
0,
2,
0,
2,
2,
4,
4,
4,
4,
1,
6,
3,
2, 5 };
6, 5 };
3, 6, 5 };
6 };
6, 3, 2 };
1, 0 };
4, 1, 5 };
14
final
final
final
final
final
int
int
int
int
int
NONE = 0;
RED = 1;
YELLOW = 2;
GREEN = 3;
BLUE = 4;
15
16
18
19
Recap
The End
21