36
Science 1 Welcome to: Chapel Hill UNC Computer Science

Science1 Welcome to: Chapel Hill UNC Computer Science

Embed Size (px)

Citation preview

Page 1: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 1

Welcome to:

Chapel Hill

UNC

Computer Science

Page 2: Science1 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!

Page 3: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 3

Etc.

RestroomsBreaksLunchWhere are the stairs?

Page 4: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 4

Any questions

?

Page 5: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 5

Parallel computing

Page 6: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 6

Page 7: Science1 Welcome to: Chapel Hill UNC Computer Science

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

[email protected]

Page 8: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 8

The puzzle

Page 9: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 9

Other puzzles

• What two words add up to “stuff”?

• How many different ways to make $1.00 in change?

• Unscramble “eeiccns”

Page 10: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 10

Page 11: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 11

Brute force problem solving

Generate candidates

FilterSolutions

Trash

Page 12: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 12

Requirements

• Candidate set must be finite.

• Must be an “Oh yeah!” problem.

Page 13: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 13

Example

Combination lock

60*60*60 = 216,000

candidates

Page 14: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 14

Example

Page 15: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 15

Oh no!

Page 16: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 16

Oh yeah!

Page 17: Science1 Welcome to: Chapel Hill UNC Computer Science

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.

Page 18: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 18

Caver’s right hand rule

Page 19: Science1 Welcome to: Chapel Hill UNC Computer Science

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

Page 20: Science1 Welcome to: Chapel Hill UNC Computer Science

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

Page 21: Science1 Welcome to: Chapel Hill UNC Computer Science

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

Page 22: Science1 Welcome to: Chapel Hill UNC Computer Science

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.

Page 23: Science1 Welcome to: Chapel Hill UNC Computer Science

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.

Page 24: Science1 Welcome to: Chapel Hill UNC Computer Science

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.

Page 25: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 25

Faster!

• Reduce size of candidate set.

• Example: 8-queens, one per row, has only 16,777,216 candidates.

Page 26: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 26

Richard Feynman

Page 27: Science1 Welcome to: Chapel Hill UNC Computer Science

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.

Page 28: Science1 Welcome to: Chapel Hill UNC Computer Science

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

Page 29: Science1 Welcome to: Chapel Hill UNC Computer Science

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?

Page 30: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 30

Solution is a sequence on known length (n) where each element is one of the colors.

1

43

2

Page 31: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 31

2. Running a maze: How can you get from start to finish legally in a maze?

20 x 20 grid

Page 32: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 32

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

Page 33: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 33

3. Making change.

How many ways are there to make $1.00 with coins. Don’t forget Sacagawea.

Page 34: Science1 Welcome to: Chapel Hill UNC Computer Science

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.

Page 35: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 35

Let’s try the 4-square puzzle

• Use pieces A, B, F, and G and try to arrange into a 2x2 square.

Page 36: Science1 Welcome to: Chapel Hill UNC Computer Science

Science 36