Title: Welcome to:
1Welcome to Chapel Hill UNC Computer Science
2Steve Weiss Department of Computer
Science University of North Carolina at Chapel
Hill weiss_at_cs.unc.edu
3Parallel computing
4(No Transcript)
5Brute force and backtracking(or how to open your
friends lockers)
6The puzzle
7Other puzzles
- What two words add up to stuff?
- How many different ways to make 1.00 in change?
- Unscramble eeiccns
8 9Brute force problem solving
Generate candidates
Filter
Solutions
Trash
10Requirements
- Candidate set must be finite.
- Must be an Oh yeah! problem.
11Example
Combination lock 606060 216,000 candidates
12Example
13Oh no!
14Oh yeah!
15Additional restrictions
- Solution is a sequence s1, s2,,sn
- Solution length, n, is known (or at least
bounded) in advance. - Each si is drawn from a finite pool T.
16Cavers right hand rule
17Generating the candidates
Classic backtrack algorithm At decision point,
do something new (extend something that hasnt
been added to this sequence at this place
before.) Fail Backtrack
Undo most recent decision (retract).
Fail done
18Problems
- Too slow, even on very fast machines.
- Case study 8-queens
- Example 8-queens has more than
281,474,976,711,000 candidates.
198-queens
- How can you place 8 queens on a chessboard so
that no queen threatens any of the others. - Queens can move left, right, up, down, and along
both diagonals.
20Problems
- Too slow, even on very fast machines.
- Case study 8-queens
- Example 8-queens has more than
281,474,976,711,000 candidates.
21Faster!
- Reduce size of candidate set.
- Example 8-queens, one per row, has only
16,777,216 candidates.
22Richard Feynman
23Faster still!
- Prune reject nonviable candidates early, not
just when sequence is complete. - Example 8-queens with pruning looks at about
16,000 partial and complete candidates.
24Still more puzzles
- Map coloring Given a map with n regions, and a
palate of c colors, how many ways can you color
the map so that no regions that share a border
are the same color?
25- Solution is a sequence on known length (n) where
each element is one of the colors.
1
2
4
3
26- 2. Running a maze How can you get from start to
finish legally in a maze?
20 x 20 grid
27- Solution is a sequence of unknown length, but
bounded by 400, where each element is S,
L, or R.
28- 3. Making change.
- How many ways are there to make 1.00 with coins.
Dont forget Sacagawea.
29- 4. Solving the 9 square problem.
- Solution is sequence of length 9 where each
element is a different puzzle piece and where the
touching edges sum to zero.
30Lets try the 4-square puzzle
- Use pieces A, B, F, and G and try to arrange into
a 2x2 square.
31(No Transcript)