© Jalal Kawash 2010 Graphs Peeking into Computer Science.

Slides:



Advertisements
Similar presentations
Trees Chapter 11.
Advertisements

Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Introduction to Graphs
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and.
1 Section 9.1 Introduction to Trees. 2 Tree terminology Tree: a connected, undirected graph that contains no simple circuits –must be a simple graph:
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
Section 3.1 Properties of Trees Sarah Graham. Tree Talk: Vocabulary oTree: a tree is a special type of graph that contains designated vertex called a.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
James Tam Graphs You will learn basic principles of graphs as well as how they can be applied to problem solving.
Graphs and Trees This handout: Trees Minimum Spanning Tree Problem.
A tree is a simple graph satisfying: if v and w are vertices and there is a path from v to w, it is a unique simple path. a b c a b c.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
03/01/2005Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 3.1 Properties of Trees Prepared by Joshua Schoenly and Kathleen McNamara.
2/10/03Tucker, Sec Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree.
Chapter 9: Graphs Basic Concepts
Important Problem Types and Fundamental Data Structures
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley.
Binary Trees Chapter 6.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley. All rights reserved.
Let G be a pseudograph with vertex set V, edge set E, and incidence mapping f. Let n be a positive integer. A path of length n between vertex v and vertex.
COSC2007 Data Structures II
Trees. Introduction to Trees Trees are very common in computer science They come in different forms They are used as data representation in many applications.
Graph Theory Topics to be covered:
© Jalal Kawash 2010 Trees & Information Coding: 3 Peeking into Computer Science.
Foundations of Discrete Mathematics
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Lecture 17 Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
© Jalal Kawash 2010 Trees & Information Coding Peeking into Computer Science.
Module #19: Graph Theory: part II Rosen 5 th ed., chs. 8-9.
© Jalal Kawash 2010 Graphs Peeking into Computer Science.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
© Jalal Kawash 2010 Graphs Peeking into Computer Science.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Discrete Mathematics Chapter 5 Trees.
Vertex Coloring Distributed Algorithms for Multi-Agent Networks
Trees Dr. Yasir Ali. A graph is called a tree if, and only if, it is circuit-free and connected. A graph is called a forest if, and only if, it is circuit-free.
Data Structures Lakshmish Ramaswamy. Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems.
CHAPTER 11 TREES INTRODUCTION TO TREES ► A tree is a connected undirected graph with no simple circuit. ► An undirected graph is a tree if and only.
Great Theoretical Ideas in Computer Science for Some.
Discrete Structures – CNS 2300 Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 9 Trees.
Tree - in “math speak” An ________ graph is a set of vertices/nodes and a set of edges, each edge connects two vertices. Any undirected graph in which.
Graphs. Graph Definitions A graph G is denoted by G = (V, E) where  V is the set of vertices or nodes of the graph  E is the set of edges or arcs connecting.
Section10.1: Introduction to Trees
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
CSCE 210 Data Structures and Algorithms
Graph Graphs and graph theory can be used to model:
Redraw these graphs so that none of the line intersect except at the vertices B C D E F G H.
Discrete Mathematicsq
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Introduction to Trees Section 11.1.
Discrete Maths 10. Trees 242/ , Semester 2, Objective
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Chapter 9: Graphs Basic Concepts
Md. Abul Kashem, Chowdhury Sharif Hasan, and Anupam Bhattacharjee
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
Chapter 9: Graphs Basic Concepts
Presentation transcript:

© Jalal Kawash 2010 Graphs Peeking into Computer Science

© Jalal Kawash 2010Peeking into Computer Science Reading Assignment Mandatory: Chapter 3 – Sections 3.3 & 3.4 2

Graph Coloring 3

© Jalal Kawash 2010Peeking into Computer Science Objectives At the end of this section, you will be able to: 1. Understand (once more) how graphs are used to represent data 2. Learn the graph coloring algorithm 3. Apply graph coloring to solve for various scheduling problems 4

© Jalal Kawash 2010Peeking into Computer Science Simple Intersection 5 Based on Based on Aho, Hopcroft, and Ullman, Data Structures and Algorithms, Addison-Wesley D B C A

© Jalal Kawash 2010Peeking into Computer Science Another Example Problem Design a traffic light for a complex intersection Identify allowed turns ◦Going straight is a turn! Group turns so that permitted simultaneous turns are in the same group Find the smallest number of groups ◦This means a traffic light with the smallest number of phases 6

© Jalal Kawash 2010Peeking into Computer Science Simple Intersection 7 Based on Based on Aho, Hopcroft, and Ullman, Data Structures and Algorithms, Addison-Wesley D B C A

© Jalal Kawash 2010Peeking into Computer Science 9 Possible Turns From A to B (denoted AB) From A to C (AC) From A to D (AD) BA BC BD DA DB DC 8 D B C A

© Jalal Kawash 2010Peeking into Computer Science Example Simultaneous Turns AC AD BA 9 D B C A

© Jalal Kawash 2010Peeking into Computer Science Example Conflicting Turns AC conflicts with DB BD BC DC 10 D B C A

© Jalal Kawash 2010Peeking into Computer Science Objective Build a graph model Vertices are turns An edge connects conflicting turns 11

© Jalal Kawash 2010Peeking into Computer Science Graph Model of Conflicting Turns 12 D B C A ABACAD BABCBD DADBDC

© Jalal Kawash 2010Peeking into Computer Science Graph Coloring Color the vertices of the graph No two adjacent vertices can have the same color ◦Adjacent: and edge connects them Each color represents a group of turns that can be simultaneous Note: more than one solution 13

© Jalal Kawash 2010Peeking into Computer Science Graph Coloring Algorithm Repeat the following two steps until the graph is colored 1. Select an uncolored vertex and color it with a new color, C 2. For each uncolored vertex, ◦Determine if it has an edge with a vertex that is colored with color C ◦If not, color it with color C ◦If yes, skip it 14

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra, Graph Coloring Example 1: Final Exams You are to schedule final exams so that a student will not have two final exams scheduled at the same time. Although you could schedule each exam in it’s own individual time slot (i.e., no two exams run simultaneously) this would be highly inefficient. ◦Another constraint is to schedule exams with the minimum number of time slots. Examinations for a lecture will be represented with vertices. A pair of vertices will be connected if there is at least one student who is registered in both.

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra, Graph Coloring Example 1: Final Exams (2) Lecture A: ◦Student 1, student 2 Lecture B: ◦Student 2, student 4, student 6 Lecture C: ◦Student 1, student 3, student 5 Lecture D: ◦Student 4, student 5 Lecture ALecture B Lecture CLecture D Student 5 Student 4 Student 1 Student 2

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra, Graph Coloring Example 2: Final Exams Lecture A: ◦Student 1, student 2, student 4 Lecture B: ◦Student 2, student 4, student 6 Lecture C: ◦Student 1, student 3, student 5 Lecture D: ◦Student 4, student 5 Lecture ALecture B Lecture CLecture D Student 5 Student 4 Student 1 Student 2, 4 Student 4

© Jalal Kawash 2010Peeking into Computer Science Graph Model of Conflicting Turns 18 D B C A ABACAD BABCBD DADBDC ABACAD BABCBD DADBDC

© Jalal Kawash 2010Peeking into Computer Science Graph Model of Conflicting Turns 19 D B C A ABACAD BABCBD DADBDC ABACAD BABCBD DADBDC

© Jalal Kawash 2010Peeking into Computer Science Graph Model of Conflicting Turns 20 D B C A ABACAD BABCBD DADBDC ABACAD BABCBD DADBDC

© Jalal Kawash 2010Peeking into Computer Science Complex Intersection 21 From From Aho, Hopcroft, and Ullman, Data Structures and Algorithms, Addison-Wesley D E B C A

Trees A popular special case of graphs 22

© Jalal Kawash 2010Peeking into Computer Science Objectives At the end of this section, the student will be able to: 1. Identify when a graph is a tree 2. Use tree terminology 3. Identify different applications of trees 4. Define binary trees

© Jalal Kawash 2010Peeking into Computer Science Computer Science Trees Trees are a special case of graphs A tree is a (directed) graph with the properties: 1. There is a designated vertex, called the root of the tree 2. There is a unique directed path from the root to every other vertex in the tree Grow downwards! 24

© Jalal Kawash 2010Peeking into Computer Science Example Tree A BCD G H FE 25

© Jalal Kawash 2010Peeking into Computer Science Example Tree A tree always “grows” downward We omit the arrows A BCD G H FE 26

© Jalal Kawash 2010Peeking into Computer Science Tree Terminology Root Child Parent Ancestor Descendant Distance Siblings Leaf A BCD G H FE 27

© Jalal Kawash 2010Peeking into Computer Science Root 28 A BCD G H FE Vertex ‘A’ is the root of the tree

© Jalal Kawash 2010Peeking into Computer Science Parent-Child (Above/Below), Ancestor-Descendant A is the parent of B, C, D. B, C, D are the children of A. B,C,D,E are descendants of A. A is ancestor of B, C, D, E 29 A BCD E

© Jalal Kawash 2010Peeking into Computer Science Parent-Child All vertices have exactly one parent except for the root (which has none). 30

© Jalal Kawash 2010Peeking into Computer Science Siblings Siblings have the same parent. B,C,D are siblings E, F are siblings A, G have no siblings 31 A BCD E FG

© Jalal Kawash 2010Peeking into Computer Science Leaf Leaves are vertices with no children B, D, E are leaves “Bottom level” 32 A BCD E

© Jalal Kawash 2010Peeking into Computer Science Distance Moving up from a node to the parent is one ‘step’. Moving up to the parent of the parent is another ‘step’. 33 A BCD E 1 step

© Jalal Kawash 2010Peeking into Computer Science Organizational Trees President VP R&D VP Finance VP Marketing Accounting Director Sales Director Development Director Research Director 34

© Jalal Kawash 2010Peeking into Computer Science Game Trees Paper-Rock-Scissors 1S 1R 1P 1R 2R 1R 2S 1S 2S 1S 2R 1S 2P 1R 2P 1P 2R 1P 2S 1P 2P draw1 wins2 wins draw1 wins 2 winsdraw 35

© Jalal Kawash 2009Peeking into Computer Science Game Trees Tic-Tac-Toe … X X … 36

© Jalal Kawash 2009Peeking into Computer Science Game Trees X X X X X X X XXXX X … 37

© Jalal Kawash 2009Peeking into Computer Science X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X Leaf: Draw X X X X X Leaf: O Wins Leaf: X Wins 38

© Jalal Kawash 2010Peeking into Computer Science Binary Trees A binary tree is a tree with the following properties: 1. The edges are labeled with the labels left or right 2. Every vertex has at most two children; if both children exist, then one edge must be labeled with left and the other right. 39

© Jalal Kawash 2010Peeking into Computer Science Example Binary Tree A C D G H FE left right 40

© Jalal Kawash 2010Peeking into Computer Science Example Binary Tree Drop the labels, if the tree is drawn with no confusion A C D G H FE C’s Left Child C’s Right Child D’s Right Child D has no Left Child 41

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Application Binary Trees 42 1 From: “Data Structures and Algorithm Analysis in C++”, Weiss M.A. 1