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

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

View Full Document Right Arrow Icon
1 Graphs and Graph Algorithms. What is a graph Uses of graphs Topological search Depth first search Breath first search
Background image of page 1

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

View Full Document Right Arrow Icon
2 Very basic problem: Maps How does Mapquest work?
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
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!
Background image of page 4
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
Background image of page 5

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

View Full Document Right Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full Document Right Arrow Icon
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
Background image of page 8
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
Background image of page 9

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

View Full Document Right Arrow Icon
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
Background image of page 10
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
Background image of page 11

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

View Full Document Right Arrow Icon
12 DAG’s Directed Acyclic Graph So common we say DAG DAG does not imply only one path between any two nodes…
Background image of page 12
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
Background image of page 13

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

View Full Document Right Arrow Icon
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
Background image of page 14
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
Background image of page 15

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

View Full Document Right Arrow Icon
Implementation ideas? How to represent vertices?
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 73

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online