1 / 16

Understanding Graphs: Nodes, Edges, and Structures

Learn about graph theory, paths, cycles, and more in the context of airline routes, computer networks, and course prerequisites. Explore terminology like degree, adjacency, weighted graphs, and directed graphs. Discover the concepts of trees in graphs and answer questions about graph properties.

Download Presentation

Understanding Graphs: Nodes, Edges, and Structures

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. CSE 373Data Structures and Algorithms Lecture 19: Graphs

  2. What are graphs? • Yes, this is a graph…. • But we are interested in a different kind of “graph”

  3. Airline Routes Nodes = cities Edges = direct flights

  4. New York Sydney Computer Networks 56 Tokyo Seattle 128 Seoul 16 181 30 140 L.A. Nodes = computers Edges = transmission rates

  5. CSE Course Prerequisites at UW 461 312 373 143 311 332 142 415 410 331 351 413 417 421 Nodes = courses Directed edge = prerequisite 401

  6. Graphs • graph: a data structure containing • a set of vertices V • a set of edges E, where an edge represents a connection between 2 vertices • edge is a pair (v, w) where v, w in V • Denote graph asG = (V, E) • Example: G = (V,E) where V = {a, b, c} and E = {(a, b), (b, c), (c, a)}

  7. Paths • path: a path from vertex A to B is a sequence of edges that can be followed starting from A to reach B • Can be represented as vertices visited or edges taken • Example: path from V to Z: {b, h} or {(v,x), (x,z)} or {V, X, Z} • reachability: v2 is reachable from v1 if a path exists from v1 to v2 • connected graph: one in which it is possible to reach any node from any other • Is this graph connected? V b a d U X Z h c e W g f Y

  8. Cycles • cycle: path from one node back to itself • Example: {V, X, Y, W, U, V} • loop: edge directly from node to itself • Many graphs don't allow loops V a b d U X Z h e c W g f Y

  9. V a b h j U d X Z c e i W g f Y More terminology • degree: number of edges touching a vertex • Example: W has degree 4 • What is the degree of X? of Z? • adjacent vertices: vertices connected directly by an edge

  10. 849 PVD 1843 ORD 142 SFO 802 LGA 1743 337 1387 HNL 2555 1099 1233 LAX 1120 DFW MIA Weighted graphs • weight: (optional) cost associated with a given edge • Example: graph of airline flights • If we were programming this graph, what information would we have to store for each vertex / edge?

  11. Directed graphs • directed graph (digraph): edges are one-way connections between vertices • If graph is directed, a vertex has a separate in/out degree

  12. Trees as Graphs • Every tree is a graph with some restrictions: • The tree is directed • There is exactly one directed path from the root to every node A B C D E F G H

  13. Graph questions • Are the following graphs directed or undirected? • Buddy graphs of instant messaging programs?(vertices = users, edges = user being on another's buddy list) • bus line graph depicting all of Seattle's bus stations and routes • graph of movies in which actors have appeared together • Are these graphs potentially cyclic? Why or why not?

  14. Graph exercise • Consider a graph of instant messenger buddies. • What do the vertices represent? What does an edge represent? • Is this graph directed or undirected? Weighted or unweighted? • What does a vertex's degree mean? In degree? Out degree? • Can the graph contain loops? Cycles?

  15. Graph exercise • Consider this graph data: • Jessica's buddy list: Meghan, Alan, Martin. • Meghan's buddy list: Alan, Lori. • Toni's buddy list: Lori, Meghan. • Martin's buddy list: Lori, Meghan. • Alan's buddy list: Martin, Jessica. • Lori's buddy list: Meghan. • Compute the in/out degree of each vertex. Is the graph connected? • Who is the most popular? Least? Who is the most antisocial? • If we're having a party and want to distribute the message the most quickly, who should we tell first?

  16. Graph exercise • Consider a graph of Facebook friends. • What do the vertices represent? What does an edge represent? • Is this graph directed or undirected? Weighted or unweighted? • What does a vertex's degree mean? In degree? Out degree? • Can the graph contain loops? Cycles?

More Related