13-graphs

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

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

View Full Document Right Arrow Icon
Graphs CS216: Program and Data Representation University of Virginia Computer Science Spring 2009 Aaron Bloomfield www.cheswick.com/ches/ map /index.html
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
3 Graph examples • Google Maps, of course – Which actually uses MapQuest data – But we’ll call it Google Maps data • Others?
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Airline maps From http://www.travelmood.com /site/seatsale/QF/images/ MR_Domestic-April2005.jpg
Background image of page 4
5 Flowcharts
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Course pre-req graphs
Background image of page 6
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
Background image of page 7

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

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

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

View Full DocumentRight Arrow Icon
10 How to weight a graph… • For Google maps? • For airline routes?
Background image of page 10
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.
Background image of page 11

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

View Full DocumentRight Arrow Icon
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
Background image of page 12
13 End of lecture on Wed, Apr 8 • Also did the last 13 slides of 12-huffman
Background image of page 13

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

View Full DocumentRight Arrow Icon
14 Representation • adjacency matrix : 1 2 3 4 1 2 3 4 1 3 4 2
Background image of page 14
15 Representation • adjacency list: 1 2 3 4 2 3 4 3 1 2 1 3 4 2
Background image of page 15

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

View Full DocumentRight Arrow Icon
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?
Background image of page 16
Topological Sort
Background image of page 17

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

View Full DocumentRight Arrow Icon
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
Background image of page 18
Image of page 19
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 73

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 Right Arrow Icon
Ask a homework question - tutors are online