Download presentation

Presentation is loading. Please wait.

Published byMargaretMargaret Simmons Modified over 2 years ago

1
Science1 Welcome to: Chapel Hill UNC Computer Science

2
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!

3
Science3 Etc. Restrooms Breaks Lunch Where are the stairs?

4
Science4 Any questions ?

5
Science5 Parallel computing

6
Science6

7
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 weiss@cs.unc.edu

8
Science8 The puzzle

9
Science9 Other puzzles What two words add up to “stuff”? How many different ways to make $1.00 in change? Unscramble “eeiccns”

10
Science10

11
Science11 Brute force problem solving Generate candidates Filter Solutions Trash

12
Science12 Requirements Candidate set must be finite. Must be an “Oh yeah!” problem.

13
Science13 Example Combination lock 60*60*60 = 216,000 candidates

14
Science14 Example

15
Science15 Oh no!

16
Science16 Oh yeah!

17
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.

18
Science18 Caver’s right hand rule

19
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

20
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

21
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

22
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.

23
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.

24
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.

25
Science25 Faster! Reduce size of candidate set. Example: 8-queens, one per row, has only 16,777,216 candidates.

26
Science26 Richard Feynman

27
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.

28
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

29
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?

30
Science30 Solution is a sequence on known length (n) where each element is one of the colors. 1 4 3 2

31
Science31 2. Running a maze: How can you get from start to finish legally in a maze? 20 x 20 grid

32
Science32 Solution is a sequence of unknown length, but bounded by 400, where each element is S, L, or R.

33
Science33 3. Making change. How many ways are there to make $1.00 with coins. Don’t forget Sacagawea.

34
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.

35
Science35 Let’s try the 4-square puzzle Use pieces A, B, F, and G and try to arrange into a 2x2 square.

36
Science36

Similar presentations

OK

B ACKTRACK SEARCH ALGORITHM. B ACKTRACKING Suppose you have to make a series of decisions, among various choices, where You don’t have enough information.

B ACKTRACK SEARCH ALGORITHM. B ACKTRACKING Suppose you have to make a series of decisions, among various choices, where You don’t have enough information.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google