Graph Coloring and Hamiltonian cycles Lecture 22 CS 312.

Slides:



Advertisements
Similar presentations
CS 336 March 19, 2012 Tandy Warnow.
Advertisements

Graph algorithms Prof. Noah Snavely CS1114
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
BackTracking Algorithms
Theory of Computing Lecture 18 MAS 714 Hartmut Klauck.
Can visit all squares of a chessboard exactly once ?
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
A Introduction to Computing II Lecture 15: Searching Graphs II Fall Session 2000.
Solving Graph Problems with Boolean Methods Randal E. Bryant Carnegie Mellon University.
Backtracking.
Lecture 13 CSE 331 Oct 2, Announcements Please turn in your HW 3 Graded HW2, solutions to HW 3, HW 4 at the END of the class Maybe extra lectures.
CHAPTER 4 Searching. Algorithm Binary Search This algorithm searches for the value key in the nondecreasing array L[i],..., L[j]. If key is found,
Lecture 16 CSE 331 Oct 9, Announcements Hand in your HW4 Solutions to HW4 next week Remember next week I will not be here so.
COMP171 Depth-First Search.
Is the following graph Hamiltonian- connected from vertex v? a). Yes b). No c). I have absolutely no idea v.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
Alyce Brady CS 510: Computer Algorithms Depth-First Graph Traversal Algorithm.
Depth-first search COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar to pre-order.
Ch 13 – Backtracking + Branch-and-Bound
New Algorithm DOM for Graph Coloring by Domination Covering
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Backtracking.
ECE669 L10: Graph Applications March 2, 2004 ECE 669 Parallel Computer Architecture Lecture 10 Graph Applications.
Depth-First Search Lecture 24 COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar.
The Art Gallery Problem
22C:19 Discrete Math Graphs Spring 2014 Sukumar Ghosh.
Graph Coloring.
CS 2813 Discrete Structures
Coloring 3/16/121. Flight Gates flights need gates, but times overlap. how many gates needed? 3/16/122.
Eulerian Graphs CSE 331 Section 2 James Daly. Reminders Project 3 is out Covers graphs Due Friday.
Dr. Jouhaina Chaouachi Siala
CSC 213 – Large Scale Programming. Today’s Goals  Make Britney sad through my color choices  Revisit issue of graph terminology and usage  Subgraphs,
Prime numbers Jordi Cortadella Department of Computer Science.
Lecture 5: Backtracking Depth-First Search N-Queens Problem Hamiltonian Circuits.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Contents of Chapter 7 Chapter 7 Backtracking 7.1 The General method
CS 312: Algorithm Analysis Lecture #32: Intro. to State-Space Search This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
CS 200 Algorithms and Data Structures
1 3-COLOURING: Input: Graph G Question: Does there exist a way to 3-colour the vertices of G so that adjacent vertices are different colours? 1.What could.
CSCI 2670 Introduction to Theory of Computing November 23, 2004.
Algorithmics - Lecture 131 LECTURE 13: Backtracking.
Hard problems in computer science Prof. Noah Snavely CS1114
Topological Sort: Definition
Introduction to Graph Theory Lecture 17: Graph Searching Algorithms.
CS 173, Lecture B Tandy Warnow. Topics for today Reminder about Examlet on Tuesday My office hours next week: –Tuesday 2-3 PM and Thursday 3-4 PM Office.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 30, 2014.
Graph Connectivity This discussion concerns connected components of a graph. Previously, we discussed depth-first search (DFS) as a means of determining.
Analysis & Design of Algorithms (CSCE 321)
Chapter 13 Backtracking Introduction The 3-coloring problem
NPC.
Computational Complexity Shirley Moore CS4390/5390 Fall 2013 August 27, 2013.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture nine Dr. Hamdy M. Mousa.
Chapter 05 Introduction to Graph And Search Algorithms.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
Map Coloring Vertex Drawing Txt: mini excursion 2 (p ) & SOL: DM.1 Classwork Project Assigned due in two blocks (print the rubric at the end of.
Unit – 5: Backtracking For detail discussion, students are advised to refer the class discussion.
NP-completeness Ch.34.
Depth-First Search N-Queens Problem Hamiltonian Circuits
BACKTRACKING- GENERAL METHOD
Exact Solutions to NP-Complete Problems
Spanning Trees Longin Jan Latecki Temple University based on slides by
Graph Theory Graph Colorings.
Graphs Chapter 13.
Spanning Trees Longin Jan Latecki Temple University based on slides by
CS 173, Lecture B Tandy Warnow
ADVANCED COMPUTATIONAL MODELS AND ALGORITHMS
Presentation transcript:

Graph Coloring and Hamiltonian cycles Lecture 22 CS 312

Follow up 8 queens material.

Objectives Use a backtracking algorithm to solve graph coloring. Solve the Hamiltonian cycle problem Discuss differences between DFS and BFS backtracking algorithms.

Graph Coloring Problem Assign colors to the nodes of a graph so that no adjacent nodes share the same color –nodes are adjacent if there is an edge for node i to node j. Find all m-colorings of a graph –all ways to color a graph with at most m colors.

Graph coloring algorithm mColor (thisNode) while (true) nextColoring (thisNode) if (color[thisNode] == 0) then break // no more colors for thisNode if (thisNode == numNodes) then print this coloring // found a valid coloring of all nodes. else mColor (thisNode + 1) // try to color the next node. endWhile nextColoring (thisNode) while (true) color[thisNode] = (color[thisNode] + 1) mod (numColors + 1) if (color[thisNode] == 0) then return // no more colors to try. for k = 1 to numNodes+1 if (connected[k,thisNode] and color[k] == color[thisNode]) then break endfor if (k == numNodes+1) return // found a new color because no nodes clashed. endWhile

M-coloring function void mColoring(int k) {do {//Generate all legal assignments for x[k] NextValue(k); if (!x[k]) break;//No new color possible if (k==n){// At most m colors have been used to color the n vertices. for (int i=1;i<=n;i++) cout<<x[i]<<‘ ‘; cout << endl; else mColoring (k+1); }while(1);} void NextValue(int k) {do { x[k] = (x[k]+1)%(m+1);//next highest color if (!x[k]) return; //All colors have been used. for (int j=1;j<=n;j++) { //Check if this color is distinct if (G[k][j] //If (k, j) is an edge && (x[k] == x[j])) //and if adj. vertices break; //have the same color } if (j == n+1) return; //New color found }while (1);//Otherwise try to find another color.}

Small Example

Aside: Coloring a Map Assign colors to countries so that no two countries are the same color. Graph coloring as map coloring.

Map coloring as Graph Coloring UtahNevada Idaho Colorado New Mexico Wyoming Arizona

Four color theorem. How many colors do you need? –Four. Haken and Appel using a computer program and 1,200 hours of run time in Checked 1,476 graphs. First proposed in 1852.

Hamiltonian Cycles Given a graph with N vertices. Find a cycle that visits all N vertices exactly once and ends where it started. Sound familiar?

Example

Hamiltonian Hamiltonian (k) while (1) x[k] = NextValue(k) if (x[k] = 0) then return if (k == N) then print solution else Hamiltonian (k+1) endWhile NextValue (k) while (1) value = (x[k]+1) mod (N+1) if (value == 0) then return value if (G[x[k-1],value]) for j = 1 to k-1 if x[j] = value then break if (j==k) and (k < N or k == N and G[x[N],x[1]]) then return value endWhile

Hamiltonian functions void Hamiltonian(int k) {do {//Generate values for x[k] NextValue(k); //Assign a legal next value to x[k] if (!x[k]) return; if (k==n) { for (int i=1;i<=n;i++) cout<<x[i]<<‘ ‘; cout << “1\n”; } else Hamiltonian(k+1); }while(1);} void NextValue(int k) {do { x[k] = (x[k]+1)%(n+1);//next vertex if (!x[k]) return; if (G[x[k-1][x[k]) { //Is there an edge? for (int j=1;j<=k-1;j++) if (x[j]==x[k]) break; if (j==k) //if true, then the vertex is distinct. if ((k<n) || (k==n) && G[x[n]][x[1]])) return; } }while (1); }

That’s it. Have a good weekend. Midterm 2 is next week.