Welcome to Chapel Hill UNC Computer Science 112022































- Slides: 31
Welcome to: Chapel Hill UNC Computer Science 1/1/2022 Explore Carolina 2004 1
Steve Weiss Department of Computer Science University of North Carolina at Chapel Hill weiss@cs. unc. edu 1/1/2022 Explore Carolina 2004 2
Parallel computing 1/1/2022 Explore Carolina 2004 3
1/1/2022 Explore Carolina 2004 4
Brute force and backtracking (or how to open your friends’ lockers) 1/1/2022 Explore Carolina 2004 5
The puzzle 1/1/2022 Explore Carolina 2004 6
Other puzzles • What two words add up to “stuff”? • How many different ways to make $1. 00 in change? • Unscramble “eeiccns” 1/1/2022 Explore Carolina 2004 7
1/1/2022 Explore Carolina 2004 8
Brute force problem solving Generate candidates Filter Solutions Trash 1/1/2022 Explore Carolina 2004 9
Requirements • Candidate set must be finite. • Must be an “Oh yeah!” problem. 1/1/2022 Explore Carolina 2004 10
Example Combination lock 60*60*60 = 216, 000 candidates 1/1/2022 Explore Carolina 2004 11
Example 1/1/2022 Explore Carolina 2004 12
Oh no! 1/1/2022 Explore Carolina 2004 13
Oh yeah! 1/1/2022 Explore Carolina 2004 14
Additional restrictions • Solution is a sequence s 1, s 2, …, sn • Solution length, n, is known (or at least bounded) in advance. • Each si is drawn from a finite pool T. 1/1/2022 Explore Carolina 2004 15
Caver’s right hand rule 1/1/2022 Explore Carolina 2004 16
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 1/1/2022 Explore Carolina 2004 17
Problems • Too slow, even on very fast machines. • Case study: 8 -queens • Example: 8 -queens has more than 281, 474, 976, 711, 000 candidates. 1/1/2022 Explore Carolina 2004 18
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. 1/1/2022 Explore Carolina 2004 19
Problems • Too slow, even on very fast machines. • Case study: 8 -queens • Example: 8 -queens has more than 281, 474, 976, 711, 000 candidates. 1/1/2022 Explore Carolina 2004 20
Faster! • Reduce size of candidate set. • Example: 8 -queens, one per row, has only 16, 777, 216 candidates. 1/1/2022 Explore Carolina 2004 21
Richard Feynman 1/1/2022 Explore Carolina 2004 22
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. 1/1/2022 Explore Carolina 2004 23
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? 1/1/2022 Explore Carolina 2004 24
Solution is a sequence on known length (n) where each element is one of the colors. 1 2 3 1/1/2022 4 Explore Carolina 2004 25
2. Running a maze: How can you get from start to finish legally in a maze? 20 x 20 grid 1/1/2022 Explore Carolina 2004 26
Solution is a sequence of unknown length, but bounded by 400, where each element is S, L, or R. 1/1/2022 Explore Carolina 2004 27
3. Making change. How many ways are there to make $1. 00 with coins. Don’t forget Sacagawea. 1/1/2022 Explore Carolina 2004 28
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. 1/1/2022 Explore Carolina 2004 29
Let’s try the 4 -square puzzle • Use pieces A, B, F, and G and try to arrange into a 2 x 2 square. 1/1/2022 Explore Carolina 2004 30
1/1/2022 Explore Carolina 2004 31