L08 - Graphs.pdf

# L08 - Graphs.pdf - 337 LAX ORD 802 SFO 1843 1233 DFW Graphs...

• 82

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

Graphs ORD DFW SFO LAX 802 1843 1233 337

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

Graphs } A graph is a pair ( V, E ) , where } V is a set of nodes, called vertices } E is a collection of pairs of vertices, called edges } Vertices and edges have meaning when constructed from a problem } Example: } A vertex represents an airport and stores the three-letter airport code } An edge represents a flight route between two airports and stores the mileage of the route ORD PVD MIA DFW SFO LAX LGA HNL 849 802 1843 1120 1233 337 2555 © Goodrich Tamassia 2
Edge Types } Directed edge } ordered pair of vertices ( u , v ) } first vertex u is the origin } second vertex v is the destination } e.g., a flight } Undirected edge } unordered pair of vertices ( u , v ) } e.g., a flight route } Directed graph } all the edges are directed } e.g., route network } Undirected graph } all the edges are undirected } e.g., flight network ORD PVD flight AA 1206 ORD PVD 849 miles © Goodrich Tamassia 3

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

John David Paul brown.edu cox.net cs.brown.edu att.net qwest.net math.brown.edu cslab1b cslab1a Applications } Electronic circuits } Printed circuit board } Integrated circuit } Transportation networks } Highway network } Flight network } Computer networks } Local area network } Internet } Web } Databases } Entity-relationship diagram © Goodrich Tamassia 4
Terminology } End vertices (or endpoints) of an edge } U and V are the endpoints of edge a } Edges incident on a vertex } a , d , and b are incident on V } Adjacent vertices } U and V are adjacent } Degree of a vertex } X has degree 5 } Parallel edges } h and i are parallel edges } Self-loop } j is a self-loop X U V W Z Y a c b e d f g h i j © Goodrich Tamassia 5

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

P 1 Terminology (cont.) } Path } sequence of alternating vertices and edges } begins with a vertex } ends with a vertex } each edge is preceded and followed by its endpoints } Simple path } path such that all its vertices and edges are distinct } Examples } P 1 =( V , b , X , h , Z ) is a simple path } P 2 =( U , c , W , e , X , g , Y , f , W , d , V ) is a path that is not simple X U V W Z Y a c b e d f g h P 2 © Goodrich Tamassia 6
Terminology (cont.) } Cycle } circular sequence of alternating vertices and edges } each edge is preceded and followed by its endpoints } Simple cycle } cycle such that all its vertices and edges are distinct } Examples } C 1 =( V , b , X , g , Y , f , W , c , U , a , ) is a simple cycle } C 2 =( U , c , W , e , X , g , Y , f , W , d , V , a , ) is a cycle that is not simple C 1 X U V W Z Y a c b e d f g h C 2 © Goodrich Tamassia 7

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

Properties Notation n number of vertices m number of edges deg( v ) degree of vertex v Property 1 Σ v deg( v ) = 2 m Proof: each edge is counted twice Property 2 In an undirected graph with no self-loops and no multiple edges m n ( n ± 1) / 2 Proof: each vertex has degree at most ( n ± 1) What is the bound for a directed graph? Example n n = 4 n m = 6 n deg( v ) = 3 © Goodrich Tamassia 8
Main Methods of the Graph ADT } Vertices and edges } are positions } store elements (problem based) } Accessor methods } endVertices (e): an array of the two endvertices of e } opposite (v, e): the vertex opposite of v on e } areAdjacent (v, w): true iff v and w are adjacent } replace (v, x): replace element at vertex v with x } replace (e, x): replace element at edge e with x } Update methods }

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

This is the end of the preview. Sign up to access the rest of the document.
• One '14

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern