combinatorial-search

# combinatorial-search - Robert Sedgewick and Kevin Wayne...

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Robert Sedgewick and Kevin Wayne Copyright 2006 http://www.Princeton.EDU/~cos226 Combinatorial Search 2 Overview Exhaustive search. Iterate through all elements of a search space. Backtracking. Systematic method for generating all solutions to a problem, by successively augmenting partial solutions. Applicability. Huge range of problems (include NP-hard ones). Caveat. Search space is typically exponential in size ! effectiveness is limited to relatively small instances. 3 Enumerating Subsets 4 Scheduling Scheduling (set partitioning). Given n jobs of varying length, divide among two machines to minimize the time the last job finishes. Remark. NP-hard. 1.41 1.73 2.00 2.23 1 2 3 4 length job or, equivalently, difference between finish times 5 Enumerating Subsets: Natural Binary Code Enumerating subsets. Given n items, enumerate all 2 n subsets. ! Count in binary from 0 to 2 n- 1. ! Look at binary representation. 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 empty 1 2 2 1 3 3 1 3 2 3 2 1 4 4 1 4 2 4 2 1 4 3 4 3 1 4 3 2 4 3 2 1 integer machine one binary code 4 3 2 1 4 3 2 4 3 1 4 3 4 2 1 4 2 4 1 4 3 2 1 3 2 3 1 3 2 1 2 1 empty machine two 6 Enumerating Subsets: Natural Binary Code Enumerating subsets. Given n items, enumerate all 2 n subsets. ! Count in binary from 0 to 2 n- 1. ! Look at binary representation. long N = 1 << n ; for ( long i = ; i < N ; i ++) { for ( int bit = ; bit < n ; bit ++) { if ((( i >> bit ) & 1 ) == 1 ) System . out . print ( bit + " " ); } System . out . println (); } 7 Samuel Beckett Quad. Starting with empty stage, 4 characters enter and exit one at a time, such that each subset of actors appears exactly once. ruler function 8 Enumerating Subsets: Binary Reflected Gray Code Binary reflected Gray code. The n-bit code is: ! the (n-1) bit code with a 0 prepended to each word, followed by ! 5 Enumerating Subsets: Natural Binary Code Enumerating subsets. Given n items, enumerate all 2 n subsets. ! Count in binary from 0 to 2 n- 1. ! Look at binary representation. 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 empty 1 2 2 1 3 3 1 3 2 3 2 1 4 4 1 4 2 4 2 1 4 3 4 3 1 4 3 2 4 3 2 1 integer machine one binary code 4 3 2 1 4 3 2 4 3 1 4 3 4 2 1 4 2 4 1 4 3 2 1 3 2 3 1 3 2 1 2 1 empty machine two 6 Enumerating Subsets: Natural Binary Code Enumerating subsets. Given n items, enumerate all 2 n subsets. ! Count in binary from 0 to 2 n- 1. ! Look at binary representation. long N = 1 << n ; for ( long i = ; i < N ; i ++) { for ( int bit = ; bit < n ; bit ++) { if ((( i >> bit ) & 1 ) == 1 ) System . out . print ( bit + " " ); } System . out . println (); } 7 Samuel Beckett Quad. Starting with empty stage, 4 characters enter and exit one at a time, such that each subset of actors appears exactly once.one at a time, such that each subset of actors appears exactly once....
View Full Document

## This document was uploaded on 06/10/2011.

### Page1 / 10

combinatorial-search - Robert Sedgewick and Kevin Wayne...

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

View Full Document
Ask a homework question - tutors are online