Introduction to Graphs

Slides:



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

CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
 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.
Graph & BFS.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
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.
Introduction to Graphs
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
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.
Graphs Chapter 28 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Graph Operations And Representation. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
GRAPH Learning Outcomes Students should be able to:
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
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,
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Graphs Chapter 12.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
Graphs Edge(arc) Vertices can be even or odd or undirected (two-way) Edges can be directed (one-way) This graph is connected. Degree(order) = 3 Odd vertex.
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.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
Basic properties Continuation
Graphs Upon completion you will be able to:
Graphs and Shortest Paths Using ADTs and generic programming.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
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.
Applied Discrete Mathematics Week 14: Trees
Unit 10 Graphs (1) King Fahd University of Petroleum & Minerals
Chapter 9 (Part 2): Graphs
Introduction to Graphs
Graphs.
CS 367 – Introduction to Data Structures
Csc 2720 Instructor: Zhuojun Duan
Introduction to Graphs
CMSC 341 Lecture 21 Graphs (Introduction)
Comp 245 Data Structures Graphs.
Graph Operations And Representation
CSE373: Data Structures & Algorithms Lecture 16: Introduction to Graphs Linda Shapiro Spring 2016.
Graphs Graph transversals.
Graphs Chapter 13.
Graphs CSE 2011 Winter November 2018.
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:
CS100: Discrete structures
Graphs.
Graph Operations And Representation
Graphs.
ITEC 2620M Introduction to Data Structures
CSE 373 Data Structures and Algorithms
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Graphs.
Graphs G = (V, E) V are the vertices; E are the edges.
Graphs.
Graphs.
Graph Operations And Representation
Graphs.
Paths and Connectivity
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Paths and Connectivity
Graphs.
Graphs: Definitions How would you represent the following?
Chapter 9 Graph algorithms
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:

Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. Adjacency Matrix. Adjacency Lists. Review Questions.

What is a Graph? Graphs are Generalization of Trees. A simple graph G = (V, E) consists of a non-empty set V, whose members are called the vertices of G, and a set E of pairs of distinct vertices from V, called the edges of G. Undirected Directed (Diagraph) Weighted

Some Example Applications of Graph Finding the least congested route between two phones, given connections between switching stations. Determining if there is a way to get from one page to another, just by following links. Finding the shortest path from one city to another. As a travelling sales-person, finding the cheapest path that passes through all the cities that the sales person must visit. Determining an ordering of courses so that prerequisite courses are always taken first.

Graphs Terminologies Path Cycle Connected Disconnected Adjacent Vertices: there is a connecting edge. A Path: A sequence of adjacent vertices. A Cycle: A path in which the last and first vertices are adjacent. Connected graph: There is a path from any vertex to every other vertex. Path Cycle Connected Disconnected

More Graph Terminologies Path and cycles in a digraph: must move in the direction specified by the arrow. Connectedness in a digraph: strong and weak. Strongly Connected: If connected as a digraph - following the arrows. Weakly connected: If the underlying undirected graph is connected (i.e. ignoring the arrows). Directed Cycle Strongly Connected Weakly Connected

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. Out-degree: number of edges emanating from v -- |A(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. In-degree: number of edges incident to w -- |I(w)|. Directed Graph Undirected Graph

Graph Representation - Adjacency Matrix (Table) Two popular representation methods are Adjacency Matrix and Adjacency List. Adjacency Matrix uses a 2-D array of dimension |V|x|V|. 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(n2) - most of it wasted for a graph with few edges. However, entries in the matrix can be accessed directly.

Adjacency List Representation of Graph 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 at least three different ways. All Linked List: The set of vertices and the set of adjacent vertices for each vertex are represented as linked lists.

Adjacency List - Cont'd The all linked list method makes efficient use of storage, O(|V|+|E|). However, it does now allow random access. All Arrays: The set of vertices and the set of adjacent vertices for each vertex are represented using 2-D Array of dimension |V| x |V|. The first column is used for the vertices and the rest of the columns are used to store vertices adjacent to each vertex.

Adjacency List - Cont'd While the all array method supports random access, it obviously wastes storage. A compromise is to use a mixture of both array and linked list. Mixed Method: The set of vertices is represented using 1-D array while the set of edges emanating from each vertex is represented as linked lists.

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