Download presentation
Presentation is loading. Please wait.
1
CSC 213 – Large Scale Programming Lecture 27: Graph ADT
2
Graphs Graph is a pair (V, E), where V is collection of nodes, called vertices E is collection of edges, where an edge connects 2 nodes Vertex and Edge each implement Position ORD PVD MIA DFW SFO LAX LGA HNL 849 802 1387 1743 1843 1099 1120 1233 337 2555 142
3
Edge Types Each edge links two vertices Imagine edge connecting u & v Edge written as (u,v) Directed edge Ordered pair of vertices u is origin or source v is destination Like a one-way street Undirected edge -- (u,v) Un ordered pair of vertices Similar to subway line ORDPVD ORDPVD
4
Graphs Types Directed graph Also called a digraph All edges in graph must be directed Examples include Java object hierarchy Undirected graph Edges are mix of directed & undirected Examples include American highways
5
Applications Electronic circuits Transportation networks Computer networks Databases Packing suitcases Finding terrorists Scheduling college’s exams Assigning classes to rooms Garbage collection Coloring countries on a map Playing minesweeper
6
Terminology Edge incident on its endpoints U & V endpoints of a Vertices adjacent when joined by edge U & V are adjacent Degree of vertex is number incident edges X has degree 5 XU V W Z Y a c b e d f g h i j
7
More Terminology Path Alternates vertices & edges Begins & ends at vertices Edge preceded & followed by endpoints ( U, c, W, e, X, g, Y, f, W, d, V ) is a path Simple path Visits vertices & edges at most once ( V, b, X, h, Z ) is a simple path XU V W Z Y a c b e d f g h
8
Even More Terminology Cycle Path that begins & ends at same vertex Simple cycle Cycle that is also simple path ( V, b, X, g, Y, f, W, c, U, a, ) is simple cycle C1C1 XU V W Z Y a c b e d f g h
9
Graph ADT Accessor methods vertices(): iterable collection of vertices edges(): iterable collection of edges endVertices(e): array with endvertices of e opposite(v,e): e’s endvertex that is not v areAdjacent(v,w): tests if v and w are adjacent replace(v,x): make x new element at vertex v replace(e,x): make x new element at edge e Update methods insertVertex(o): add vertex storing element o insertEdge(v,w,o): add edge (v,w) with element o removeVertex(v): kill v (& its incident edges) removeEdge(e): remove e Retrieval methods incidentEdges(v): edges incident to v
10
For Next Lecture Discuss first Graph ADT implementation How should we store edge & vertex collections How do we implement the different methods? Is this approach efficient?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.