Intro to Graphs CSIT 402 Data Structures II. CSIT 402 Graph Introduction2 Graphs Graphs are composed of ›Nodes (vertices) Can be labeled ›Edges (arcs)

Slides:



Advertisements
Similar presentations
Introduction to Graphs
Advertisements

Graphs COL 106 Slide Courtesy : Douglas W. Harder, U Waterloo.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
1 Section 8.2 Graph Terminology. 2 Terms related to undirected graphs Adjacent: 2 vertices u & v in an undirected graph G are adjacent (neighbors) in.
1 Graph Introduction Definitions. 2 Definitions I zDirected Graph (or Di-Graph) is an ordered pair G=(V,E) such that yV is a finite, non-empty set (of.
Connected Components, Directed Graphs, Topological Sort Lecture 25 COMP171 Fall 2006.
CSE 321 Discrete Structures Winter 2008 Lecture 25 Graph Theory.
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.
Connected Components, Directed graphs, Topological sort COMP171 Fall 2005.
Selected Topics in Data Networking Graph Representation.
Applied Discrete Mathematics Week 12: Trees
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Fall 2014 Doug James Lecture 17: Graphs.
Chapter 9: Graphs Basic Concepts
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE Discrete.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
9.2 Graph Terminology and Special Types Graphs
Graph. Data Structures Linear data structures: –Array, linked list, stack, queue Non linear data structures: –Tree, binary tree, graph and digraph.
Graphs Chapter 10.
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,
Chapter 2 Graph Algorithms.
1 Graphs Chapters 9.1 and 9.2 University of Maryland Chapters 9.1 and 9.2 Based on slides by Y. Peng University of Maryland.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Module #19: Graph Theory: part I Rosen 5 th ed., chs. 8-9 내년 3 월 ? 교환 학생 프로그램 영어 점수 미리미리 준비하세요.
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.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
Data Structures Week 9 Introduction to Graphs Consider the following problem. A river with an island and bridges. The problem is to see if there is a way.
 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.
Graphs CSE 2011 Winter June Graphs A graph is a pair (V, E), where  V is a set of nodes, called vertices  E is a collection of pairs.
GRAPHS THEROY. 2 –Graphs Graph basics and definitions Vertices/nodes, edges, adjacency, incidence Degree, in-degree, out-degree Subgraphs, unions, isomorphism.
Graphs What are Graphs? General meaning in everyday math: A plot or chart of numerical data using a coordinate system. Technical meaning in discrete.
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,
9 Graphs. A graph G = (V, E) consists of V, a nonempty set of vertices (or nodes) and E, a set of edges. Each edge has either one or two vertices associated.
COSC 2007 Data Structures II Chapter 14 Graphs I.
Graphs 9.1 Graphs and Graph Models أ. زينب آل كاظم 1.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
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.
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,
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.
Chapter 9: Graphs.
Graph Revisited Fei Chen CSCI2100B Data Structures Tutorial 12 1.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University Graphs Original Slides by Rada Mihalcea.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
1 Graphs Chapters 10.1 and 10.2 University of Maryland Chapters 10.1 and 10.2 Based on slides by Y. Peng University of Maryland.
Subject Four Graphs Data Structures. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes.
Chapter Chapter Summary Graphs and Graph Models Graph Terminology and Special Types of Graphs Representing Graphs and Graph Isomorphism Connectivity.
Graphs Lecture 19 CS2110 – Spring 2013.
Basic Concepts Graphs For more notes and topics visit:
Graph Graphs and graph theory can be used to model:
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
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.
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
CS100: Discrete structures
Chapter 9: Graphs Basic Concepts
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Graph Terminology CSE 373 Data Structures.
CC 215 Data Structures Graph Terminology
CSE 373 Data Structures Lecture 17
Graphs By Rajanikanth B.
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Graph Terminology CSE 373 Data Structures.
Graph Algorithms DS.GR.1 Chapter 9 Overview Representation
Chapter 9: Graphs Basic Concepts
CSE 373 Data Structures Lecture 13
Graphs G = (V,E) V is the vertex set.
GRAPHS.
Presentation transcript:

Intro to Graphs CSIT 402 Data Structures II

CSIT 402 Graph Introduction2 Graphs Graphs are composed of ›Nodes (vertices) Can be labeled ›Edges (arcs) Directed (arrowhead) Undirected Can be labeled node edge

CSIT 402 Graph Introduction3 Graphs: Data Structure Progression Consider previous data structures Linked List: Nodes with 1 incoming edge and 1 outgoing edge Binary Trees/Heaps: Nodes with 1 incoming edge and 2 outgoing edges General Trees: Nodes with 1 incoming edge and any number of outgoing edges Idea: All of the above are graphs More examples on next seven slides… Value Next node Value Next node

CSIT 402 Graph Introduction4 Course Prerequisites Nodes = courses Directed edge = prerequisite

CSIT 402 Graph Introduction5 Representing a Maze S Nodes = locations Edge = paths between locations S E B E Directed or Undirected?

CSIT 402 Graph Introduction6 Representing Electrical Circuits Nodes = battery, switch, resistor, etc. Edges = connections Battery Switch Resistor Directed or Undirected?

CSIT 402 Graph Introduction7 Program statements x1=q+y*z x2=y*z-q Naive: common subexpression eliminated: yz * - q + q * x1x2 yz - q + q* x1x2 Nodes = symbols/operators Edges = relationships y*z calculated twice Directed or Undirected?

CSIT 402 Graph Introduction8 Precedence S 1 a=0; S 2 b=1; S 3 c=a+1 S 4 d=b+a; S 5 e=d+1; S 6 e=c+d; Which statements must execute before S 6 ? S 1, S 2, S 3, S 4 Nodes = statements Edges = precedence requirements Directed or Undirected? Values

CSIT 402 Graph Introduction9 Information Transmission in a Computer Network Seattle L.A. Tokyo Seoul Nodes = computers Edges = transmission rates Directed or Undirected? Values

CSIT 402 Graph Introduction10 Traffic Flow on Highways Nodes = cities Edges = # vehicles on connecting highway UW Directed or Undirected?

CSIT 402 Graph Introduction11 Formal Definition A graph G is a tuple (V, E) where ›V is a set of vertices or nodes ›E is a set of edges An Edge e is a pair (v 1,v 2 ), where v i ε V ›Example: V = {A, B, C, D, E, F} E = {(A,B), (A,D), (B,C), (C,D), (C,E), (D,E)} A B C E D F

If the order of edge pairs (v i, v j ) is important (e.g prerequisites), the graph is directed (also called a digraph): (v i, v j )  (v j, v i ), i  j If the order of edge pairs (v i, v j ) is unimportant (e.g. maze), the graph is called an undirected graph (never called an undigraph): In this case, (v i, v j ) = (v j, v i ), i  j CSIT 402 Graph Introduction12 Directed vs Undirected Graphs vivi vjvj vivi vjvj

CSIT 402 Graph Introduction13 Undirected Graph Terminology Two vertices u and v are adjacent in an undirected graph G if {u,v} is an edge in G ›edge e = {u,v} is incident (in contact) with vertex u and vertex v The degree of a vertex in an undirected graph is the number of edges incident with it ›a self-loop counts twice (both ends count) ›denoted with deg(v) A B C E D F Deg(D) = 3 Deg(F) = 0 (A,B) is incident to A and to B Self-loop B is adjacent to C and C is adjacent to B

CSIT 402 Graph Introduction14 Directed Graph Terminology Vertex u is adjacent to vertex v in a directed graph G if (u,v) is an edge in G ›vertex u is the initial vertex of (u,v) Vertex v is adjacent from vertex u ›vertex v is the terminal (or end) vertex of (u,v) Degree ›in-degree is the number of edges with the vertex as the terminal vertex ›out-degree is the number of edges with the vertex as the initial vertex

CSIT 402 Graph Introduction15 Directed Graph Terminology A B C E D F In-degree = 2 Out-degree = 1 In-degree = 0 Out-degree = 0 B adjacent to C and C adjacent from B

CSIT 402 Graph Introduction16 Handshaking Theorem Let G=(V,E) be an undirected graph with |E|=e edges. Then Every edge contributes +1 to the degree of each of the two vertices it is incident with ›number of edges is exactly half the sum of deg(v) ›the sum of the deg(v) values must be even Add up the degrees of all vertices.

CSIT 402 Graph Introduction17 Space and time are analyzed in terms of: Number of vertices = |V| and Number of edges = |E| There are at least two ways of representing graphs: The adjacency matrix representation The adjacency list representation Graph Representations

CSIT 402 Graph Introduction18 A B C D E F M(v, w) = 1 if (v, w) is in E 0 otherwise ABCDEFABCDEF Space = |V| 2 A B C E D F Adjacency Matrix

CSIT 402 Graph Introduction19 A B C D E F ABCDEFABCDEF Space = |V| 2 M(v, w) = 1 if (v, w) is in E 0 otherwise A B C E D F Adjacency Matrix for a Digraph

CSIT 402 Graph Introduction20 B D BD C A C E D E A C ABCDEFABCDEF A B C E D F Space = |V| + 2 |E| For each v in V, L(v) = list of w such that (v, w) is in E a b Adjacency List list of neighbors

CSIT 402 Graph Introduction21 B D E D C a b ABCDEFABCDEF E A B C E D F For each v in V, L(v) = list of w such that (v, w) is in E Space = |V| + |E| Adjacency List for a Digraph

CSIT 402 Directed Graphs 22 Paths and Cycles Given a directed graph G = (V,E), a path is a sequence of vertices v 1,v 2, …,v k such that: ›(v i,v i+1 ) in E for 1 < i < k path length = number of edges in the path path cost = sum of costs of each edge (if edges have costs) A graph contains a cycle if, there exists a path v 1,v 2, …,v k, k > 1 such that v k = v 1 G is acyclic if it has no cycles.