CS261 Data Structures Single Source Reachability - Edge List Representation.

Slides:



Advertisements
Similar presentations
EXAMPLE: X Y Z T 5 VERTICES 6 EDGES S Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet.
Advertisements

Stacks, Queues, and Linked Lists
1. Find the cost of each of the following using the Nearest Neighbor Algorithm. a)Start at Vertex M.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Analysis of Algorithms CS Data Structures Section 2.6.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Topological Sort and Hashing
CS 261 Reachability Problems. The classic Reachability algorithm findReachable (graph g, vertex start) { create a set of reachable vertices, initially.
Graphs - II CS 2110, Spring Where did I leave that book?
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
CS171 Introduction to Computer Science II Graphs Strike Back.
Graphs CS3240, L. grewe.
CS 261 – Recitation 9 & 10 Graphs & Final review
Graphs.
CS 261- Winter 2009 Dynamic Array Queue and Deque.
Shortest Paths and Dijkstra's Algorithm CS 110: Data Structures and Algorithms First Semester,
Data Structures - Stacks. What are data structures? Different ways to organize data What data structures have we used before? lists / arrays Deck (AceyDeucey)
Graph.
Graphs CS-240/341. Graphs Used for representing many-to-many relationships –can take two forms directed (digraph) - a finite set of elements called vertices.
What is the next line of the proof? a). Let G be a graph with k vertices. b). Assume the theorem holds for all graphs with k+1 vertices. c). Let G be a.
CS 261 – Data Structures Graphs. Used in a variety of applications and algorithms Graphs represent relationships or connections Superset of trees (i.e.,
Graphs.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Alyce Brady CS 510: Computer Algorithms Breadth-First Graph Traversal Algorithm.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
Transforming Infix to Postfix
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CSC 2300 Data Structures & Algorithms March 30, 2007 Chapter 9. Graph Algorithms.
CS261 Data Structures DFS and BFS – Edge List Representation.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Chapter 9 Abstract Data Types and Algorithms. 2 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified.
CSCI-455/552 Introduction to High Performance Computing Lecture 18.
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
1 Chapter 28 Weighted Graph Applications. 2 Objectives F To represent weighted edges using adjacency matrices and priority queues (§28.2). F To model.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 28 Weighted Graph.
Chapter 7 Stacks II CS Data Structures I COSC 2006
CS261 – Data Structures Graphs. Goals Introduction and Motivation Representations.
Data Structures and Algorithms Ver. 1.0 Session 17 Objectives In this session, you will learn to: Implement a graph Apply graphs to solve programming problems.
Data structures Abstract data types Java classes for Data structures and ADTs.
CS261 Data Structures Dijkstra’s Algorithm – Edge List Representation.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Graph Theory By: Maciej Kicinski Chiu Ming Luk. Extract Triple words.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
DIRECTED ACYCLIC GRAPHS AND TOPOLOGICAL SORT CS16: Introduction to Data Structures & Algorithms Tuesday, March 10,
Graphs Upon completion you will be able to:
Breadth-first and depth-first traversal Prof. Noah Snavely CS1114
Breadth-first and depth-first traversal CS1114
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Lecture 12 Graph Algorithms
What is the next line of the proof?
More Graph Algorithms.
Data Structures – Stacks and Queus
Graphs Part 2 Adjacency Matrix
Lecture 16 CSE 331 Oct 8, 2012.
COMP171 Depth-First Search.
Lecture 11 Graph Algorithms
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

CS261 Data Structures Single Source Reachability - Edge List Representation

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

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

Single Source Reachability: Stack Let’s use a Stack as our container Basic algorithm: Initialize set of reachable vertices and add v i 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, v j, of v, if v j is NOT in reachable add to stack

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix What cities are reachable from peoria? [Just for repeatability, when I push neighbors on the stack, I do so in alphabetical order) Stack(top->bot)Reachable 0Peoria{}

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix What cities are reachable from peoria? Stack(top->bot)Reachable 0peoria{} 1publeo, pittsburghpeoria

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix Stack(top->bot)Reachable 0peoria{} 1pueblo, pittsburghpeoria 2pierre, pittsburghpeoria, pueblo

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix Stack(top->bot)Reachable 0peoria{} 1pueblo, pittsburghpeoria 2pierre, pittsburghpeoria, pueblo 3pendleton, pittsburghpeoria, pueblo, pierre

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix Stack(top->bot)Reachable 0peoria{} 1pueblo, pittsburghpeoria 2pierre, pittsburghpeoria, pueblo 3pendleton, pittsburghpeoria, pueblo, pierre 4phoenix, pittsburghpeoria, pueblo, pierre, pendleton

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix Stack(top->bot)Reachable 0peoria{} 1pueblo, pittsburghpeoria 2pierre, pittsburghpeoria, pueblo 3pendleton, pittsburghpeoria, pueblo, pierre 4phoenix, pittsburghpeoria, pueblo, pierre, pendleton 5pittsburgh, pittsburghpeoria, pueblo, pierre, pendleton, phoenix

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix Stack(top->bot)Reachable 0peoria{} 1pueblo, pittsburghpeoria 2pierre, pittsburghpeoria, pueblo 3pendleton, pittsburghpeoria, pueblo, pierre 4phoenix, pittsburghpeoria, pueblo, pierre, pendleton 5pittsburgh, pittsburghpeoria, pueblo, pierre, pendleton, phoenix 6pensacola, pittsburghpeoria, pueblo, pierre, pendleton, phoenix, pittsburgh

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix Stack(top->bot)Reachable 0peoria{} 1pueblo, pittsburghpeoria 2pierre, pittsburghpeoria, pueblo 3pendleton, pittsburgh peoria, pueblo, pierre 4phoenix, pittsburghpeoria, pueblo, pierre, pendleton 5pittsburgh, pittsburgh peoria, pueblo, pierre, pendleton, phoenix 6pensacola, pittsburgh peoria, pueblo, pierre, pendleton, phoenix, pittsburgh 7pittsburghpeoria, pueblo, pierre, pendleton, phoenix, pittsburgh,pensacola

Single-Source Reachability: Stack Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix Stack(top->bot)Reachable 0peoria{} 1pueblo, pittsburgh peoria 2pierre, pittsburghpeoria, pueblo 3pendleton, pittsburgh peoria, pueblo, pierre 4phoenix, pittsburgh peoria, pueblo, pierre, pendleton 5pittsburgh, pittsburgh peoria, pueblo, pierre, pendleton, phoenix 6pensacola, pittsburgh peoria, pueblo, pierre, pendleton, phoenix, pittsburgh 7pittsburghpeoria, pueblo, pierre, pendleton, phoenix, pittsburgh,pensacola 8{}peoria, pueblo, pierre, pendleton, phoenix, pittsburgh,pensacola

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

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