13-graphs

# 13-graphs - Spring 2009 CS216: Program and Data...

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

Graphs CS216: Program and Data Representation University of Virginia Computer Science Spring 2009 Aaron Bloomfield www.cheswick.com/ches/ map /index.html

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

View Full Document
2 Topic Coverage • Graph terminology – Lots of it! • Ways of representing graphs and costs & benefits – Adjacency matrix – Adjacency list • Solving problems with graphs – Topological sort – Traveling salesperson
3 Graph examples • Google Maps, of course – Which actually uses MapQuest data – But we’ll call it Google Maps data • Others?

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

View Full Document
4 Airline maps From /site/seatsale/QF/images/ MR_Domestic-April2005.jpg
5 Flowcharts

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

View Full Document
6 Course pre-req graphs
7 Graphs G = ( V , E ) V are the vertices ; E are the edges . Edges are of the form (v, w) , where v, w V. • ordered pair: directed graph or digraph • unordered pair: undirected graph v 9 v 8 v 10 v 3 v 6 v 7 v 4 v 5 v 1 v 2

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

View Full Document
8 How big are these graphs? • These are educated guesses, by the way • Airport codes – There are probably 3,000 world-wide airports – Assume you can fly to 25 airports from each – That’s 3,000*25 = 75,000 edges • Google maps – There are probably 10 million vertices in the US – Assume each one connects to three others – That’s 3 * 10 million = 30 million edges
9 Terminology • A weight or cost can be associated with each edge. • w is adjacent to v iff (v, w) E. path : sequence of vertices w 1 , w 2 , w 3 , … , w N such that (w i , w i+1 ) E for 1 i < N. length of a path: number of edges in the path. simple path : all vertices are distinct.

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

View Full Document
10 How to weight a graph… • For Google maps? • For airline routes?
11 More terminology cycle : directed graph : path of length 1 such that w 1 = w N . undirected graph : same, except all edges are distinct. connected : there is a path from every vertex to every other vertex. loop : (v, v) E. complete graph : there is an edge between every pair of vertices.

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

View Full Document
12 Digraph terminology directed acyclic graph : no cycles. “DAG” strongly connected : there is a path from every vertex to every other vertex. weakly connected : the underlying undirected graph is connected. C D A B E F G
13 End of lecture on Wed, Apr 8 • Also did the last 13 slides of 12-huffman

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

View Full Document
14 Representation • adjacency matrix : 1 2 3 4 1 2 3 4 1 3 4 2
15 Representation • adjacency list: 1 2 3 4 2 3 4 3 1 2 1 3 4 2

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

View Full Document
16 Representation in the real world • Two types of representation – Adjacency matrix – Adjacency graph • How does Google maps probably store it? • How do airline routes probably store it?
Topological Sort

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

View Full Document
Topological Sort • Given a directed acyclic graph, construct an ordering of the vertices such that if there is a path from v i to v j , then v j appears after v i in the ordering. – The result is a linear list of vertices
This is the end of the preview. Sign up to access the rest of the document.

## 13-graphs - Spring 2009 CS216: Program and Data...

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

View Full Document
Ask a homework question - tutors are online