science1 welcome to: chapel hill unc computer science
TRANSCRIPT
Science 1
Welcome to:
Chapel Hill
UNC
Computer Science
Science 2
Agenda
WelcomeParallel computing exerciseProtein folding and origamiExtended break: Meet with our students
ACM Programming teamFirst year seminar: Lego robotsFirst year seminar: Computer animation (room 030)Deltasphere
Sessions: 10:35, 11:15, 1:00, 1:40Virtual reality demo (ticket)Russ Taylor: Visualization (sessions 1 and 2)Jan Prins: Parallel computing (sessions 1 and 2)Jack Snoeyink & Wei Wang: Protein folding (all sessions)Kevin Jeffay: Computer networking (sessions 3 and 4)Steve Weiss: Brute force (sessions 3 and 4)
Round table: CS curriculum, careers, all questions answered!
Science 3
Etc.
RestroomsBreaksLunchWhere are the stairs?
Science 4
Any questions
?
Science 5
Parallel computing
Science 6
Science 7
Brute force and backtracking(or how to open your friends’
lockers)
Steve Weiss
Department of Computer Science
University of North Carolina at Chapel Hill
Science 8
The puzzle
Science 9
Other puzzles
• What two words add up to “stuff”?
• How many different ways to make $1.00 in change?
• Unscramble “eeiccns”
Science 10
Science 11
Brute force problem solving
Generate candidates
FilterSolutions
Trash
Science 12
Requirements
• Candidate set must be finite.
• Must be an “Oh yeah!” problem.
Science 13
Example
Combination lock
60*60*60 = 216,000
candidates
Science 14
Example
Science 15
Oh no!
Science 16
Oh yeah!
Science 17
Additional 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.
Science 18
Caver’s right hand rule
Science 19
Generating the candidates
Classic backtrack algorithm:
At decision point, do something new (extend something that hasn’t been added to this sequence at this place before.)
Fail: Backtrack: Undo most recent decision (retract). Fail: done
Science 20
Recursive backtrack algorithm(pseudo Java)
backtrack(Sequence s)
{ for each si in T
{ s.extend(si);
if (s.size() == MAX) // Complete sequence
display(s);
else
backtrack(s);
s.retract();
} // End of for
} // End of backtrack
Science 21
Problem solver
backtrack(Sequence s)
{ for each si in T
{ s.extend(si);
if (s.size() == MAX) // Complete sequence
if (s.solution()) display(s);
else
backtrack(s);
s.retract();
} // End of for
} // End of backtrack
Science 22
Problems
• Too slow, even on very fast machines.
• Case study: 8-queens
• Example: 8-queens has more than 281,474,976,711,000 candidates.
Science 23
8-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.
Science 24
Problems
• Too slow, even on very fast machines.
• Case study: 8-queens
• Example: 8-queens has more than 281,474,976,711,000 candidates.
Science 25
Faster!
• Reduce size of candidate set.
• Example: 8-queens, one per row, has only 16,777,216 candidates.
Science 26
Richard Feynman
Science 27
Faster 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.
Science 28
Backtrack with pruning
backtrack(Sequence s)
{ for each si in T
if (s.okToAdd(si)) // Pruning
{ s.extend(si);
if (s.size() == MAX) // Complete solution
display(s);
else
backtrack(s);
s.retract();
} // End of if
} // End of backtrack
Science 29
Still more puzzles
1.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?
Science 30
Solution is a sequence on known length (n) where each element is one of the colors.
1
43
2
Science 31
2. Running a maze: How can you get from start to finish legally in a maze?
20 x 20 grid
Science 32
Solution is a sequence of unknown length, but bounded by 400, where each element is S, L, or R.
Science 33
3. Making change.
How many ways are there to make $1.00 with coins. Don’t forget Sacagawea.
Science 34
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.
Science 35
Let’s try the 4-square puzzle
• Use pieces A, B, F, and G and try to arrange into a 2x2 square.
Science 36