SlideServe
Menu
Préférences
© SlideServe · v2026

CS261 Data Structures

jeremy-good avatar
15 diapositives · 301 Views · Nov 02, 2014

This guide explores single-source reachability in graphs using an edge list representation. It outlines the algorithm for finding all reachable nodes from the city of Peoria, focusing on two methods: using a set and a stack. The algorithm initializes a set of reachable vertices, iteratively explores neighbors, and collects reachable nodes. Sample cities include Pendleton, Pittsburgh, Pueblo, Princeton, Phoenix, and Pensacola. The implementation leverages data structures like dynamic arrays and maps. Additionally, a discussion prompt encourages consideration of alternative approaches, such as using a queue.

CS261 Data Structures - slide 1
01 / 15CS261 Data Structures
1 / 17

Télécharger la présentation

CS261 Data Structures
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CS261 Data Structures Single Source Reachability - Edge List Representation

  2. Question Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola • What nodes are reachable from Peoria?

  3. Single Source Reachability: Edge-List findReachable(graph g, vertex start) { create a set of reachable vertices, initially empty. call this r. create a container for vertices known to be reachable. call this c add start vertex to container c while the container c is not empty { remove first entry from the container c, assign to v if v is not already in the set of reachable vertices r { add v to the reachable set r add the neighbors of v, not already reachable, to the container c return r

  4. Single Source Reachability: Stack Let’s use a Stack as our container Basic algorithm: Initialize set of reachable vertices and add vi to a stack While stack is not empty Get and remove (pop) last vertex v from stack if vertex v is not in reachable, add it to reachable For all neighbors, vj, of v, if vj is NOT in reachable add to stack

  5. Single-Source Reachability: Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola What cities are reachable from peoria? [Just for repeatability, when I push neighbors on the stack, I do so in alphabetical order)

  6. Single-Source Reachability: Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola What cities are reachable from peoria?

  7. Single-Source Reachability: Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola

  8. Single-Source Reachability: Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola

  9. Single-Source Reachability:Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola

  10. Single-Source Reachability: Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola

  11. Single-Source Reachability: Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola

  12. Single-Source Reachability: Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola

  13. Single-Source Reachability: Stack Pierre Peoria Pendleton Pittsburgh Pueblo Princeton Phoenix Pensacola

  14. Implementation • Reachable: Array of integers: R[i] = 0 / 1 • Stack: dynamic array deque, LL Deque • Graph Representation (edge list): • Dynamic array of LinkedLists • HashMap of LinkedLists • key = name of node • value = list of neighbors

  15. Your Turn • Worksheet 41 • Something to think about… • What happens if we use a Queue instead of a Stack to hold the unexplored neighbors?