Chapter 9 Graph algorithms Lec 21 Dec 1, 2010. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
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++
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.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
Chapter 3 The Greedy Method 3.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
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.
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
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.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
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.
Graph Operations And Representation. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
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.
Data Structures Using C++ 2E
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Shortest Path Problem Topic 11 ITS033 – Programming & Algorithms C B A E D F Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program,
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 2 Graph Algorithms.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
Data Structures & Algorithms Graphs
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
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.
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.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
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:
Introduction to Graphs
Introduction to Graphs
Unit 3 Graphs.
Shortest Path Problems
Graph Operations And Representation
Graph Algorithm.
Connected Components Minimum Spanning Tree
Graphs & Graph Algorithms 2
Graph Operations And Representation
Shortest Path Problems
Graphs G = (V, E) V are the vertices; E are the edges.
Chapter 16 1 – Graphs Graph Categories Strong Components
Graph Operations And Representation
Graphs G = (V,E) V is the vertex set.
Chapter 9 Graph algorithms
Introduction to Graphs
Introduction to Graphs
Presentation transcript:

Chapter 9 Graph algorithms Lec 21 Dec 1, 2010

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 a graph 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 one 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. A connected graph in which removal of any edge makes it unconnected. An cyclic graph in which addition of any edges introduces a cycle.

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 =

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. O(1) time to determine if there is an edge between two given vertices.

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)

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)

Single-source Shortest path problem directed, weighted graph is the input specified source s. want to compute the shortest path from s to all the vertices.

Example:

Dijkstra’s algorithm: Works when there are no negative weight edges. takes time O(e log n) where e = number of edges, n = number of vertices. suppose n ~ 10 5, e ~ 10 6, then the number of computations ~ 2 x 10 6

. Data structures needed: Adjacency list rep. of graph a heap some additional structures (e.g. array)

key operation: relaxation on edge For each node v, the algorithm assigns a value d[v] which gets updated and will in the end become the length of the shortest path from s to v.

implementation of relaxation

Dijkstra’s algorithm

Dijkstra’s algorithm – Example

Course summary