18-recursive-backtracking-2

# 18-recursive-backtracking-2 - CSE 143 Lecture 18 More...

This preview shows pages 1–5. Sign up to view the full content.

CSE 143 Lecture 18 More Recursive Backtracking slides created by Marty Stepp http://www.cs.washington.edu/143/

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Exercise: Dominoes • The game of dominoes is played with small black tiles, each having 2 numbers of dots from 0-6. Players line up tiles to match dots. • Given a class Domino with the following public methods: int first() // first dots value int second() // second dots value void flip() // inverts 1st/2nd boolean contains(int n) // true if 1st/2nd == n String toString() // e.g. "(3|5)" • Write a method hasChain that takes a List of dominoes and a starting/ending dot value, and returns whether the dominoes can be made into a chain that starts/ends with those values.
3 Domino chains • Suppose we have the following dominoes: • We can link them into a chain from 1 to 3 as follows: – Notice that the 3|5 domino had to be flipped. • We can "link" one domino into a "chain" from 6 to 2 as follows:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Exercise client code import java.util.*; // for ArrayList public class SolveDominoes { public static void main(String[] args) { // [(1|4), (2|6), (4|5), (1|5), (3|5)] List<Domino> dominoes = new ArrayList<Domino>(); dominoes.add(new Domino(1, 4)); dominoes.add(new Domino(2, 6)); dominoes.add(new Domino(4, 5));
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/30/2011 for the course COMPUTER S 143 taught by Professor John during the Spring '11 term at Washington State Community College.

### Page1 / 12

18-recursive-backtracking-2 - CSE 143 Lecture 18 More...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online