Graphs CS 105. 10/02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Analysis of Algorithms CS 477/677
22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
Graph-02.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
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.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
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.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
CTIS 154 Discrete Mathematics II1 8.2 Paths and Cycles Kadir A. Peker.
Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Graphs. Graph A “graph” is a collection of “nodes” that are connected to each other Graph Theory: This novel way of solving problems was invented by a.
Graph Operations And Representation. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
ALG0183 Algorithms & Data Structures Lecture 18 The basics of graphs. 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks.
GRAPH Learning Outcomes Students should be able to:
Graph. Data Structures Linear data structures: –Array, linked list, stack, queue Non linear data structures: –Tree, binary tree, graph and digraph.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Graphs Chapter 12.
Graphs1 Definitions Examples The Graph ADT LAX PVD LAX DFW FTL STL HNL.
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Spring 2007Graphs1 ORD DFW SFO LAX
Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements.
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.
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
Data Structures & Algorithms Graphs
Graph A graph G is a set V(G) of vertices (nodes) and a set E(G) of edges which are pairs of vertices. abcd e i fgh jkl V = { a, b, c, d, e, f, g, h, i,
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.
COSC 2007 Data Structures II Chapter 14 Graphs I.
GRAPHS.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
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 황승원 Fall 2010 CSE, POSTECH. 2 2 Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
MAT 2720 Discrete Mathematics Section 8.2 Paths and Cycles
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Graphs Upon completion you will be able to:
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
1) Find and label the degree of each vertex in the graph.
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.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University Graphs Original Slides by Rada Mihalcea.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Graphs ORD SFO LAX DFW Graphs 1 Graphs Graphs
BCA-II Data Structure Using C Submitted By: Veenu Saini
Graphs Chapter 20.
Graph theory Definitions Trees, cycles, directed graphs.
CS120 Graphs.
Graph Theory.
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Graph Operations And Representation
Walks, Paths, and Circuits
Graphs By Rajanikanth B.
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Graphs CS 2606.
Graphs G = (V,E) V is the vertex set.
GRAPHS.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

Graphs CS 105

10/02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition The Graph Data Structure set V of vertices collection E of edges (pairs of vertices in V) Drawing of a Graph vertex circle/oval edge line connecting the vertex pair

10/02/05 Graphs Slide 3 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Sample Uses Airports and flights Persons and acquaintance relationships (e.g., friendster) Intersections and streets Computers and connections; the Internet

10/02/05 Graphs Slide 4 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graph Example Graph G=(V,E): V={a,b,c,d}, E={(a,b),(b,c),(b,d),(a,d)} d a b c

10/02/05 Graphs Slide 5 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Directed Graph Edge set is a set of ordered pairs Graph G=(V,E): V={a,b,c,d}, E={(a,b),(b,c),(b,d),(d,b),(d,a)} d a b c

10/02/05 Graphs Slide 6 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Adjacency Vertices connected by an edge are adjacent An edge e is incident on a vertex v (and vice-versa) if v is an endpoint of e Degree of a vertex v, deg(v) number of edges incident on v if directed graph, indeg(v) and outdeg(v)

10/02/05 Graphs Slide 7 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graph Properties Graph G with n vertices and m edges  v in G deg(v) = 2m  v in G indeg(v) =  v in G outdeg(v) = m m is O(n 2 ) m <= n(n-1)/2 if G is undirected m <= n(n-1) if G is directed

10/02/05 Graphs Slide 8 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Subgraphs Graph H a subgraph of graph G vertex set of H is a subset of vertex set of G edge set of H is a subset of edge set of G Spanning subgraph vertex set of H identical to vertex set of G

10/02/05 Graphs Slide 9 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Paths and Cycles (simple) Path sequence of distinct vertices such that consecutive vertices are connected through edges (simple) Cycle same as path except that first and last vertices are identical Directed paths and cycles edge directions matter

10/02/05 Graphs Slide 10 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graph Implementations Edge List vertices and edges are nodes edge nodes refer to incident vertex nodes Adjacency List same as edge list but vertex nodes also refer to incident edge nodes Adjacency Matrix 2D matrix of vertices; entries are edges

10/02/05 Graphs Slide 11 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Implementation Examples Illustrate the following graph using the different implementations d a b c

10/02/05 Graphs Slide 12 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Edge List ABDC

10/02/05 Graphs Slide 13 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Adjacency List

10/02/05 Graphs Slide 14 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Adjacency Matrix

10/02/05 Graphs Slide 15 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Comparing Implementations Edge List simplest but most inefficient Adjacency List many vertex operations are O(d) time where d is the degree of the vertex Adjacency Matrix adjacency test is O(1) addition/removal of a vertex: resize 2D array

10/02/05 Graphs Slide 16 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Sample Graph problems Connectivity Determine if a given graph is connected; i.e., is there a path between any two vertices in the graph Euler tour Is there a sequence of vertices that traverse all edges in the graph exactly once Hamiltonian cycle Is there a simple cycle that connects all vertices in the graph

10/02/05 Graphs Slide 17 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Weighted Graphs Graph G = (V,E) such that there are weights/costs associated with each edge w((a,b)): cost of edge (a,b) representation: matrix entries costs d a b c e 35

10/02/05 Graphs Slide 18 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Problems on Weighted Graphs Minimum-cost Spanning Tree Given a weighted graph G, determine a spanning tree with minimum total edge cost Single-source shortest paths Given a weighted graph G and a source vertex v in G, determine the shortest paths from v to all other vertices in G Path length: sum of all edges in path Traveling Salesman Given a weighted graph G, provide shortest cycle that contains all vertices in G