GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Graph A graph, G = (V, E), is a data structure where: V is a set of vertices (aka nodes) E is a set of edges We use graphs to represent relationships among.
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 Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph & BFS.
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.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Introduction to Graphs
Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
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.
Applied Discrete Mathematics Week 12: Trees
Balanced Binary Search Trees height is O(log n), where n is the number of elements in the tree AVL (Adelson-Velsky and Landis) trees red-black trees get,
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.
GRAPHS Education is what remains after one has forgotten what one has learned in school. Albert Einstein Albert Einstein Smitha N Pai.
9.2 Graph Terminology and Special Types Graphs
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.
Graphs CS /02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
Data Structures Using C++ 2E
Graphs. Motivating Problem Konigsberg bridge problem (1736): Konigsberg bridge problem (1736): C A B D ab c d e f g Starting in one land area, is it possible.
Been-Chian Chien, Wei-Pang Yang, and Wen-Yang Lin 6-1 Chapter 6 Graphs Introduction to Data Structure CHAPTER 6 GRAPHS 6.1 The Graph Abstract Data Type.
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 Chapter 12.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Data Structures & Algorithms Graphs
1/24 Introduction to Graphs. 2/24 Graph Definition Graph : consists of vertices and edges. Each edge must start and end at a vertex. Graph G = (V, E)
Chapter 5 Graphs  the puzzle of the seven bridge in the Königsberg,  on the Pregel.
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.
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 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,
Graph. 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.
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Chapter 6 Graphs. 2 Outline Definitions, Terminologies and Applications Graph Representation Elementary graph operations Famous Graph Problems.
Graphs Upon completion you will be able to:
Chapter 9: Graphs.
Graphs and Paths : Chapter 15 Saurav Karmakar
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.
Chapter 05 Introduction to Graph And Search Algorithms.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
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.
Introduction to Graphs
Introduction to Graphs
Balanced Binary Search Trees
Graph Operations And Representation
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.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Graph Operations And Representation
Graphs Chapter 7 Visit for more Learning Resources.
Graphs G = (V, E) V are the vertices; E are the edges.
Graph Operations And Representation
Graphs G = (V,E) V is the vertex set.
Chapter 9 Graph algorithms
Introduction to Graphs
Presentation transcript:

GRAPHS CSE, POSTECH

Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected, directed, weighted Graph representations: adjacency matrix, array adjacency lists, linked adjacency lists Graph search methods: breath-first, depth-first search Algorithms: – to find a path in a graph – to find the connected components of an undirected graph – to find a spanning tree of a connected undirected graph

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 vertices. Edges are also called arcs and lines. Vertices i and j are adjacent vertices iff (i, j) is an edge in the graph The edge (i, j) is incident on the vertices i and j

Graphs Undirected edge has no orientation (no arrow head) Directed edge has an orientation (has an arrow head) Undirected graph – all edges are undirected Directed graph – all edges are directed u v directed edge u v undirected edge

Undirected Graph

Directed Graph (Digraph)

Directed Graph It is useful to have a slightly refined notion of adjacency and incidence Directed edge (i, j) is incident to vertex j and incident from vertex i Vertex i is adjacent to vertex j, and vertex j is adjacent from vertex i In Figure 16.1, which graphs are undirected and which graphs are directed?

Applications – Communication Network vertex = router edge = communication link

Applications - Driving Distance/Time Map vertex = city edge weight = driving distance/time

Applications - Street Map Streets are one- or two-way. A single directed edge denotes a one-way street A two directed edge denotes a two-way street Read Example 16.1 and see Figure 16.2

Path A sequence of vertices P = i 1, i 2, …, i k is an i 1 to i k path in the graph G=(V, E) iff the edge (i j, i j+1 ) is in E for every j, 1≤ j < k What are possible paths in Figure 16.2(b)?

Simple Path A simple path is a path in which all vertices, except possibly in the first and last, are different What are possible simple paths in Figure 16.2(b)? Do Exercise 16.1 and explain why or why not

Length (Cost) of a Path Each edge in a graph may have an associated length (or cost). The length of a path is the sum of the lengths of the edges on the path What is the length of the path 5, 9, 11, 10?

Subgraph & Cycle Let G = (V, E) be an undirected graph A graph H is a subgraph of graph G iff its vertex and edge sets are subsets of those of G A cycle is a simple path with the same start and end vertex List all cycles of the graph of Figure 16.1(a)? – 1, 2, 3, 1 – 1, 4, 3, 1 – 1, 2, 3, 4, 1 Do Exercise 16.5

Spanning Tree Let G = (V, E) be an undirected graph A connected undirected graph that contains no cycles is a tree A subgraph of G that contains all the vertices of G and is a tree is a spanning tree A spanning tree has n vertices and n-1 edges What are possible spanning trees in Figure 16.1(a)?  See spanning trees of Figure 16.1(a) in Figure 16.3

Spanning Trees What are the possible spanning trees for this tree? What is the cost of each spanning tree?

Minimum-Cost Spanning Tree (MCST) The spanning tree that costs the least is called the minimum-cost spanning tree See Figure 16.4 Which tree is the MCST of the example tree given in the previous page? What is its cost?

Bipartite Graph A bipartite graph is a special graph where the set of vertices can be divided into two disjoint sets U and V such that no edge has both end- points in the same set. A simple undirected graph G = (V, E) is called bipartite if there exists a partition of the vertex set V = V 1 U V 2 so that both V 1 and V 2 are independent sets. Read Example 16.3 and see Figure 16.5 Do Exercise 16.7

Graph Properties

Number of Edges – Undirected Graph Each edge is of the form (u,v), u != v. The no. of possible pairs in an n vertex graph is n*(n-1) Since edge (u,v) is the same as edge (v,u), the number of edges in an undirected graph is n*(n-1)/2 Thus, the number of edges in an undirected graph is  n*(n-1)/2

Number of Edges - Directed Graph Each edge is of the form (u,v), u != v. The no. of possible pairs in an n vertex graph is n*(n-1) Since edge (u,v) is not the same as edge (v,u), the number of edges in a directed graph is n*(n-1) Thus, the number of edges in a directed graph is  n*(n-1)

Vertex Degree The degree of vertex i is the no. of edges incident on vertex i. e.g., degree(2) = 2, degree(5) = 3, degree(3) = 1

Sum of Vertex Degrees Sum of degrees = 2e (where e is the number of edges)

In-Degree of a Vertex In-degree of vertex i is the number of edges incident to i (i.e., the number of incoming edges). e.g., indegree(2) = 1, indegree(8) = 0

Out-Degree of a Vertex Out-degree of vertex i is the number of edges incident from i (i.e., the number of outgoing edges). e.g., outdegree(2) = 1, outdegree(8) = 2

Sum of In- and Out-Degrees Each edge contributes 1 to the in-degree of some vertex and 1 to the out-degree of some other vertex. Sum of in-degrees = sum of out-degrees = e, where e is the number of edges in the digraph.

Complete Undirected Graphs A complete undirected graph has n(n-1)/2 edges (i.e., all possible edges) and is denoted by K n What would a complete undirected graph look like when n=5? When n=6?

Complete Directed Graphs A complete directed graph (also denoted by K n ) on n vertices contains exactly n(n-1) edges See Figure 16.7 for complete digraphs for n = 1, 2, 3 and 4 What would a complete directed graph look like when n=5? When n=6? Do Exercise 16.9

ADT graph See ADT 16.1 for the abstract data type specification of a graph See Program 16.1 for the abstract class definition of graph

Sample Graph Problems Path Finding Problems Connectedness Problems Spanning Tree Problems

Path Finding Path between 1 and 8 What is a possible path & its length? A path is 1, 2, 5, 9, 8 and its length is 20.

Another Path Between 1 and 8 Path length is 28. What is the path?

Example of No Path No path between 2 and 9.

Connected Graph Let G = (V, E) be an undirected graph G is connected iff there is a path between every pair of vertices in G

Example of Not Connected

Example of Connected Graph

Connected Component A connected component is a maximal subgraph that is connected. A connected graph has exactly 1 component.

Connected Components

Not a Component

Communication Network Each edge is a link that can be constructed (i.e., a feasible link)

Communication Network Problems Is the network connected? – Can we communicate between every pair of cities? Find the components. Want to construct the smallest number of feasible links so that resulting network is connected.

Cycles and Connectedness Removal of an edge that is on a cycle does not affect connectedness. Which edges can be removed without affecting the connectedness?

Cycles and Connectedness Connected subgraph with all vertices and minimum number of edges has no cycles.

Representation of Unweighted Graphs The most frequently used representations for unweighted graphs are – Adjacency Matrix – Linked adjacency lists – Array adjacency lists

Adjacency Matrix 0/1 n x n matrix, where n = # of vertices A(i, j) = 1 iff (i, j) is an edge.

Adjacency Matrix Properties Diagonal entries are zero. Adjacency matrix of an undirected graph is symmetric (A(i,j) = A(j,i) for all i and j).

Adjacency Matrix for Digraph Diagonal entries are zero. Adjacency matrix of a digraph need not be symmetric. See Figure 16.9 for more adjacency matrices

Adjacency Matrix Complexity n 2 bytes of space is needed to represent adjacency matrix For an undirected graph, we may store only lower or upper triangle (exclude diagonal): (n-1)n/2 bytes. See Figure for adjacency matrices of Figure 16.9 with diagonals eliminated Requires O(n) time to find vertex degree and/or vertices adjacent to a given vertex.

Adjacency Lists Adjacency list for vertex i is a linear list of vertices adjacent from vertex i. An array of n adjacency lists for each vertex of the graph.

Linked Adjacency Lists Each adjacency list is a chain. Array length = n. # of chain nodes = 2e (undirected graph) # of chain nodes = e (digraph) See Figure for more linked adjacency lists

Array Adjacency Lists Each adjacency list is an array list. Array length = n. # of chain nodes = 2e (undirected graph) # of chain nodes = e (digraph) See Figure for more array adjacency lists

Representation of Weighted Graphs Weighted graphs are represented with simple extensions of those used for unweighted graphs The cost-adjacency-matrix representation uses a matrix C just like the adjacency-matrix representation does Cost-adjacency matrix: C(i, j) = cost of edge (i, j) Adjacency lists: each list element is a pair (adjacent vertex, edge weight) See Figure for cost-adjacency matrices See Figure for linked adjacency lists for weighted graph

Exercise – for the digraph Figure 16.2(b) (a) adjacency matrix(b) Linked adjacency list (c) Array adjacency list

READING READ Sections