CS/ENGRD 2110 Object-Oriented Programming and Data Structures Fall 2014 Doug James Lecture 17: Graphs.

Slides:



Advertisements
Similar presentations
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
Advertisements

22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Graphs COL 106 Slide Courtesy : Douglas W. Harder, U Waterloo.
Graph & BFS.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lectures 3 Tuesday, 9/25/01 Graph Algorithms: Part 1 Shortest.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Connected Components, Directed Graphs, Topological Sort COMP171.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
22C:19 Discrete Math Graphs Spring 2014 Sukumar Ghosh.
Social Media Mining Graph Essentials.
Intro to Graphs CSIT 402 Data Structures II. CSIT 402 Graph Introduction2 Graphs Graphs are composed of ›Nodes (vertices) Can be labeled ›Edges (arcs)
1 Graphs Algorithms Sections 9.1, 9.2, and Graphs v1v1 v2v2 v5v5 v7v7 v8v8 v3v3 v6v6 v4v4 A graph G = (V, E) –V: set of vertices (nodes) –E: set.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 2 Graph Algorithms.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
1 CS104 : Discrete Structures Chapter V Graph Theory.
GRAPHS THEROY. 2 –Graphs Graph basics and definitions Vertices/nodes, edges, adjacency, incidence Degree, in-degree, out-degree Subgraphs, unions, isomorphism.
GRAPHS Lecture 19 CS2110 – Fall Time to do A4, Recursion Histogram: max: [00:02): 17 av: 5.2 [02:04): 102 median: 4.5 [04:06): 134 [06:08):
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Data Structures & Algorithms Graphs
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Part II Lecture 7. Lecture Objectives  Topological Sort  Spanning Tree  Minimum Spanning Tree  Shortest Path.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
CSC2100B Tutorial 10 Graph Jianye Hao.
CSCI2100 Data Structures Tutorial 12
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Great Theoretical Ideas in Computer Science for Some.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graph Revisited Fei Chen CSCI2100B Data Structures Tutorial 12 1.
Chapter 05 Introduction to Graph And Search Algorithms.
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
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.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
Chapter Chapter Summary Graphs and Graph Models Graph Terminology and Special Types of Graphs Representing Graphs and Graph Isomorphism Connectivity.
Graphs - I CS 2110, Spring 2017 Leonhard Euler. 1736
Graphs Lecture 19 CS2110 – Spring 2013.
School of Computing Clemson University Fall, 2012
Lecture 11 Graph Algorithms
GRAPHS Lecture 16 CS2110 Fall 2017.
Graph Algorithm.
Graphs Lecture 18 CS2110 – Fall 2009.
Modeling and Simulation NETW 707
Graphs Chapter 13.
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.
Chapter 11 Graphs.
GRAPHS Lecture 17 CS2110.
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS Lecture 17 CS2110 Spring 2018.
Richard Anderson Lecture 5 Graph Theory
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Fall 2014 Doug James Lecture 17: Graphs

Readings Chapter 28 Graphs Chapter 29 Graph Implementations 2

These are not Graphs 3...not the kind we mean, anyway

These are Graphs 4 K5K5 K 3,3 =

Applications of Graphs Communication networks; social networks Routing and shortest path problems Commodity distribution (network flow) Traffic control Resource allocation Numerical linear algebra (sparse matrices) Geometric modeling (meshes, topology, …) Image processing (e.g., graph cuts) Computer animation (e.g., motion graphs) Systems biology … 5

Applications of Graphs Communication networks; social networks Routing and shortest path problems Commodity distribution (network flow) Traffic control Resource allocation Numerical linear algebra (sparse matrices) Image processing (e.g., graph cuts) Systems biology Geometric modeling (meshes, topology, …) … 6 High School Dating (Bearman, Moody, and Stovel, 2004) (Image by Mark Newman)

Applications of Graphs Communication networks; social networks Routing and shortest path problems Commodity distribution (network flow) Traffic control Resource allocation Numerical linear algebra (sparse matrices) Image processing (e.g., graph cuts) Systems biology Geometric modeling (meshes, topology, …) … 7

Applications of Graphs Communication networks; social networks Routing and shortest path problems Commodity distribution (network flow) Traffic control Resource allocation Numerical linear algebra (sparse matrices) Image processing (e.g., graph cuts) Systems biology Geometric modeling (meshes, topology, …) … 8

9

10

11

12

Graph Definitions A directed graph (or digraph) is a pair (V, E) where – V is a set – E is a set of ordered pairs (u,v) where u,v   V Usually require u ≠ v (i.e., no self-loops) An element of V is called a vertex or node An element of E is called an edge or arc |V| = size of V, often denoted n |E| = size of E, often denoted m 13

Example Directed Graph (Digraph) 14 V = { a,b,c,d,e,f } E = { (a,b), (a,c), (a,e), (b,c), (b,d), (b,e), (c,d), (c,f), (d,e), (d,f), (e,f) } |V| = 6, |E| = 11 b a c d e f

Example Undirected Graph 15 An undirected graph is just like a directed graph, except the edges are unordered pairs (sets) {u,v} Example: b a c e d f V = { a,b,c,d,e,f } E = { {a,b}, {a,c}, {a,e}, {b,c}, {b,d}, {b,e}, {c,d}, {c,f}, {d,e}, {d,f }, {e,f } }

Some Graph Terminology Vertices u and v are called the source and sink of the directed edge (u,v), respectively Vertices u and v are called the endpoints of (u,v) Two vertices are adjacent if they are connected by an edge The outdegree of a vertex u in a directed graph is the number of edges for which u is the source The indegree of a vertex v in a directed graph is the number of edges for which v is the sink The degree of a vertex u in an undirected graph is the number of edges of which u is an endpoint 16 b a c e d f b a c d e f

More Graph Terminology A path is a sequence v 0,v 1,v 2,...,v p of vertices such that (v i,v i+1 ) ∈ E, 0 ≤ i ≤ p – 1 The length of a path is its number of edges – In this example, the length is 5 A path is simple if it does not repeat any vertices A cycle is a path v 0,v 1,v 2,...,v p such that v 0 = v p A cycle is simple if it does not repeat any vertices except the first and last A graph is acyclic if it has no cycles A directed acyclic graph is called a dag 17 v0v0 v5v5 b a c d e f

Is This a Dag? Intuition: – If it’s a dag, there must be a vertex with indegree zero This idea leads to an algorithm – A digraph is a dag if and only if we can iteratively delete indegree-0 vertices until the graph disappears 18 b a c d e f

Topological Sort We just computed a topological sort of the dag – This is a numbering of the vertices such that all edges go from lower- to higher-numbered vertices Useful in job scheduling with precedence constraints

Example of Topological Sort Starcraft II build order: Roach Rush HatcherySpawning PoolRoach WarrenRoaches Gas Possible Topological Sorts 1.Hatch, SPool, RWarren, Gas, Roaches 2.Hatch, SPool, Gas, RWarren, Roaches 3.Hatch, Gas, SPool, RWarren, Roaches Timing is everything though ;)

Graph Coloring A coloring of an undirected graph is an assignment of a color to each node such that no two adjacent vertices get the same color How many colors are needed to color this graph? 21

Graph Coloring A coloring of an undirected graph is an assignment of a color to each node such that no two adjacent vertices get the same color How many colors are needed to color this graph? 22

An Application of Coloring Vertices are jobs Edge (u,v) is present if jobs u and v each require access to the same shared resource, and thus cannot execute simultaneously Colors are time slots to schedule the jobs Minimum number of colors needed to color the graph = minimum number of time slots required 23

Planarity A graph is planar if it can be embedded in the plane with no edges crossing Is this graph planar? 24

Planarity A graph is planar if it can be embedded in the plane with no edges crossing Is this graph planar? – Yes 25

Planarity A graph is planar if it can be embedded in the plane with no edges crossing Is this graph planar? – Yes 26

Detecting Planarity Kuratowski's Theorem A graph is planar if and only if it does not contain a copy of K 5 or K 3,3 (possibly with other nodes along the edges shown) 27 K 3,3 K5K5

Four-Color Theorem: Every planar graph is 4-colorable. ( Appel & Haken, 1976) 28

Another 4-colored planar graph 29

Bipartite Graphs A directed or undirected graph is bipartite if the vertices can be partitioned into two sets such that all edges go between the two sets The following are equivalent – G is bipartite – G is 2-colorable – G has no cycles of odd length 30

Traveling Salesperson Find a path of minimum distance that visits every city 31 Amsterdam Rome Boston Atlanta London Paris Copenhagen Munich Ithaca New York Washington

Representations of Graphs Adjacency ListAdjacency Matrix

Adjacency Matrix or Adjacency List? Definitions – n = number of vertices – m = number of edges – d(u) = degree of u = number of edges leaving u Adjacency Matrix – Uses space O(n 2 ) – Can iterate over all edges in time O(n 2 ) – Can answer “Is there an edge from u to v?” in O(1) time – Better for dense graphs (lots of edges) Adjacency List – Uses space O(m+n) – Can iterate over all edges in time O(m+n) – Can answer “Is there an edge from u to v?” in O(d(u)) time – Better for sparse graphs (fewer edges) 33

Graph Algorithms Search – depth-first search – breadth-first search Shortest paths – Dijkstra's algorithm Minimum spanning trees – Prim's algorithm – Kruskal's algorithm 34

Readings Chapter 28 Graphs Chapter 29 Graph Implementations 35