18-recursive_backtracking-2

18-recursive_backtracking-2 - CSE143 Lecture18...

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

View Full Document Right Arrow Icon
CSE 143 Lecture 18 More Recursive Backtracking   slides created by Marty Stepp http://www.cs.washington.edu/143/
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 methods: public int first() // first dots value public int second() // second dots value public 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. If the chain's start/end are the same, the answer is always  true .
Background image of page 2
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: 
Background image of page 3

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

View Full DocumentRight Arrow Icon
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)); dominoes.add(new Domino(1, 5)); dominoes.add(new Domino(3, 5)); System.out.println(
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/04/2011 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

Page1 / 13

18-recursive_backtracking-2 - CSE143 Lecture18...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online