Science1 Welcome to: Chapel Hill UNC Computer Science.

Slides:



Advertisements
Similar presentations
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
Advertisements

PROBLEM SOLVING AND SEARCH
BackTracking Algorithms
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
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.
CompSci 100e Program Design and Analysis II March 3, 2011 Prof. Rodger CompSci 100e, Spring
Eight queens puzzle. The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard such that none of them are able to capture.
SIGCSE Nifty assignments: Brute force and backtracking Steve Weiss Department of Computer Science University of North Carolina at Chapel Hill
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Backtracking What is backtracking?
Creativity In Context SAGA OF THE RACOON BEYOND BRAINSTORMING Session BA 303- B2B MARKETING LINDELL PHILLIP CHEW.
Computational Complexity, Physical Mapping III + Perl CIS 667 March 4, 2004.
Ch 13 – Backtracking + Branch-and-Bound
Backtracking.
When you add the age of the ship and the age of its boiler, it totals 42 years. So S + B = 42. Now pay attention! The ship is twice as old as the boiler.
Introduction to Bioinformatics Algorithms Exhaustive Search and Branch-and-Bound Algorithms for Partial Digest Mapping.
Data Structures Using C++ 2E Chapter 6 Recursion.
Busby, Dodge, Fleming, and Negrusa. Backtracking Algorithm Is used to solve problems for which a sequence of objects is to be selected from a set such.
Scott Perryman Jordan Williams.  NP-completeness is a class of unsolved decision problems in Computer Science.  A decision problem is a YES or NO answer.
Data Structures Using C++ 2E Chapter 6 Recursion.
Backtracking. N-Queens The object is to place queens on a chess board in such a way as no queen can capture another one in a single move –Recall that.
CS 100Lecture 51 CS100J Lecture 5 n Previous Lecture –Programming Concepts n Rules of thumb –learn and use patterns –inspiration from hand-working problem.
Recursion: Backtracking
Back Tracking Project Due August 11, 1999 N-queens: –A classic puzzle for chess buffs is the N- Queens problem. Simply stated: is it possible to place.
Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.
NxN Queens Problem Q- -- -Q Q- -- -Q Q- -- QQ -- Q- Q- Q- -Q QQ -- -Q -- -Q Q- -Q -Q Q- Q- -Q Q- -- Q- -- QQ Q- -Q -Q -Q -- QQ -- -Q START.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
BackTracking CS335. N-Queens The object is to place queens on a chess board in such as way as no queen can capture another one in a single move –Recall.
Two Dimensional Arrays
1 N -Queens via Relaxation Labeling Ilana Koreh ( ) Luba Rashkovsky ( )
Announcements This Wednesday, Class and Labs are cancelled! The last lab is due this Wednesday … how many people are planning on doing it? Finally posted.
Data Structures Using C++ 2E1 Recursion and Backtracking: DFS Depth first search (a way to traverse a tree or graph) Backtracking can be regarded as a.
Sudoku Jordi Cortadella Department of Computer Science.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
Two Dimensional Arrays. Two-dimensional Arrays Declaration: int matrix[4][11]; 4 x 11 rows columns
Department of Computer Science 1 Recursion & Backtracking 1.The game of NIM 2.Getting out of a maze 3.The 8 Queen’s Problem 4.Sudoku.
Sequence Comparison Algorithms Ellen Walker Bioinformatics Hiram College.
Relate Multiplication and Division
§5 Backtracking Algorithms A sure-fire way to find the answer to a problem is to make a list of all candidate answers, examine each, and following the.
Backtracking & Brute Force Optimization Intro2CS – weeks
CSE 143 Lecture 13 Recursive Backtracking slides created by Ethan Apter
Program Development by Stepwise Refinement
© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique.
Analysis & Design of Algorithms (CSCE 321)
CSCE350 Algorithms and Data Structure Lecture 21 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
Probability Distributions and Expected Value Chapter 5.1 – Probability Distributions and Predictions Mathematics of Data Management (Nelson) MDM 4U Authors:
Donghyun (David) Kim Department of Mathematics and Computer Science North Carolina Central University 1 Chapter 5 Reducibility Some slides are in courtesy.
An Analysis of the n- Queens problem Saleem Karamali.
Hard Problems Some problems are hard to solve.  No polynomial time algorithm is known.  E.g., NP-hard problems such as machine scheduling, bin packing,
Simplifying Dynamic Programming Jamil Saquer & Lloyd Smith Computer Science Department Missouri State University Springfield, MO USA.
CSG3F3/ Desain dan Analisis Algoritma
Problem Solving: Brute Force Approaches
BackTracking CS255.
Design and Analysis of Algorithm
Constraint Satisfaction Problem
Problem Solving: Brute Force Approaches
Analysis and design of algorithm
Jordi Cortadella Department of Computer Science
Start Finish Find the solution 42 out of out of 2200
adapted from Recursive Backtracking by Mike Scott, UT Austin
Constraint satisfaction problems
Backtracking and Branch-and-Bound
Puzzle A Puzzle B.
Exercise: Dice rolls Write a method diceRoll that accepts an integer parameter representing a number of 6-sided dice to roll, and output all possible arrangements.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Constraint satisfaction problems
Backtracking, Search, Heuristics
Presentation transcript:

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