David Stotts Computer Science Department UNC Chapel Hill.

Slides:



Advertisements
Similar presentations
What is a graph ? G=(V,E) V = a set of vertices E = a set of edges edge = unordered pair of vertices
Advertisements

Chapter 9 Graphs.
22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
Introduction to Graph Theory Lecture 19: Digraphs and Networks.
Last time: terminology reminder w Simple graph Vertex = node Edge Degree Weight Neighbours Complete Dual Bipartite Planar Cycle Tree Path Circuit Components.
1 Representing Graphs. 2 Adjacency Matrix Suppose we have a graph G with n nodes. The adjacency matrix is the n x n matrix A=[a ij ] with: a ij = 1 if.
Graphs. Overview What is a graph? Some terminology Types of graph Implementing graphs (briefly) Some graph algorithms Graphs 2/18.
CS 206 Introduction to Computer Science II 10 / 31 / 2008 Happy Halloween!!! Instructor: Michael Eckmann.
1 Representing Relations Part 2: directed graphs.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Wednesday, 9/26/01 Graph Basics.
CSE 321 Discrete Structures Winter 2008 Lecture 25 Graph Theory.
Discrete Math for CS Chapter 8: Directed Graphs. Discrete Math for CS digraph: A digraph is a graph G = (V,E) where V is a finite set of vertices and.
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Fall 2014 Doug James Lecture 17: Graphs.
Chapter 9: Graphs Basic Concepts
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
22C:19 Discrete Math Graphs Spring 2014 Sukumar Ghosh.
GRAPH Learning Outcomes Students should be able to:
 Jim has six children.  Chris fights with Bob,Faye, and Eve all the time; Eve fights (besides with Chris) with Al and Di all the time; and Al and Bob.
Graphs Chapter 10.
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
More Graphs, Subgraphs and Trees Planarity and Coloring.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
It's a world-wide webby wonderland.. Graphs are often used to represent real-world information and real-world structures. Graph Theory was even invented.
Vertices and Edges Introduction to Graphs and Networks Mills College Spring 2012.
GRAPHS THEROY. 2 –Graphs Graph basics and definitions Vertices/nodes, edges, adjacency, incidence Degree, in-degree, out-degree Subgraphs, unions, isomorphism.
Data Structures & Algorithms Graphs
1 12/2/2015 MATH 224 – Discrete Mathematics Formally a graph is just a collection of unordered or ordered pairs, where for example, if {a,b} G if a, b.
Chapter 10 Graph Theory Eulerian Cycle and the property of graph theory 10.3 The important property of graph theory and its representation 10.4.
COSC 2007 Data Structures II Chapter 14 Graphs I.
Sec. 5.1: Planarity & Coloring
Graph.
Unit – V Graph theory. Representation of Graphs Graph G (V, E,  ) V Set of vertices ESet of edges  Function that assigns vertices {v, w} to each edge.
1.5 Graph Theory. Graph Theory The Branch of mathematics in which graphs and networks are used to solve problems.
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.
Representing Relations Using Matrices A relation between finite sets can be represented using a zero-one matrix Suppose R is a relation from A = {a 1,
Homework #5 Due: October 31, 2000 Christine Kang Graph Concepts and Algorithms.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
Graph Terminologies Department of CE/IT M.S.P.V.L.Polytechnic College,
David Stotts Computer Science Department UNC Chapel Hill.
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Great Theoretical Ideas in Computer Science for Some.
Graph Concepts and Algorithms Using LEDA By Caroline Moore and Carmen Frerichs (252a-at and 252a-ao) each graph in the presentation was created using gw_basic_graph_algorithms.
Graph Revisited Fei Chen CSCI2100B Data Structures Tutorial 12 1.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
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.
Graph Concepts Illustrated Using The Leda Library Amanuel Lemma CS252 Algorithms.
CSC 252: Algorithms October 28, 2000 Homework #5: Graphs Victoria Manfredi (252a-ad) notes: -Definitions for each of the graph concepts are those presented.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Graph Terms By Susan Ott. Vertices Here are 7 vertices without any edges Each Vertex is labeled a different color and number.
Programming Abstractions Cynthia Lee CS106B. Upcoming Topics Graphs! 1.Basics  What are they? How do we represent them? 2.Theorems  What are some things.
Graphs David Kauchak cs302 Spring Admin HW 12 and 13 (and likely 14) You can submit revised solutions to any problem you missed Also submit your.
David Stotts Computer Science Department UNC Chapel Hill.
Graphs Lecture 19 CS2110 – Spring 2013.
Basic Concepts Graphs For more notes and topics visit:
Redraw these graphs so that none of the line intersect except at the vertices B C D E F G H.
Great Theoretical Ideas In Computer Science
Discrete Maths 9. Graphs Objective
Planarity Testing.
Graph Theory.
Chapter 9: Graphs Basic Concepts
Graph Theory By Amy C. and John M..
Decision Maths Graphs.
Graphs G = (V, E) V are the vertices; E are the edges.
Discrete Mathematics for Computer Science
Chapter 9: Graphs Basic Concepts
GRAPHS.
Presentation transcript:

David Stotts Computer Science Department UNC Chapel Hill

Basic Graph Theory (part 1)

Graph is not a picture or a chart Mathematical structure based in sets and relations/functions G = ( V, E ) where V is a set of vertices (nodes) E is a set of edges (arcs) E is a set of pairs E = { (a,b) | a ∈ V ∧ b ∈ V } ◦ An edge is a relation between two vertices We let edges represent (model) different things… ◦ road from a to b, a is parent of b, a employs b ◦ a must be taken before b, a explains b, …

adjacent we say b is adjacent to a iff (a,b) ∈ E directed graph edges in E are directional pairs in E are ordered draw with arrows we say “digraph” Example (a,b) ∈ E b a a b d c V = { a, b, c, d } E = { (a,b), (b,c), (c,a), (c,d), (d,b) } so G = ( { a, b, c, d }, { (a,b), (b,c), (c,a), (c,d), (d,b) } )

Edges have no direction If b is adjacent to a, then a is also adjacent to b pairs in E are unordered draw with no arrowheads Symmetry: If (a,b) ∈ E then (b,a) ∈ E Example (a,b) ∈ E ∧ (b,a) ∈ E b a a b d c V = { a, b, c, d } E = { (a,b), (b,a), (a,c), (c,a), (b,c), (c,b), (b,d), (d,b) }

Symmetry: (a,b) ∈ E ∧ (b,a) ∈ E ab This … not the same as this … b a This is shaking hands This is hand on the shoulder If a shakes b’s hand, It is impossible for b not to shake a’s hand

Some problems may need a “weight” associated with each edge E = { (s,d,w) | s∈V ∧ d∈V ∧ w∈Int } ab or weights might be real Unweighted graphs can be thought of as having weight of 1 on each edge b a 4 5 2

Here ( b, b ) ∈ E So there is a path b to b that has length 1 b d c

a d b c

We require the edges to be distinct If (a,b) ∈ E there is no cycle between a and b per se a, b, a is not a cycle, that would imply an edge (a,b) and another edge (b,a)… (path length 2) but these are one edge, the same edge ab b a Another reason these are technically not the same

We require the edges to be distinct No cycles in this graph ab c b a c cycles in this one a,b,a a,b,a,c,a b,a,c,a,b etc. ab c cycles now… a,b,c,a b,c,a,b etc.

DAG: Directed Acyclic Graph Special form used in many problems b a c f e d Directed edges No cycles... DAG Directed edges But cycles ? b a c f e d Yes, so not a DAG

We have been using DAG’s already… Anyone? Trees Directed edges No cycles... DAG b a c f d ih e g We often use directed edges because the parent- child relation is one-way, not symmetric

Lets go back to the previous DAG example How can we answer the question “ Is there a cycle? ” b a c f e d Directed edges But cycles ? Cycles… not a DAG No… a DAG Now? No… a DAG Now? No… a DAG Graph Algorithm: For each vertex v { trace paths from v see if you revisit a node on the path each path must end or revisit (why?) }

Undirected Graph Has a path from every vertex to every other vertex b a c f e d connected Not connected b a c f e d

Directed Graph Strongly Connected: Has a path from every vertex to every other vertex d a b c Strongly connected Not strongly connected d a b c

Directed Graph Weakly Connected: underlying undirected graph is connected Not strongly connected d a b c d a b c Underlying undirected graph this is connected This is weakly connected so …

s.c. no a b c a b c s.c. yes a b c d e w.c. no we just say not connected w.c. yes so also w.c. yes so also s.c. no

K4 K5 K6 N nodes, N(N-1) edges 2 (6*5)/2 = 15 edges (4*3)/2 = 6 edges K1K2 K3

All edges can be drawn on a plane with none crossing K3is planar This earlier graph K4 planar?

May be planar, but drawn poorly K4 K4 is planar Redraw one of the crossing edges, “rubber-band” it outside the others So here’s another graph algorithm… given graph G, is it planar? Have to solve this by wandering around in data structures for V, E you don’t have a drawing Determining planarity is important in laying out VLSI circuits on boards Metal “wires” cant cross

What about K5? No matter which inner edge you “stretch” you get a cross K5 not planar Turns out that K4 is the largest complete graph that is planar

Nodes are in two disjoint sets (types), and every edge connects different type nodes is bipartite not bipartite but now not is bipartite still is …

Can think of bipartite as colorable with 2 colors Every edge goes between the 2 color collections is bipartite a b c d e f g a b c d e f g

Tree is an acyclic graph. Prove it is bipartite Base: 1 node, just color it B b a c f d ih e g j k By induction on #nodes N Inductive Hypothesis: Every tree T with N nodes is bipartite. Inductive Step: Show that T’ with N+1 nodes is bipartite. Consider T = T’ less a leaf node v. T’ is a tree, and T’ has N nodes, and so by IH is bipartite. Node v in T has one neighbor (its parent); whatever the color of the parent is, assign v the other color. Then the arc between p and v is an arc connecting different color nodes. Node v is not part of any other edge. Therefore, T’ is bipartite.