Prabhas Chongstitvatana

Slides:



Advertisements
Similar presentations
Graphs and Finding your way in the wilderness
Advertisements

DS.GR.14 Graph Matching Input: 2 digraphs G1 = (V1,E1), G2 = (V2,E2) Questions to ask: 1.Are G1 and G2 isomorphic? 2.Is G1 isomorphic to a subgraph of.
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
CS420 lecture ten BACKTRACK. Solution vectors In optimization problems, or more general in search problems, a set of choices are to be made to arrive.
1 Perfect Matchings in Bipartite Graphs An undirected graph G=(U  V,E) is bipartite if U  V=  and E  U  V. A 1-1 and onto function f:U  V is a perfect.
K-d tree k-dimensional indexing. Jaruloj Chongstitvatana k-d trees 2 Definition Let k be a positive integer. Let t be a k -d tree, with a root node p.
Lecture 17: Spanning Trees Minimum Spanning Trees.
TEDI: Efficient Shortest Path Query Answering on Graphs Author: Fang Wei SIGMOD 2010 Presentation: Dr. Greg Speegle.
We will use Gauss-Jordan elimination to determine the solution set of this linear system.
Combinatorial Algorithms Reference Text: Kreher and Stinson.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
CSC 205 Programming II Lecture 18 The Eight Queens Problem.
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.
Algorithmics - Lecture 131 LECTURE 13: Backtracking.
Prabhas Chongstitvatana1 Las Vegas algorithm The answer obtained is always correct but sometime no answer. Modified deterministic algorithm by using randomness.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
The n queens problem Many solutions to a classic problem: On an n x n chess board, place n queens so no queen threatens another.
Analysis & Design of Algorithms (CSCE 321)
Chapter 13 Backtracking Introduction The 3-coloring problem
1 Week 5 Courtesy of Sheridan Houghten. 2 Lexicographic Order – Subsets of {1, …, n} (See KS, algorithm 2.1) Algorithm to find rank of subset T: FindRank(n,
Prabhas Chongstitvatana 1 Backtracking Eight queens problem 1 try all possible C 64 8 = 4,426,165,368 2 never put more than one queen on a given row, vector.
State space search Represented by a four-tuple [N,A,S,GD], where: N is the problem space A is the set of arcs (or links) between nodes. These correspond.
1 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 CSC384: Intro to Artificial Intelligence Backtracking Search I ● Announcements.
CSG3F3/ Desain dan Analisis Algoritma
Problem Solving: Brute Force Approaches
Part 3 Linear Programming
Edit from old slide since 2000 P. Chongstitvatana 26 Nov 2010
Depth-First Search N-Queens Problem Hamiltonian Circuits
CSSE 230 Day 25 Skip Lists.
Figure 5.1 a) Five queens that cannot attack each other, but that can attack all of column 6; b) backtracking to column 5 to try another square for the.
CS 367 – Introduction to Data Structures
Design and Analysis of Algorithm
Perfect Matchings in Bipartite Graphs
Search
Breadth-First Searches
Algorithm Design and Analysis (ADA)
Problem Solving: Brute Force Approaches
The Greedy Approach Winter-2004 Young CS 331 D&A of Algo. Greedy.
Trees 1: Theory, Models, Generic Heap Algorithms, Priority Queues
Prabhas Chongstitvatana
Part 3 Linear Programming
Back Tracking.
Analysis and design of algorithm
Counting Permutations When Indistinguishable Objects May Exist
Graphs All tree structures are hierarchical. This means that each node can only have one parent node. Trees can be used to store data which has a definite.
Graphs, Trees and Algorithms 1
Number Theory.
Number Theory.
Branch and Bound.
Breadth-First Searches
Chapter 22: Elementary Graph Algorithms I
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
The n queens problem Many solutions to a classic problem:
Area Models A strategy for Multiplication
Foundations of Algorithms, Fourth Edition
Algorithms: Design and Analysis
Backtracking and Branch-and-Bound
Advanced LP models column generation.
Advanced LP models column generation.
Sudoku.
Part 3 Linear Programming
Parallel Graph Algorithms
Where do these graphs intersect
GRAPHING LINEAR EQUATIONS
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Depth-First Searches.
Priority Queues (Heaps)
GRAPH TRAVERSAL.
Presentation transcript:

Prabhas Chongstitvatana Backtracking Eight queens problem 1 try all possible C64 8 = 4,426,165,368 2 never put more than one queen on a given row, vector representation : each row specify which column (3,1,6,2,8,6,4,7) Prabhas Chongstitvatana

Prabhas Chongstitvatana 1 2 3 4 5 6 7 8 X X X X X X X X (3,1,6,2,8,6,4,7) Prabhas Chongstitvatana

Prabhas Chongstitvatana Queen1 for i1 = 1 to 8 do for i2 = 1 to 8 do . . . . for i3 = 1 to 8 do sol = [i1, i2, . . . i8 ] if solution ( sol ) then write sol stop write “there is no solution” Num. Of positions = 8 8 = 16,777,216 (first soln after 1,299,852 ) Prabhas Chongstitvatana

Prabhas Chongstitvatana 3 Never put queen on the same row (different numbers on soln vector) Queen2 sol = initial-permutation while sol != final-permutation and not solution(sol) do sol = next-permutation if solution(sol) then write sol else write “there is no solution” Prabhas Chongstitvatana

Prabhas Chongstitvatana Permutation T[1 . . n] is a global array initialize to [1,2,. . n] initial call perm(1) Perm(i) if i = n then use T else for j = i to n do exchange T[i] and T[j] perm(i+1) exchange T[i] and T[j] Number of positions 8! = 40,320 (first soln after 2830) Prabhas Chongstitvatana

Prabhas Chongstitvatana 8-queen as tree search a vector V[1. .k] of integers between 1 and 8 is k-promising, if none of the k queens threatens any of the others. A vector V is k-promising if, for every pair of integers i and j between 1 and k with i != j, we have V[i] - V[j] is-not-in {i-j, 0, j-i}. Solutions to the 8-queen correspond to vectors that are 8-promising. Prabhas Chongstitvatana

Prabhas Chongstitvatana Let N be the set of k-promising vectors, k: 0 .. 8. Let G = (N,A) be the directed graph such that (U,V) is-in A iff there exists an integer k, k:0..8 , such that U is k-promising V is (k+1)-promising, and U[i] = V[i] for every i in [1..k] k = 0 . . . Number of node < 8! (node 2057, first soln after 114 ) k = 8 Prabhas Chongstitvatana

General Template for backtracking Backtrack ( v[1..k] ) // v is k-promising vector if solution ( v ) then write v else for each (k+1)-promising vector w such that w[1..k] = v[1..k] do backtrack( w[1.. k+1] ) Prabhas Chongstitvatana