Graph Operations And Representation. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Data Structures Using C++
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Chapter 8, Part I Graph Algorithms.
Data Structures Using C++
Data Structures Using Java1 Chapter 11 Graphs. Data Structures Using Java2 Chapter Objectives Learn about graphs Become familiar with the basic terminology.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
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.
Graph & BFS.
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.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Graphs & Graph Algorithms 2
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.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
ALG0183 Algorithms & Data Structures Lecture 18 The basics of graphs. 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks.
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.
1 Abstract Data Type We have discussed: List Tree Today we will talk about Graph.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Graphs Chapter 12.
7.1 and 7.2: Spanning Trees. A network is a graph that is connected –The network must be a sub-graph of the original graph (its edges must come from the.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Data Structures & Algorithms 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.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
COSC 2007 Data Structures II
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,
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.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Chapter 6 Graphs. 2 Outline Definitions, Terminologies and Applications Graph Representation Elementary graph operations Famous Graph Problems.
Graph Theory. undirected graph node: a, b, c, d, e, f edge: (a, b), (a, c), (b, c), (b, e), (c, d), (c, f), (d, e), (d, f), (e, f) subgraph.
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.
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.
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
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.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
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.
Graphs.
Graphs Chapter 20.
Introduction to Graphs
Introduction to Graphs
Unit 3 Graphs.
CS120 Graphs.
Graph Operations And Representation
Connected Components Minimum Spanning Tree
Graphs & Graph Algorithms 2
Graphs Chapter 13.
Graph Operations And Representation
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Graph Operations And Representation
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Graphs G = (V,E) V is the vertex set.
Chapter 9 Graph algorithms
Introduction to Graphs
Introduction to Graphs
Presentation transcript:

Graph Operations And Representation

Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.

Path Finding Path between 1 and Path length is 20.

Another Path Between 1 and Path length is 28.

Example Of No Path No path between 2 and

Connected Graph Undirected graph. There is a path between every pair of vertices.

Example Of Not Connected

Connected Graph Example

Connected Components

Connected Component A maximal subgraph that is connected.  Cannot add vertices and edges from original graph and retain connectedness. A connected graph has exactly 1 component.

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 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.

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

Tree Connected graph that has no cycles. n vertex connected graph with n-1 edges.

Spanning Tree Subgraph that includes all vertices of the original graph. Subgraph is a tree.  If original graph has n vertices, the spanning tree has n vertices and n-1 edges.

Minimum Cost Spanning Tree Tree cost is sum of edge weights/costs

A Spanning Tree Spanning tree cost =

Minimum Cost Spanning Tree Spanning tree cost =

A Wireless Broadcast Tree Source = 1, weights = needed power. Cost = =

Graph Representation Adjacency Matrix Adjacency Lists  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 (Digraph) Diagonal entries are zero. Adjacency matrix of a digraph need not be symmetric.

Adjacency Matrix n 2 bits of space For an undirected graph, may store only lower or upper triangle (exclude diagonal).  (n-1)n/2 bits 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 aList[1] = (2,4) aList[2] = (1,5) aList[3] = (5) aList[4] = (5,1) aList[5] = (2,4,3)

Linked Adjacency Lists Each adjacency list is a chain aList[1] aList[5] [2] [3] [4] Array Length = n # of chain nodes = 2e (undirected graph) # of chain nodes = e (digraph)

Array Adjacency Lists Each adjacency list is an array list aList[1] aList[5] [2] [3] [4] Array Length = n # of list elements = 2e (undirected graph) # of list elements = e (digraph)

Weighted Graphs Cost adjacency matrix.  C(i,j) = cost of edge (i,j) Adjacency lists => each list element is a pair (adjacent vertex, edge weight)

Number Of Java Classes Needed Graph representations  Adjacency Matrix  Adjacency Lists  Linked Adjacency Lists  Array Adjacency Lists  3 representations Graph types  Directed and undirected.  Weighted and unweighted.  2 x 2 = 4 graph types 3 x 4 = 12 Java classes

Abstract Class Graph package dataStructures; import java.util.*; public abstract class Graph { // ADT methods come here // create an iterator for vertex i public abstract Iterator iterator(int i); // implementation independent methods come here }

Abstract Methods Of Graph // ADT methods public abstract int vertices(); public abstract int edges(); public abstract boolean existsEdge(int i, int j); public abstract void putEdge(Object theEdge); public abstract void removeEdge(int i, int j); public abstract int degree(int i); public abstract int inDegree(int i); public abstract int outDegree(int i);