CS4800: Algorithms & Data Jonathan Ullman

Similar documents
Algorithm Design and Analysis

Algorithm Design and Analysis

Algorithm Design and Analysis

Homework Assignment #3 Graph

Graphs & Digraphs Tuesday, November 06, 2007

CS4800: Algorithms & Data Jonathan Ullman

Info 2950, Lecture 16

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Copyright 2000, Kevin Wayne 1

Graph Algorithms (part 3 of CSC 282),

Algorithms: Lecture 10. Chalmers University of Technology

Undirected Graphs. Hwansoo Han

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Graph Algorithms (part 3 of CSC 282),

3.1 Basic Definitions and Applications

Trees. Arash Rafiey. 20 October, 2015

ECE 242 HOMEWORK 5. In the figure below, one can go from node B to A but not from A to B.

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

COMPSCI 311: Introduction to Algorithms First Midterm Exam, October 3, 2018

CS4800: Algorithms & Data Jonathan Ullman

(Dijkstra s Algorithm) Consider the following positively weighted undirected graph for the problems below: 8 7 b c d h g f

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

CS 206 Introduction to Computer Science II

Week 11: Minimum Spanning trees

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.

3.1 Basic Definitions and Applications. Chapter 3. Graphs. Undirected Graphs. Some Graph Applications

Homework 5: Graphs, Minimum Spanning Trees, and Dijkstra Shortest-Path

Outline. Graphs. Divide and Conquer.

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

Solutions to relevant spring 2000 exam problems

Problem Score Maximum MC 34 (25/17) = 50 Total 100

Graph: representation and traversal

3.1 Basic Definitions and Applications

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Graph. Vertex. edge. Directed Graph. Undirected Graph

CS 491 CAP Introduction to Graphs and Search

Spanning trees. Suppose you have a connected undirected graph

GRAPHS Lecture 17 CS2110 Spring 2014

Lecture 9 Graph Traversal

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Spanning Trees. Lecture 22 CS2110 Spring 2017

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

Lecture 3: Graphs and flows

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

W4231: Analysis of Algorithms

Chapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

CS/COE

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

Graphs - I CS 2110, Spring 2016

GRAPHICAL ALGORITHMS. UNIT _II Lecture-12 Slides No. 3-7 Lecture Slides No Lecture Slides No

Fundamental Algorithms

Total Score /1 /20 /41 /15 /23 Grader

Test points UTA Student ID #

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Algorithms Activity 6: Applications of BFS

Chapter 9 Graph Algorithms

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

GRAPHS Lecture 19 CS2110 Spring 2013

Breadth First Search. Graph Traversal. CSE 2011 Winter Application examples. Two common graph traversal algorithms

LECTURE 26 PRIM S ALGORITHM

Pred 8 1. Dist. Pred

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Question Paper Code : 97044

CS 361 Data Structures & Algs Lecture 13. Prof. Tom Hayes University of New Mexico

CS302 - Data Structures using C++

Graph traversal is a generalization of tree traversal except we have to keep track of the visited vertices.

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Graph Traversals. CS200 - Graphs 1

CS 310 Advanced Data Structures and Algorithms

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS

Searching in Graphs (cut points)

22.1 Representations of graphs

Unweighted Graphs & Algorithms

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Plan. CMPSCI 311: Introduction to Algorithms. Recall. Adjacency List Representation. DFS Descriptions. BFS Description

Lecture 10: Analysis of Algorithms (CS ) 1

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Graph Algorithms Using Depth First Search

Parallel Breadth First Search

Konigsberg Bridge Problem

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

Copyright 2000, Kevin Wayne 1

(Re)Introduction to Graphs and Some Algorithms

CS 361 Data Structures & Algs Lecture 15. Prof. Tom Hayes University of New Mexico

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

CISC 320 Midterm Exam

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

CS 561, Lecture 9. Jared Saia University of New Mexico

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Transcription:

CS4800: Algorithms & Data Jonathan Ullman Lecture 11: Graphs Graph Traversals: BFS Feb 16, 2018

What s Next

What s Next Graph Algorithms: Graphs: Key Definitions, Properties, Representations Exploring Graphs: Breadth/Depth First Search Applications: Connectivity, Bipartiteness, Topological Sorting Shortest Paths: Dijkstra Minimum Spanning Trees: Borůvka, Prim, Kruskal Network Flow: Algorithms Unlimited Applications

Graphs

Graphs: Key Definitions Definition: A directed graph! = #, % # is the set of nodes/vertices % # # is the set of edges An edge is an ordered ( = ), * from ) to * Definition: An undirected graph! = #, % Edges are unordered ( = ), * between ) and * Simple Graph: No duplicate edges No self-loops ( = ), )

Ask the Audience How many edges can there be in a simple directed/undirected graph?

Graphs Are Everywhere Transportation networks Communication networks WWW Biological networks Citation networks Social networks

Paths/Connectivity A path is a sequence of consecutive edges in % ), +,, +,, + -, + -, +.,, + 01,, * The length of the path is the # of edges An undirected graph is connected if for every two vertices ), * #, there is a path from ) to *

Paths/Connectivity A path is a sequence of consecutive edges in % ), +,, +,, + -, + -, +.,, + 01,, * The length of the path is the # of edges A directed graph is strongly connected if for every two vertices ), * #, there are paths from ) to * and from * to )

Cycles A cycle is a path *, * - * 0 *, where 5 2 and *,,, * 0 are distinct

Ask the Audience Suppose an undirected graph! is connected True/False?! has 8 1 edges

Ask the Audience Suppose an undirected graph! has = 8 1 edges True/False?! is connected

Trees An undirected graph! is a tree if:! is connected! contains no cycles Theorem: any two of the following implies the third! is connected! contains no cycles! has = 8 1 edges

Trees Rooted tree: choose a root node : and orient edges away from : Models hierarchical structure

Phylogeny Trees

Parse Trees if (A[x]==2) then (32 2 + (a*64 +12)/8) else fibonacci(n) if-then-else == + fn-call array ref 2 power + / 8 fibonacci n A x 32 2 * 12 a 64

Exploring a Graph

Exploring a Graph Problem: Is there a path from ; to <? Idea: Explore all nodes reachable from ;. Two different search techniques: Breadth-First Search: explore all nearby nodes before moving on to further away nodes Depth-First Search: follow a path until you get stuck

Exploring a Graph BFS/DFS are a General Template for Graph Algs Extensions of Breadth-First Search: 2-Coloring (Bipartiteness) Shortest Paths Minimum Spanning Tree (Prim s Algorithm) Extensions of Depth-First Search: Finding Cycles Topological Sorting Strongly Connected Components

Breadth-First Search (BFS) Informal Description: start at ;, find all neighbors of ;, find all neighbors of neighbors of ;, BFS Algorithm: = > = ; =, = all neighbors of = > = - = all neighbors of =, that are not in = >, =, =? = all neighbors of =?1, that are not in = >,, =?1, Stop when =?@, is empty.

Ask the Audience BFS this graph from ; = 1

Ask the Audience BFS this graph from ; = 1

Breadth-First Search (BFS) Definition: the distance between ;, < is the number of edges on the shortest path from ; to < Theorem: BFS reveals the distance from ; to all other nodes! Nodes in layer = A have distance exactly B from ; Nodes not in any layer are not reachable from ;

Implementing Graph Search GenericSearch(;): C = ; While there is an edge ), * where ) C, * C Add * to C To implement we need to decide: How to represent the graph as input? How to track the vertices that are already explored? How to choose the next edge to explore?

Adjacency-Matrix Representation The adjacency matrix of a graph! = #, % with 8 nodes is the matrix E 1: 8, 1: 8 where E B, H = I 1 B, H % 0 B, H % Cost Space: Θ # - Lookup: Θ 1 time List Neighbors: Θ # time A 1 2 3 4 1 0 1 1 0 2 0 0 1 0 3 0 0 0 0 4 0 0 1 0 2 1 3 4

Adjacency-List Representation The adjacency list of a vertex * # is the list E[*] of all the neighbors of * E 1 = 2,3 E 2 = 3 E 3 = E 4 = 3 2 1 3 4

BFS Implementation Initialize found * false * # BFS(;): Initialize found ; true Initialize layer ; 0, layer * * ; Initialize B 0, = > ;, ` While (= A is not empty) Initialize a new layer = A@, For () = A ): For ( ), * %): If (found * = false) then Set found * true, layer * B + 1 Add (), *) to `, add * to = A@, Increment the layer B B + 1