Chapter 11 Graphs.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Review Binary Search Trees Operations on Binary Search Tree
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 8, Part I Graph Algorithms.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
Graph.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
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.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
Course notes CS2606: Data Structures and Object-Oriented Development Graphs Department of Computer Science Virginia Tech Spring 2008 (The following notes.
UNCA CSCI November, 2001 These notes were prepared by the text’s author Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
COSC 2007 Data Structures II Chapter 14 Graphs III.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs Slide credits:  K. Wayne, Princeton U.  C. E. Leiserson and E. Demaine, MIT  K. Birman, Cornell U.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Graphs. What is a graph? In simple words, A graph is a set of vertices and edges which connect them. A node (or vertex) is a discrete position in the.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Graph Search Applications, Minimum Spanning Tree
Graphs Chapter 20.
Graphs Representation, BFS, DFS
Data Structures 13th Week
Lecture 11 Graph Algorithms
Fundamentals, Terminology, Traversal, Algorithms
Minimum Spanning Tree Chapter 13.6.
Csc 2720 Instructor: Zhuojun Duan
12. Graphs and Trees 2 Summary
C.Eng 213 Data Structures Graphs Fall Section 3.
Introduction to Graphs
Depth-First Search.
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
CS202 - Fundamental Structures of Computer Science II
CS120 Graphs.
Graph Algorithm.
Graphs Representation, BFS, DFS
Graph Algorithm.
Graphs Chapter 13.
Graphs Chapter 15 explain graph-based algorithms Graph definitions
Graphs Chapter 11 Objectives Upon completion you will be able to:
Graphs.
CSCI 333 Graphs Chapter 11 20, 22, and 25 November 2002.
Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}
Spanning Trees Longin Jan Latecki Temple University based on slides by
ITEC 2620M Introduction to Data Structures
Chapter 15 Graphs © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CSCI2100 Data Structures Tutorial
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Weighted Graphs & Shortest Paths
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Chapter 16 1 – Graphs Graph Categories Strong Components
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Elementary Graph Algorithms
Lecture 10 Graph Algorithms
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 .
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Chapter 11 Graphs

Definitions A graph is two sets. Edges connect nodes. A set of nodes or vertices V A set of edges E Edges connect nodes. The number of vertices |V| The number of edges |E| A sparse graph is one with relatively few edges A dense graph is one with relatively many edges A graph with all possible edges is complete

More Definitions A graph with edges directed from one vertex to another is a direct graph or a diagraph A graph whose edges are not directed is called an undirected graph A graph with labels associated with its vertices is called a labeled graph Two vertices that share an edge are called adjacent. They are also called neighbors. An edge connecting vertices u and v is written (u,v). The edge is said to be incident on u and v. Associated with each edge may be a cost or a weight.

Still More Definitions A sequence of vertices v1, v2,…,vn forms a path of length n-1 if there exist edges from vi to vi+1 for 1 <= i < n. A path is simple if all vertices on the path are unique A cycle is a path of length 3 or more that connects some vertex to itself. A cycle is simple if the path is simple except for the first and last vertices.

Yes More Definitions A subgraph S is formed from Graph G by selecting a subset of Vs of G’s vertices and a subset Es of G’s edges such that for every edge E in Es, both whose vertices are in Vs. An undirected graph is connected if there is at least one path from any vertex to any other. A graph without cycles is called acyclic. A directed graph without cycles is called directed acyclic graph or DAG

Graph Representations Adjacency Matrix If a pair of vertices have an edge between them, then there is a 1 in the matrix. Adjacency List If a vertex has an edge, then a node is added to its list with the other node as the data

Graph Implementations A common activity that graphs must support is traversals This usually requires finding the node that is closest or the first node Then you usually need to find the next node after some given node. Another common member needed for a graph implementation is a way to mark each of the vertices

Graph Traversals To visit the vertices of a graph in some specific order based on the graph’s topology. There are some troublesome issues It may not be possible to reach all of the vertices from each other The graph may contain cycles and we need to make sure that the cycles do not cause an infinite loop

The Mark Graphs will typically maintain a mark for each vertex in the graph. They will clear the marks before a traversal begins and set the mark as they go. When the traversal is done we can check the marks to see if all the vertices have been visited.

Depth-first Search Whenever a vertex is visited, a DFS will recursively visit all of its unvisited neighbors. void DFS(Graph* G, int v) { Previsit(G, v); G->setMark(v, VISITED); for(int w=G->first(v); w<G->n(); w=G->next(v, w) ) if (G->getMark(v) == UNVISITED) DFS(G, w); PostVisit(G,v); }

Breadth-First Search Examines all vertices connected to the start vertex before visiting vertices further away Similar to DFS except a queue replaces the recursion stack. If the graph is a tree, this is equivalent to traversing level by level.

Shortest Paths Problem Single-source shortest-path Given a vertex v in a graph G, what is the shortest path from v to all other vertices in G This is usually solved by a classic algorithm. Dijkstra’s Algorithm

Dijkstra’s Algorithm The algorithm maintains a distance estimate from each vertex to every other vertex. Initially, every distance is set to infinity. Vertices are process in order of distance. Whenever a vertex is processed, its distance is updated for all of its neighbors.

Minimum-Cost Spanning Trees MST problem takes a connected, undirected, weighted graph. The MST is the graph containing the vertices of G along with the subset of G’s edges that Has minimum total cost as measured by summing the values for all of the edges in the subset Keeps the vertices connected.

Minimum-Cost Spanning Tree There are two main algorithms for solving this problem Prim’s algorithm Kruskal’s algorithm