{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs340-09s_slides09-graphs

# cs340-09s_slides09-graphs - Graphs Traversals Shortest Path...

This preview shows pages 1–15. Sign up to view the full content.

Graphs : Traversals Shortest Path Minimum Spanning Trees Network Flow (and more graph stuff) and Complexity CS340: Data Structures and Algorithms Bouvier’s Presentation based on PPTs by: Rose Hoberman William White

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Graph Reperesentations
3 Graphs A graph G = (V, E) consists of a set of vertices , V , and a set of edges, E , each of which is a pair of vertices. If the edges are ordered pairs of vertices, then the graph is directed . Undirected, unweighted, unconnected, loopless graph (length of longest simple path: 2) Directed, unweighted, acyclic, weakly connected, loopless graph (length of longest simple path: 6) Directed, unweighted, cyclic, strongly connected, loopless graph (length of longest simple cycle: 7) Undirected, unweighted, connected graph, with loops (length of longest simple path: 4) Directed, weighted, cyclic, weakly connected, loopless graph (weight of longest simple cycle: 27) 3 4 2 4 2 3 5 6 3 6 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Graph Representations Adjacency Matrix: A B D H E G F C A B C D E F G H A B C D E F G H 1 1 0 0 0 0 1 0 1 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 0 0 1 0 A B D H E G F C A B C D E F G H A B C D E F G H 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 A B D H E G F C 3 4 2 4 2 3 5 6 3 6 5 A B C D E F G H A B C D E F G H 2 3 5 4 6 6 2 3 4 5 3 The Problem: Most graphs are sparse (i.e., most vertex pairs are not edges), so the memory requirement is excessive: Θ ( V 2 ).
5 Adjacency List: A B C D E F G H A A B B E G A G B C G E G D F H A B D H E G F C A B C D E F G H B B 3 H G 6 2 4 C A 3 5 3 5 4 2 D E G G 6 E A B D H E G F C 3 4 2 4 2 3 5 6 3 6 5 A B C D E F G H B E B G C A E D F G D H A B D H E G F C

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Graph Terminology
7 Paths and cycles A path is a sequence of nodes v 1 , v 2 , …, v N such that (v i ,v i +1 ) E for 0< i <N – The length of the path is N-1. Simple path : all v i are distinct, 0< i <N A cycle is a path such that v 1 =v N – An acyclic graph has no cycles

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 Cycles PIT BOS JFK DTW LAX SFO
9 More useful definitions In a directed graph: • The indegree of a node v is the number of distinct edges (w,v) E. • The outdegree of a node v is the number of distinct edges (v,w) E. A node with indegree 0 is a root .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
10 Trees are graphs dag - a d irected a cyclic g raph. tree - an undirected connected acyclic graph forest - an acyclic undirected graph (not necessarily connected) (i.e., each connected component is a tree)
11 Example DAG Watch Socks Shoes Underwear Pants Belt Tie Shirt Jacket a DAG implies an ordering on events

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
12 Example DAG In a complex DAG, it can be hard to find a schedule that obeys all the constraints. Watch Socks Shoes Underwear Pants Belt Tie Shirt Jacket
Topological Sort

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14 Topological Sort For a directed acyclic graph G = (V,E) A topological sort is an ordering of all of G’s vertices v 1 , v 2 , …, v n such that...
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 76

cs340-09s_slides09-graphs - Graphs Traversals Shortest Path...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online