Science1 Welcome to: Chapel Hill UNC Computer Science
Science2 Agenda Welcome Parallel computing exercise Protein folding and origami Extended break:Meet with our students ACM Programming team First year seminar: Lego robots First year seminar: Computer animation (room 030) Deltasphere Sessions: 10:35, 11:15, 1:00, 1:40 Virtual 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!
Science3 Etc. Restrooms Breaks Lunch Where are the stairs?
Science4 Any questions ?
Science5 Parallel computing
Science6
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
Science8 The puzzle
Science9 Other puzzles What two words add up to “stuff”? How many different ways to make $1.00 in change? Unscramble “eeiccns”
Science10
Science11 Brute force problem solving Generate candidates Filter Solutions Trash
Science12 Requirements Candidate set must be finite. Must be an “Oh yeah!” problem.
Science13 Example Combination lock 60*60*60 = 216,000 candidates
Science14 Example
Science15 Oh no!
Science16 Oh yeah!
Science17 Additional restrictions Solution is a sequence s 1, s 2,…,s n Solution length, n, is known (or at least bounded) in advance. Each s i is drawn from a finite pool T.
Science18 Caver’s right hand rule
Science19 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
Science20 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
Science21 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
Science22 Problems Too slow, even on very fast machines. Case study: 8-queens Example: 8-queens has more than 281,474,976,711,000 candidates.
Science23 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.
Science24 Problems Too slow, even on very fast machines. Case study: 8-queens Example: 8-queens has more than 281,474,976,711,000 candidates.
Science25 Faster! Reduce size of candidate set. Example: 8-queens, one per row, has only 16,777,216 candidates.
Science26 Richard Feynman
Science27 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.
Science28 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
Science29 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?
Science30 Solution is a sequence on known length (n) where each element is one of the colors
Science31 2. Running a maze: How can you get from start to finish legally in a maze? 20 x 20 grid
Science32 Solution is a sequence of unknown length, but bounded by 400, where each element is S, L, or R.
Science33 3. Making change. How many ways are there to make $1.00 with coins. Don’t forget Sacagawea.
Science34 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.
Science35 Let’s try the 4-square puzzle Use pieces A, B, F, and G and try to arrange into a 2x2 square.
Science36