lecture11graphs1

# lecture11graphs1 - Graphs and Graph Algorithms. What is a...

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

1 Graphs and Graph Algorithms. What is a graph Uses of graphs Topological search Depth first search Breath first search

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

View Full Document
2 Very basic problem: Maps How does Mapquest work?
3 Graphs V 1 V 2 V 4 V 3 V 5 Graph G=(V,E) V – Vertices E – Edges Edge e = {u,v}, where u,v V Most basic graph

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

View Full Document
4 Extensions Do edges have a direction? Directed graphs vs. Undirected graphs What’s the difference? Do edges have a weight? Weighted vs. Unweighted graphs What’s the difference? Two different topics here!
5 Directed Graphs V 1 V 2 V 4 V 3 V 5 Graph G=(V,E) V – Vertices E – Edges Edge e = (u,v), where u,v V Also called digraphs Edges have direction

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

View Full Document
6 Weighted Graphs V 1 V 2 V 4 V 3 V 5 Graph G=(V,E) V – Vertices E – Edges Edge e = {u,v,w} V x V x 2.3 4.1 1.2 3.7 87 2
7 Adjacency V 1 V 2 V 4 V 3 V 5 Vertex x is adjacent to vertex y if and only if (x,y) E V 2 is adjacent to: V 1 , V 4 , V 5

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

View Full Document
8 Path V 1 V 2 V 4 V 3 V 5 A path is a sequence of vertices v 1 , v 2 , …, v N such that (v i ,v i+1 ) E for all 1≤i<N-1 The length of the path in an unweighted graph is the number of edges on the path (not the number of vertices) Path: V , V , V , V
9 Special stuff Some graphs will assume (v,v) E Some will require you to explicitly state this An edge from a vertex to itself is a loop A simple path is a path where all vertices are distinct Except the first and last may be the same

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

View Full Document
10 Cycles V 1 V 2 V 4 V 3 V 5 A cycle is a path of length at least 1 such that v 1 = v N Rule: For undirected graphs, every edge in the cycle must be unique (can’t go backwards over the same edge) Cycle: V , V , V , V A graph is acyclic if it has no cycles
11 Cycles in Directed Graphs V 1 V 2 V 4 V 3 V 5 V 1 V 2 V 4 V 3 V 5 Cyclic Acyclic

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

View Full Document
12 DAG’s Directed Acyclic Graph So common we say DAG DAG does not imply only one path between any two nodes…
13 Representing graphs How can we represent graphs? Graphs tend to be far more application specific Rarely “general” implementations Though: XGMML – eXtensible Graph Markup and Modeling Language

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

View Full Document
14 Undirected Graph b a c d e f g a b c d e f g a b c d e f g 0 1 0 0 1 0 1 1 0 1 1 0 0 0 0 1 0 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 G=(V,E), where V = {a,b,c,d,e,f,g} E={{a,b},{a,g},{a,e},{b,d},{b,c}, {c,d},{c,e},{d,f},{e,f},{e,g}, {f,g}} a b c d e f g b e g a d c b e d c a f g Adjacency Matrix Adjacency List
15 b a c d e f g a b c d e f g a b c d e f g 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 Adjacency Matrix Directed Graphs Indegree of v V : # of incoming edges to v Outdegree of v: # of outgoing edges from v Degree of v: sum of indegree and outdegree Indeg(a) = 2 Outdeg(a) = 1 Deg(a) = 3 Adjacency List a: g e: a, g, c b: a, d, c f: e c: b, d, e g: f d: f

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

View Full Document
Implementation ideas? How to represent vertices?
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.

### Page1 / 72

lecture11graphs1 - Graphs and Graph Algorithms. What is a...

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

View Full Document
Ask a homework question - tutors are online