DOC PREVIEW
UMBC CMSC 341 - Graphs - CMSC 341

This preview shows page 1-2-3-23-24-25-26-46-47-48 out of 48 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CMSC 341Basic Graph DefinitionsGraph ApplicationsBasic Graph Definitions (2)Undirected GraphDirected GraphA Single Graph with Multiple ComponentsBasic Graph Definitions (3)Basic Graph Definitions (4)Paths in GraphsPaths in Graphs (2)Connectedness in GraphsDisjoint Sets and GraphsUndirected Graph/Disjoint Set ExampleDiGraph / Strongly Connected ComponentsA Graph ADTAdjacency Matrix ImplementationUndirected Graph / Adjacency MatrixDirected Graph / Adjacency MatrixWeighted, Directed Graph / Adjacency MatrixAdjacency Matrix PerformanceAdjacency List ImplementationVector of ListsAdjacency List PerformanceGraph TraversalsBreadth-First TraversalBreadth-First ExampleUnweighted Shortest Path ProblemRecursive Depth First TraversalDFS with explicit stackDFS ExampleSlide 32GetAdjacentGetAdjacent (2)Number of EdgesSlide 36Dijkstra’s AlgorithmSlide 38Dijkstra ExampleCorrectness of Dijkstra’s AlgorithmRunning Time of Dijkstra’s AlgorithmDijkstra and Negative EdgesDirected Acyclic GraphsMore DefinitionsTopological OrderingTopological SortTopSort ExampleRunning Time of TopSortCMSC 341Graphs8/3/2007UMBC CMSC 341 Graphs2Basic Graph DefinitionsA graph G = (V,E) consists of a finite set of vertices, V, and a finite set of edges, E. Each edge is a pair (v,w) where v, w  V.V and E are sets, so each vertex v  V is unique, and each edge e  E is unique.Edges are sometimes called arcs or lines.Vertices are sometimes called nodes or points.8/3/2007UMBC CMSC 341 Graphs3Graph ApplicationsGraphs can be used to model a wide range of applications includingIntersections and streets within a cityRoads/trains/airline routes connecting cities/countriesComputer networksElectronic circuits8/3/2007UMBC CMSC 341 Graphs4Basic Graph Definitions (2)A directed graph is a graph in which the edges are ordered pairs. That is, (u,v)  (v,u), u, v  V. Directed graphs are sometimes called digraphs.An undirected graph is a graph in which the edges are unordered pairs. That is, (u,v) = (v,u).A sparse graph is one with “few” edges.That is |E| = O( |V| )A dense graph is one with “many” edges.That is |E| = O( |V|2 )8/3/2007UMBC CMSC 341 Graphs5Undirected GraphAll edges are two-way. Edges are unordered pairs.V = { 1, 2 ,3, 4, 5}E = { (1,2), (2, 3), (3, 4), (2, 4), (4, 5), (5, 1) }213 458/3/2007UMBC CMSC 341 Graphs6Directed Graph1523 4All edges are “one-way” as indicated by the arrows. Edges are ordered pairs.V = { 1, 2, 3, 4, 5}E = { (1, 2), (2, 4), (3, 2), (4, 3), (4, 5), (5, 4), (5, 1) }8/3/2007UMBC CMSC 341 Graphs7A Single Graph with Multiple Components7698213 458/3/2007UMBC CMSC 341 Graphs8Basic Graph Definitions (3)Vertex w is adjacent to vertex v if and only if (v, w)  E. For undirected graphs, with edge (v, w), and hence also (w, v), w is adjacent to v and v is adjacent to w.An edge may also have:weight or cost -- an associated valuelabel -- a unique nameThe degree of a vertex, v, is the number of vertices adjacent to v. Degree is also called valence.Basic Graph Definitions (4)For directed graphs vertex w is adjacent to vertex v if and only if (v, w)  E.Indegree of a vertex w is the number of edges (v,w).OutDegree of a vertex w is the number of edges(w,v).1523 4213 458/3/2007UMBC CMSC 341 Graphs10Paths in GraphsA path in a graph is a sequence of vertices w1, w2, w3, …, wn such that (wi, wi+1)  E for 1  i < n.The length of a path in a graph is the number of edges on the path. The length of the path from a vertex to itself is 0.A simple path is a path such that all vertices are distinct, except that the first and last may be the same.A cycle in a graph is a path w1, w2, w3, …, wn , w  V such that:there are at least two vertices on the pathw1 = wn (the path starts and ends on the same vertex)if any part of the path contains the subpath wi, wj, wi, then each of the edges in the subpath is distinct (i. e., no backtracking along the same edge)A simple cycle is one in which the path is simple.A directed graph with no cycles is called a directed acyclic graph, often abbreviated as DAGPaths in Graphs (2)How many simple paths from 1 to 4 and what are their lengths?1523 4213 458/3/2007UMBC CMSC 341 Graphs12Connectedness in GraphsAn undirected graph is connected if there is a path from every vertex to every other vertex.A directed graph is strongly connected if there is a path from every vertex to every other vertex.A directed graph is weakly connected if there would be a path from every vertex to every other vertex, disregarding the direction of the edges.A complete graph is one in which there is an edge between every pair of vertices.A connected component of a graph is any maximal connected subgraph. Connected components are sometimes simply called components.8/3/2007UMBC CMSC 341 Graphs13Disjoint Sets and GraphsDisjoint sets can be used to determine connected components of an undirected graph.For each edge, place its two vertices (u and v) in the same set -- i.e. union( u, v )When all edges have been examined, the forest of sets will represent the connected components.Two vertices, x, y, are connected if and only if find( x ) = find( y )8/3/2007UMBC CMSC 341 Graphs14Undirected Graph/Disjoint Set ExampleSets representing connected components { 1, 2, 3, 4, 5 }{ 6 }{ 7, 8, 9 }7698213 458/3/2007UMBC CMSC 341 Graphs15DiGraph / Strongly Connected Componentsagbhd fcije8/3/2007UMBC CMSC 341 Graphs16A Graph ADTHas some data elementsVertices and EdgesHas some operationsgetDegree( u ) -- Returns the degree of vertex u (outdegree of vertex u in directed graph)getAdjacent( u ) -- Returns a list of the vertices adjacent to vertex u (list of vertices that u points to for a directed graph)isAdjacentTo( u, v ) -- Returns TRUE if vertex v is adjacent to vertex u, FALSE otherwise.Has some associated algorithms to be discussed.8/3/2007UMBC CMSC 341 Graphs17Adjacency Matrix ImplementationUses array of size |V|  |V| where each entry (i ,j) is boolean TRUE if there is an edge from vertex i to vertex jFALSE otherwisestore weights when edges are weightedVery simple, but large space requirement = O(|V|2)Appropriate if the graph is dense.Otherwise, most of the entries in the table are FALSE.For example, if a graph is used to represent a street map like Manhattan in which most streets run E/W or N/S, each


View Full Document

UMBC CMSC 341 - Graphs - CMSC 341

Download Graphs - CMSC 341
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Graphs - CMSC 341 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Graphs - CMSC 341 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?