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.

Slides:



Advertisements
Similar presentations
Review Binary Search Trees Operations on Binary Search Tree
Advertisements

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.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Graph & BFS.
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.
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.
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.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
GRAPHS Education is what remains after one has forgotten what one has learned in school. Albert Einstein Albert Einstein Smitha N Pai.
GRAPH Learning Outcomes Students should be able to:
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.
Intro to Graphs CSIT 402 Data Structures II. CSIT 402 Graph Introduction2 Graphs Graphs are composed of ›Nodes (vertices) Can be labeled ›Edges (arcs)
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.
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.
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.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Chapter 5 Graphs  the puzzle of the seven bridge in the Königsberg,  on the Pregel.
Data Structures CSCI 132, Spring 2014 Lecture 38 Graphs
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.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: 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.
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,
Graphs Basic properties.
Graphs Upon completion you will be able to:
Copyright © Curt Hill Graphs Definitions and Implementations.
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.
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.
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
Fundamental Graph Theory (Lecture 1) Lectured by Hung-Lin Fu 傅 恆 霖 Department of Applied Mathematics National Chiao Tung University.
Unit 10 Graphs (1) King Fahd University of Petroleum & Minerals
Introduction to Graphs
Basic Concepts Graphs For more notes and topics visit:
Graphs.
CS 367 – Introduction to Data Structures
Introduction to Graphs
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.
CS100: Discrete structures
Graphs.
Graph Operations And Representation
Graphs.
Graphs Chapter 7 Visit for more Learning Resources.
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Trees-2, Graphs Data Structures with C Chpater-6 Course code: 10CS35
Graph Operations And Representation
Graphs: Definitions How would you represent the following?
Chapter 9 Graph algorithms
Heaps Chapter 6 Section 6.9.
Introduction to Graphs
For Friday Read chapter 9, sections 2-3 No homework
Introduction to Graphs
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

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 to each other The set of edges describes relationships among the vertices

Formal definition of graphs A graph G is defined as follows: G=(V,E) V(G): a finite, nonempty set of vertices E(G): a set of edges (pairs of vertices)

Directed vs. undirected graphs When the edges in a graph have no direction, the graph is called undirected Directed or not directed ? not Number of vertices and edges ? 4, 4 Name of vertice V Name edges

When the edges in a graph have a direction, the graph is called directed (or digraph) Directed vs. undirected graphs (cont.) V(Graph2)={1,3,5,7,9,11} E(Graph2) = {(1,3) (3,1) (5,9) (9,11) (5,7), (9,9), 11,1) Graph2 Number of vertices and edges ?

Trees are special cases of graphs!! Trees vs graphs Number of vertices and edges ?

Graph terminology Adjacent nodes: two nodes are adjacent if they are connected by an edge Path: a sequence of vertices that connect two nodes in a graph Complete graph: a graph in which every vertex is directly connected to every other vertex 5 is adjacent to 7 7 is adjacent from 5

What is the number of edges in a complete directed graph with N vertices? N * (N-1) Graph terminology (cont.)

What is the number of edges in a complete undirected graph with N vertices? N * (N-1) / 2 Graph terminology (cont.)

Weighted graph: a graph in which each edge carries a value Graph terminology (cont.)

Further Graph Terminologies Emanate: an edge e = (v, w) is said to emanate from v. – A(v) denotes the set of all edges emanating from v. Incident: an edge e = (v, w) is said to be incident to w. – I(w) denote the set of all edges incident to w. Out-degree: number of edges emanating from v -- |A(v)| In-degree: number of edges incident to w -- |I(w)|. Directed GraphUndirected Graph

Graph Representations For vertices: – an array or a linked list can be used For edges: – Adjacency Matrix (Two-dimensional array) – Adjacency List (One-dimensional array of linked lists) – Linked List (one list only)

Adjacency Matrix Representation Adjacency Matrix uses a 2-D array of dimension |V|x|V| for edges. (For vertices, a 1-D array is used) The presence or absence of an edge, (v, w) is indicated by the entry in row v, column w of the matrix. For an unweighted graph, boolean values could be used. For a weighted graph, the actual weights are used.

Notes on Adjacency Matrix For undirected graph, the adjacency matrix is always symmetric. In a Simple Graph, all diagonal elements are zero (i.e. no edge from a vertex to itself). The space requirement of adjacency matrix is O(n 2 ) - most of it wasted for a graph with few edges. However, entries in the matrix can be accessed directly.

Adjacency List Representation This involves representing the set of vertices adjacent to each vertex as a list. Thus, generating a set of lists. This can be implemented in different ways. Our representation: – Vertices as a one dimensional array – Edges as an array of linked list (the emanating edges of vertex 1 will be in the list of the first element, and so on, … vertices     edges  1,2  1,3 Null  2,3  2,4 Null  4,1  4,3 Null  4,2 Empty

Simple List Representation Vertices are represented as a 1-D array or a linked list Edges are represented as one linked list – Each edge contains the information about its two vertices verticesedges edge(1,2) edge(1,3) edge(2,3) edge(2,4) edge(4,1) edge(4,2) edge(4,3)

Review Questions 1.Consider the undirected graph GA shown above. List the elements of V and E. Then, for each vertex v in V, do the following: 1.Compute the in-degree of v 2.Compute the out-degree of v 3.List the elements of A(v) 4.List the elements of I(v). 2.Consider the undirected graph GA shown above. 1.Show how the graph is represented using adjacency matrix. 2.Show how the graph is represented using adjacency lists. 3.Repeat Exercises 1 and 2 for the directed graph GB shown above.