introduction to graph and graph coloring

57
1/48 Theoretical Section Practical Section INTRODUCTION TO GRAPH AND GRAPH COLORING PROBLEM Design Methods and Analysis of Algorithm Darwish Ahmad Herati St. Joseph’s College (Autonomous) Computer Science Department MSc (Computer Science) SUPERVISOR Prof. Ms. Mrinmoyee Bhattacharya September 1, 2015 Darwish Ahmad Herati Design Methods and analysis of Algorithm

Upload: darwish-ahmad-herati

Post on 09-Jan-2017

782 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Introduction to Graph and Graph Coloring

1/48

Theoretical SectionPractical Section

INTRODUCTION TO GRAPH AND GRAPHCOLORING PROBLEM

Design Methods and Analysis of AlgorithmDarwish Ahmad Herati

St. Joseph’s College (Autonomous)Computer Science Department

MSc (Computer Science)

SUPERVISORProf. Ms. Mrinmoyee Bhattacharya

September 1, 2015

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 2: Introduction to Graph and Graph Coloring

2/48

Theoretical SectionPractical Section

Contents

1 Theoretical SectionIntroductionHistoryDefinitionsAlgorithmComplexityApplications

2 Practical SectionExamplesImplementationSimulation Technologies

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 3: Introduction to Graph and Graph Coloring

3/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Introduction to Graph:

A graph is a collection (nonempty set) of vertices andedgesA graph G is a set of vertex (nodes) v connected by edges(links) e. Thus G=(v , e).

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 4: Introduction to Graph and Graph Coloring

4/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Example of Graphs:

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 5: Introduction to Graph and Graph Coloring

5/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Introduction to Graphs:

A graph is a mathematical object that is used to modeldifferent situations objects and processes:

- Linked list- Tree(Special type of graph)- Flowchart chart of a program- Structure chart of a program- Finite state automata- Electric Circuits- Course Curriculum- etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 6: Introduction to Graph and Graph Coloring

6/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

Vertex (Node):Edge (Link):Adjacent Vertices:Sub-Graph:Directed Graph:Undirected Graph:Connected Graph:Unconnected Graph:

Paths:Simple path:Cycles:Loop:Trees:Spanning tree of a graph:Complete graphs:Weighted graphs:Networks:

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 7: Introduction to Graph and Graph Coloring

7/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

Chromatic Number:K-coloring:Optimal Coloring:etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 8: Introduction to Graph and Graph Coloring

8/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:Vertex (Node): can have names and propertiesEdge (Link): connect two vertices, can be labeled, can bedirectedAdjacent Vertices: if there is an edge between them.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 9: Introduction to Graph and Graph Coloring

9/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

Subgraph: A subgraph S of a graph G is a graph whoseset of vertices and set of edges are all subsets of G.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 10: Introduction to Graph and Graph Coloring

10/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

Directed Graph: In directedgraphs the edges are oriented,they have a beginning and anend. Thus A B and B A aredifferent edges.Sometimes the edges of adirected graph are called arcs.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 11: Introduction to Graph and Graph Coloring

11/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

Undirected Graph: Inundirected graphs the edges aresymmetrical, e.g. if A and B arevertices, A B and B A are oneand the same edge. Graph1above is undirected.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 12: Introduction to Graph and Graph Coloring

12/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:Connected Graph: There is a path between each twovertices.Unconnected Graph: There are at least two vertices notconnected by a path.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 13: Introduction to Graph and Graph Coloring

13/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

paths: A path is a list of vertices in which successivevertices are connected by edgesSimple Path: No vertex is repeated.Some paths in Graph1 :A B C DA C B A C DA BD C BC B ASome paths in Graph2:D A BA D A C

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 14: Introduction to Graph and Graph Coloring

14/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:Cycles:A cycle is a simple path with distinct edges, wherethe first vertex is equal to the last.Cycles in Graph1:C A B C, C B A C, A B C A, A C B A, B A C B, B C A B A BA is not a cycle, because the edge A B is the same as B ALoop: An edge that connects the vertex with itself

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 15: Introduction to Graph and Graph Coloring

15/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:Trees:A tree is an undirected graph with no cycles and avertex chosen to be the root of the tree.Note: in a tree, when we choose a root we impose anorientation. Given an acyclic graph, we may choose anynode to be the root of a tree.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 16: Introduction to Graph and Graph Coloring

16/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:Spanning Tree of a Graph: A spanning tree of anundirected graph is a subgraph that contains all thevertices, and no cycles. If we add any edge to the spanningtree, it forms a cycle, and the tree becomes a graph.It is possible to define a spanning tree for directed graphs,however the definition is rather complicated and will not bediscussed here.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 17: Introduction to Graph and Graph Coloring

17/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:Complete Graphs:Graphs with all edges present eachvertex is connected to all other vertices, are calledcomplete graphs.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 18: Introduction to Graph and Graph Coloring

18/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

Weighted Graphs: Weights areassigned to each edge(e.g. distances in a road map)

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 19: Introduction to Graph and Graph Coloring

19/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

Networks:Directed weightedgraphsNote:Some textbooks definenetworks to be undirectedweighted graphs as well.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 20: Introduction to Graph and Graph Coloring

20/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Terminologies of Graphs:

Chromatic Number: The chromatic number of a graph Gis the smallest number k for which a k-coloring of thevertices of G is possible.We will use the notation x(G) todenote the chromatic number of G.k-coloring: A k-coloring of a graph G is a coloring of thevertices of G using k colors and satisfying the requirementthat adjacent vertices are colored with different colors.Optimal Coloring: An optimal coloring of a graph G is acoloring of the vertices of G using the fewest possiblenumber of colors.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 21: Introduction to Graph and Graph Coloring

21/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Introduction to Graph Coloring

Graph coloring is one of the oldest concepts in the theoryof graphs,A graph G = (V, E) consists two sets where one is the setof vertices and another is the set of edges such that eachedges is associated with an un ordered pair of vertices andgraph coloring is one of the most useful models in graphtheory. Graph coloring is the way of coloring the vertices ofa graph with the minimum number of colors such that notwo adjacent vertices share the same color.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 22: Introduction to Graph and Graph Coloring

22/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Introduction to Graph Coloring

A k-coloring of graph G is an assignment of integers{1, 2, . . . ,k} (the colors) to the vertices of G in such a waythat neighbors receive different integers. The chromaticnumber of G is the smallest k such that G has a k-coloring.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 23: Introduction to Graph and Graph Coloring

23/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Types of Graph Coloring:

Vertix Coloring:Edge Coloring:Face Coloring/ Map Coloring:

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 24: Introduction to Graph and Graph Coloring

24/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Vertix Coloring of Graph:

Vertix Coloring:A vertex coloring of a graph is to color thevertices of the graph in such a way that any two adjacentvertices receive different colors.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 25: Introduction to Graph and Graph Coloring

25/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Edge Coloring of Graph:Edge Coloring:An edge coloring of a graph is to color theedges of the graph in such a way that any two adjacentedges receive different colors.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 26: Introduction to Graph and Graph Coloring

26/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Face Coloring / Map Coloring of Graph:

Face Coloring/ Map Coloring:

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 27: Introduction to Graph and Graph Coloring

27/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Francis Guthrie and Demorgan

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 28: Introduction to Graph and Graph Coloring

28/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Cayley and Kempe 1879

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 29: Introduction to Graph and Graph Coloring

29/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Percy John Heawood 1890

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 30: Introduction to Graph and Graph Coloring

30/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

K. Appel W. Haken 1977

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 31: Introduction to Graph and Graph Coloring

31/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Rebertson, Sanders, Seymour, Thomas

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 32: Introduction to Graph and Graph Coloring

32/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Definitions:

An n-coloring is proper if no pair of adjacent vertices getsthe same color.The graph coloring problem involves assigning values (orcolors) to the vertices of a graph so that adjacent verticesare assigned distinct colors. With the objective ofminimizing the number of colors used.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 33: Introduction to Graph and Graph Coloring

33/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Greedy Algorithm for Graph Coloring:

Step 1. Assign the first color (c1) to the first vertex (v1).Step 2. Vertex v2 is assigned color c1 if it is not adjacentto v1; otherwise it gets assigned color c2.Steps 3,4,...,n. Vertex v1 is assigned the first possiblecolor in the priority list of colors (i.e. the first color that hasnot been assigned to one of the already colored neighborsof vi ).

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 34: Introduction to Graph and Graph Coloring

34/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Analysis of Graph Coloring:An Upper bound on the computing time of MCOLORINGcan arrived by finding the number of internal nodes in thestate space tree is:

At each internal node, O(mn) time is spent by Next Valueto determine the children corresponding to legal coloring.Hence the total time is bounded by:

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 35: Introduction to Graph and Graph Coloring

35/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Applications of Graph Coloring:

Graph Coloring: has many applications in jobscheduling, assignments of classes/classrooms,assignments of wireless channels.Aircraft scheduling:Making Schedule or Time Table:Mobile Radio Frequency Assignment:Suduku:Register Allocation:Bipartite Graphs:Map Coloring:etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 36: Introduction to Graph and Graph Coloring

36/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Aircraft Scheduling:

Aircraft scheduling: Assume that we have k aircrafts,and we have to assign them to n flights, where the ith flightis during the time interval (ai, bi). Clearly, if two flightsoverlap, then we cannot assign the same aircraft to bothflights. The vertices of the conflict graph correspond to theflights, two vertices are connected if the correspondingtime intervals overlap. Therefore the conflict graph is aninterval graph, which can be colored optimally inpolynomial time.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 37: Introduction to Graph and Graph Coloring

37/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Making Schedule or Time Table:Making Schedule or Time Table: Suppose we want tomake am exam schedule for a university. We have listdifferent subjects and students enrolled in every subject.Many subjects would have common students (of samebatch, some backlog students, etc). How do we schedulethe exam so that no two exams with a common student arescheduled at same time? How many minimum time slotsare needed to schedule all exams? This problem can berepresented as a graph where every vertex is a subjectand an edge between two vertices mean there is acommon student. So this is a graph coloring problemwhere minimum number of time slots is equal to thechromatic number of the graph.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 38: Introduction to Graph and Graph Coloring

38/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Mobile Radio Frequency Assignment:

Mobile Radio Frequency Assignment: Whenfrequencies are assigned to towers, frequencies assignedto all towers at the same location must be different. How toassign frequencies with this constraint? What is theminimum number of frequencies needed? This problem isalso an instance of graph coloring problem where everytower represents a vertex and an edge between two towersrepresents that they are in range of each other.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 39: Introduction to Graph and Graph Coloring

39/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Suduku:

Suduku: Suduku is also a variation of Graph coloringproblem where every cell represents a vertex. There is anedge between two vertices if they are in same row or samecolumn or same block.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 40: Introduction to Graph and Graph Coloring

40/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Register Allocation:

Register Allocation: In compiler optimization, registerallocation is the process of assigning a large number oftarget program variables onto a small number of CPUregisters. This problem is also a graph coloring problem.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 41: Introduction to Graph and Graph Coloring

41/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Bipartite:

Bipartite Graphs: We can check if a graph is Bipartite ornot by colowing the graph using two colors. If a givengraph is 2-colorable, then it is Bipartite, otherwise not. Seethis for more details.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 42: Introduction to Graph and Graph Coloring

42/48

Theoretical SectionPractical Section

IntroductionHistoryDefinitionsAlgorithmComplexityApplications

Map Coloring:

Map Coloring: Geographical maps of countries or stateswhere no two adjacent cities cannot be assigned samecolor. Four colors are sufficient to color any map (See FourColor Theorem)

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 43: Introduction to Graph and Graph Coloring

43/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Coloring Examples:

: Vertex Coloring: Vertix Coloring: Vertix Coloring: Edge Coloring: Both Vertex & Edge: Face Coloring: Map Coloring

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 44: Introduction to Graph and Graph Coloring

43/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Coloring Examples:

: Vertex Coloring: Vertix Coloring: Vertix Coloring: Edge Coloring: Both Vertex & Edge: Face Coloring: Map Coloring

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 45: Introduction to Graph and Graph Coloring

43/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Coloring Examples:

: Vertex Coloring: Vertix Coloring: Vertix Coloring: Edge Coloring: Both Vertex & Edge: Face Coloring: Map Coloring

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 46: Introduction to Graph and Graph Coloring

43/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Coloring Examples:

: Vertex Coloring: Vertix Coloring: Vertix Coloring: Edge Coloring: Both Vertex & Edge: Face Coloring: Map Coloring

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 47: Introduction to Graph and Graph Coloring

43/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Coloring Examples:

: Vertex Coloring: Vertix Coloring: Vertix Coloring: Edge Coloring: Both Vertex & Edge: Face Coloring: Map Coloring

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 48: Introduction to Graph and Graph Coloring

43/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Coloring Examples:

: Vertex Coloring: Vertix Coloring: Vertix Coloring: Edge Coloring: Both Vertex & Edge: Face Coloring: Map Coloring

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 49: Introduction to Graph and Graph Coloring

43/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Coloring Examples:

: Vertex Coloring: Vertix Coloring: Vertix Coloring: Edge Coloring: Both Vertex & Edge: Face Coloring: Map Coloring

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 50: Introduction to Graph and Graph Coloring

44/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Implementation of Graphs using C++:

Implementation:Two Graphs using Greedy MethodImplementation in C++.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 51: Introduction to Graph and Graph Coloring

45/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Theorem Simulation Technologies:

1st: DemonstrationProgram2nd: CGraph Simulator3rd: GraphTeaSimulator4th: Graph Magic5th: etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 52: Introduction to Graph and Graph Coloring

45/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Theorem Simulation Technologies:

1st: DemonstrationProgram2nd: CGraph Simulator3rd: GraphTeaSimulator4th: Graph Magic5th: etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 53: Introduction to Graph and Graph Coloring

45/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Theorem Simulation Technologies:

1st: DemonstrationProgram2nd: CGraph Simulator3rd: GraphTeaSimulator4th: Graph Magic5th: etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 54: Introduction to Graph and Graph Coloring

45/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Theorem Simulation Technologies:

1st: DemonstrationProgram2nd: CGraph Simulator3rd: GraphTeaSimulator4th: Graph Magic5th: etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 55: Introduction to Graph and Graph Coloring

45/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Graph Theorem Simulation Technologies:

1st: DemonstrationProgram2nd: CGraph Simulator3rd: GraphTeaSimulator4th: Graph Magic5th: etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 56: Introduction to Graph and Graph Coloring

46/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

References

Srikanth.S, (2014). Design and Analysis of AlgorithmsTommy R. Jensen and Bjarne Toft, (1995) Graph ColoringProblemsLydia Sinapova. (2015)(http://faculty.simpson.edu/lydia.sinapova/www/cmsc250/LN250_Weiss/L19-Graphs.htm) . Accessed Augest 252015.etc.

Darwish Ahmad Herati Design Methods and analysis of Algorithm

Page 57: Introduction to Graph and Graph Coloring

47/48

Theoretical SectionPractical Section

ExamplesImplementationSimulation Technologies

Thank You For YourAttention

Darwish Ahmad Herati Design Methods and analysis of Algorithm