Lecture 16 CSE 331 Oct 2, 2013.

Slides:



Advertisements
Similar presentations
Lecture 16 CSE 331 Oct 9, Announcements Hand in your HW4 Solutions to HW4 next week Remember next week I will not be here so.
Advertisements

Lecture 15 CSE 331 Oct 7, Mid-term stuff Chapters 1-3 in [KT] Sample mid-term (and graded HW3) at the END of class The web version has the correct.
Important Problem Types and Fundamental Data Structures
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
Lecture 13 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
DIRECTED ACYCLIC GRAPHS AND TOPOLOGICAL SORT CS16: Introduction to Data Structures & Algorithms Tuesday, March 10,
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
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.
Topological Sort. Sorting technique over DAGs (Directed Acyclic Graphs) It creates a linear sequence (ordering) for the nodes such that: –If u has an.
Breadth-First Search (BFS)
Lecture 16 CSE 331 Oct 5, 2011.
Topological Sorting.
Graphs Lecture 19 CS2110 – Spring 2013.
Chapter 15 Lists Objectives
CSE 2331/5331 Topic 9: Basic Graph Alg.
Lecture 20 CSE 331 Oct 15, 2010.
Lecture 15 CSE 331 Oct 3, 2016.
Lecture 16 CSE 331 Oct 5, 2016.
Lecture 17 CSE 331 Oct 3, 2014.
CS120 Graphs.
More Graph Algorithms.
Topological Sort.
Graph Algorithm.
Lecture 15 CSE 331 Oct 5, 2012.
Lecture 15 CSE 331 Sep 29, 2014.
Lecture 15 CSE 331 Oct 3, 2016.
Topological Sort.
Lecture 24 CSE 331 Oct 28, 2016.
Lecture 24 CSE 331 Oct 27, 2017.
Paul Beame in lieu of Richard Anderson
Lecture 14 CSE 331 Sep 30, 2016.
Lecture 12 CSE 331 Sep 26, 2016.
"Learning how to learn is life's most important skill. " - Tony Buzan
Lecture 14 CSE 331 Sep 30, 2011.
Lecture 17 CSE 331 Oct 10, 2012.
Search Related Algorithms
Topological Sort CSE 373 Data Structures Lecture 19.
Lecture 13 CSE 331 Oct 1, 2012.
Graph Representation (23.1/22.1)
Lectures on Graph Algorithms: searching, testing and sorting
Lecture 19 CSE 331 Oct 12, 2016.
Lecture 26 CSE 331 Nov 2, 2012.
Lecture 13 CSE 331 Sep 27, 2017.
Lecture 16 CSE 331 Oct 4, 2017.
Richard Anderson Autumn 2016 Lecture 5
Lecture 19 CSE 331 Oct 8, 2014.
Lecture 19 CSE 331 Oct 13, 2010.
Lecture 27 CSE 331 Oct 31, 2014.
Lecture 14 CSE 331 Oct 3, 2012.
Lecture 14 CSE 331 Sep 29, 2017.
Lecture 25 CSE 331 Oct 27, 2014.
Lecture 16 CSE 331 Oct 8, 2012.
Lecture 18 CSE 331 Oct 9, 2017.
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
Richard Anderson Winter 2009 Lecture 6
Lecture 15 CSE 331 Oct 3, 2011.
Lecture 17 CSE 331 Oct 7, 2011.
CSE 417: Algorithms and Computational Complexity
Important Problem Types and Fundamental Data Structures
Lecture 25 CSE 331 Oct 28, 2011.
Lecture 19 CSE 331 Oct 10, 2016.
Richard Anderson Winter 2019 Lecture 6
Richard Anderson Lecture 5 Graph Theory
Lecture 15 CSE 331 Oct 4, 2010.
Analysis and design of algorithm
Lecture 11 Graph Algorithms
Richard Anderson Winter 2019 Lecture 5
Lecture 13 CSE 331 Sep 28, 2016.
Richard Anderson Autumn 2015 Lecture 6
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:

Lecture 16 CSE 331 Oct 2, 2013

Group/Algo registration deadline BOTH DUE ON MONDAY!

Quiz next Wed In class 1:00pm-1:10pm sharp Two True/False with justification Qs

Sample mid-term exams

Today’s agenda Quick recap of run time analysis for BFS Quick run time analysis for DFS (and Queue version of BFS) Helping you schedule your activities for the day

O(m+n) BFS Implementation Input graph as Adjacency list BFS(s) Array CC[s] = T and CC[w] = F for every w≠ s Set i = 0 Set L0= {s} While Li is not empty Linked List Li+1 = Ø For every u in Li For every edge (u,w) Version in KT also computes a BFS tree If CC[w] = F then CC[w] = T Add w to Li+1 i++

All layers are considered in first-in-first-out order All the layers as one BFS(s) All layers are considered in first-in-first-out order CC[s] = T and CC[w] = F for every w≠ s Set i = 0 Set L0= {s} While Li is not empty Li+1 = Ø For every u in Li Can combine all layers into one queue: all the children of a node are added to the end of the queue For every edge (u,w) If CC[w] = F then CC[w] = T Add w to Li+1 i++

An illustration 1 2 3 4 5 7 8 6 1 7 2 3 8 4 5 6

Queue O(m+n) implementation BFS(s) CC[s] = T and CC[w] = F for every w≠ s O(n) Intitialize Q= {s} O(1) Σu O(nu) = O(Σu nu) = O(m) While Q is not empty Repeated at most once for each vertex u Delete the front element u in Q For every edge (u,w) O(nu) Repeated nu times O(1) If CC[w] = F then O(1) CC[w] = T Add w to the back of Q

Questions?

Implementing DFS in O(m+n) time Same as BFS except stack instead of a queue

A DFS run using an explicit stack 7 8 1 7 7 6 3 2 3 5 8 4 4 5 5 3 6 2 3 1

DFS stack implementation CC[s] = T and CC[w] = F for every w≠ s Same O(m+n) run time analysis as for BFS Intitialize Ŝ = {s} While Ŝ is not empty Pop the top element u in Ŝ For every edge (u,w) If CC[w] = F then CC[w] = T Push w to the top of Ŝ

Questions?

Reading Assignment Sec 3.3, 3.4 and 3.5 of [KT]

Directed graphs Model asymmetric relationships Precedence relationships u needs to be done before w means (u,w) edge

Directed graphs Adjacency matrix is not symmetric Each vertex has two lists in Adj. list rep.

Directed Acyclic Graph (DAG) No directed cycles Precedence relationships are consistent

Topological Sorting of a DAG Order the vertices so that all edges go “forward”