1 / 18

Lecture 27: Graph ADT

CSC 213 – Large Scale Programming. Lecture 27: Graph ADT. Today’s Goals. Discuss what is NOT meant by term “Graph” Why no bar charts, scatter plots , & pie charts mentioned How term is used for mathematical graph Review terminology of mathematical graphs

yakov
Download Presentation

Lecture 27: Graph ADT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 213 – Large Scale Programming Lecture 27:Graph ADT

  2. Today’s Goals • Discuss what is NOT meant by term “Graph” • Why no bar charts, scatter plots, & pie charts mentioned • How term is used for mathematical graph • Review terminology of mathematical graphs • Why do we care about edges & vertices • Directed vs. undirected more than types of plays • Which 1 of these made up: incident, adjacent, feeder • Cycles & paths not related to Queen songs • Examine Graph ADT’s method & what they do

  3. Overview of Remainder of Term

  4. What We Are Not Discussing

  5. Graphs • Mathematically, graph is pair (V, E) where • Vis collection of nodes, called vertices • Two nodes can be connected by an edge in E • Positionimplemented by Vertex & Edge classes PVD 849 ORD 1843 142 SFO 802 LGA 1743 337 1387 HNL 2555 1099 LAX 1233 DFW 1120 MIA

  6. Edge Types • Edge connects two vertices in the graph • Image we have edge connecting u & v • (u,v) is name given to this edge

  7. Edge Types • Edge connects two vertices in the graph • Image we have edge connecting u & v • (u,v) is name given to this edge • Edges can be directed • One-way street is directed edge • uis originor source • vis destination Life Death

  8. Edge Types • Edge connects two vertices in the graph • Image we have edge connecting u & v • (u,v) is name given to this edge • Edges can be directed • One-way street is directed edge • uis originor source • vis destination • Undirected edge is alternative • Vertices listed in any order • Subway lines normally undirected Life Death Best Canisius

  9. Graph Types • Graph is directed if all edges directed • All edges in graph must be directed • Examples include trees & Java object hierarchy • Any edge allowed in undirected graphs • Can have only undirected or mix of both edges • Roadways & CSC major are examples of this

  10. Applications • Electronic circuits • Transportation networks • Databases • Packing suitcases • Finding terrorists • Scheduling college’s exams • Assigning classes to rooms • Garbage collection • Coloring countries on a map • Playing minesweeper

  11. Other Applications

  12. Terminology • Edge incident on its endpoints • U & Vendpointsofa • Vertices adjacent when joined by edge • Uadjacent to V • Vadjacent to U • Directedness unimportantdetermining adjacency V b a h j U X Z d i c e W g f Y

  13. Terminology • Degree of vertex is number incident edges • X has degree of 5 • Does not matter if edges directed or not • What the edges’ other endvertices unimportant • (Self-edges only count once) V b a h j U X Z d i c e W g f Y

  14. Path Terminology • Pathis set of vertices in Graph where • All of the consecutive vertices adjacent • May or may not have edge from last to first vertices (U,W,X,Y,W,V) is path V a b U X Z h c e W g f Y

  15. Path Terminology • Simple pathis a path which: • Is named by alternating vertices & edges • 0 or 1 appearance for each vertex & edge (V,b,X,h,Z) is simple path V a b d U X Z h c e W g f Y

  16. Cycle Terminology • Cycle is path with several additional properties • Each cycle must begin & end at same vertex • No edge required from this vertex to itself • Simple cycle is special cycle • But is also simple path (V,X,Y,W,U,V) is simple cycle V a b d U X Z h c e W g f Y

  17. Graph ADT • Accessor methods • vertices(): iterable for vertices • edges(): iterable for edges • endVertices(e): array with end points of edge e • opposite(v,e): e’send point that is not v • areAdjacent(v,w): check 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(x): create vertex storing elementx • insertEdge(v,w,x): add edge (v,w) with elementx • removeVertex(v): remove v(& incident edges) • removeEdge(e): remove e • Retrieval methods • incidentEdges(v): get edges incident to v

  18. For Next Lecture • New weekly assignment available now • Usual time for when it is due: 5PM on Tuesday • Consider design & develop tests for program #2 • 2nd deadline is Friday, so get cracking • Spend time working on this: design saves coding • Reading on implementing Graph for Friday • What are simplest implementations of Graph? • When would each be good to use is program?

More Related