Lecture 13 CSE 331 Sep 28, 2016.

Slides:



Advertisements
Similar presentations
Lecture 13 CSE 331 Oct 2, Announcements Please turn in your HW 3 Graded HW2, solutions to HW 3, HW 4 at the END of the class Maybe extra lectures.
Advertisements

Lecture 12 CSE 331 Sep 30, Announcements Final exam: Dec 16, 11:45am-2:45pm, NSC 210 HW 2 solutions at the end of the lecture Mid term: Oct 16,
Lecture 14 CSE 331 Oct 5, Extra lectures on proofs Tuesday 5-6pm (Jeff) Wednesday 4:30-6pm (Atri) Commons 9 Prefer my name to Professor/Dr. Rudra.
Lecture 17 CSE 331 Oct 8, HW 4 due today Q1 and Q2 in one pile Q3 in another pile I will not take any HW after 1:15pm.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
Lecture 18 CSE 331 Oct 11, Mid term Next Monday in class.
Lecture 13 CSE 331 Oct 2, Announcements Mid term in < 2 weeks Graded HW2 at the END of the class.
Lecture 12 CSE 331 Sep 28, Upcoming Important Dates Tuesday Oct 8 (~1.5 weeks) Mini Project group compositions Monday Oct 12 (2 weeks) Quiz 1 Monday.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
CSC 172 DATA STRUCTURES.
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
Breadth-First Search (BFS)
Lecture 16 CSE 331 Oct 5, 2011.
Thinking about Algorithms Abstractly
CSE 373 Topological Sort Graph Traversals
Lecture 11 Graph Algorithms
Graph Algorithms BFS, DFS, Dijkstra’s.
CSC317 Graph algorithms Why bother?
CSE 2331/5331 Topic 9: Basic Graph Alg.
Graph Search Lecture 17 CS 2110 Fall 2017.
Depth-First Search.
Instructor: Lilian de Greef Quarter: Summer 2017
CS120 Graphs.
Graph Search Lecture 17 CS 2110 Spring 2018.
Lecture 15 CSE 331 Oct 5, 2012.
Lecture 15 CSE 331 Sep 29, 2014.
CSE 421: Introduction to Algorithms
Graphs Chapter 15 explain graph-based algorithms Graph definitions
Lecture 14 CSE 331 Sep 30, 2016.
Lecture 12 CSE 331 Sep 26, 2016.
Lecture 12 CSE 331 Sep 25, 2017.
Lecture 14 CSE 331 Sep 30, 2011.
Can you get there from here?
Lecture 13 CSE 331 Oct 1, 2012.
Chapter 22: Elementary Graph Algorithms I
Graph Algorithms What is a graph? V - vertices E µ V x V - edges
Elementary Graph Algorithms
Graphs Part 2 Adjacency Matrix
Lecture 13 CSE 331 Sep 27, 2017.
Lecture 13 CSE 331 Sep 24, 2013.
Depth-First Search D B A C E Depth-First Search Depth-First Search
Algorithms Lecture # 30 Dr. Sohail Aslam.
Lecture 19 CSE 331 Oct 13, 2010.
Lecture 14 CSE 331 Oct 3, 2012.
Lecture 12 CSE 331 Sep 28, 2012.
Lecture 12 CSE 331 Sep 26, 2011.
Lecture 14 CSE 331 Sep 29, 2017.
Lecture 16 CSE 331 Oct 8, 2012.
COMP171 Depth-First Search.
Lecture 16 CSE 331 Oct 2, 2013.
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
Lecture 15 CSE 331 Oct 3, 2011.
Depth-First Search CSE 2011 Winter April 2019.
Lecture 11 CSE 331 Sep 19, 2014.
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Lecture 11 CSE 331 Sep 21, 2017.
Lecture 12 CSE 331 Sep 22, 2014.
Graph Traversal Lecture 18 CS 2110 — Spring 2019.
Depth-First Search CSE 2011 Winter April 2019.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Lecture 11 CSE 331 Sep 22, 2016.
3.2 Graph Traversal.
Applications of BFS CSE 2011 Winter /17/2019 7:03 AM.
Elementary Graph Algorithms
Lecture 15 CSE 331 Oct 4, 2010.
Analysis and design of algorithm
Lecture 10 Graph Algorithms
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:

Lecture 13 CSE 331 Sep 28, 2016

Mini Project Pitch due in a week

T/F polls up on piazza

Today’s agenda Computing Connected component (with DFS)

DFS(u) Mark u as explored and add u to R For each edge (u,v) If v is not explored then DFS(v)

Why is DFS a special case of Explore?

Every non-tree edge is between a node and its ancestor A DFS run Every non-tree edge is between a node and its ancestor DFS(u) u is explored For every unexplored neighbor v of u DFS(v) 1 1 7 2 2 3 8 4 4 5 Note that the tree is arbitrary based on which neighbor was visited first. 5 DFS tree 6 6 3 8 7

Questions?

Connected components are disjoint Either Connected components of s and t are the same or are disjoint Algorithm to compute ALL the connected components? Run BFS on some node s. Then run BFS on t that is not connected to s

Reading Assignment Sec 3.2 in [KT]

Rest of today’s agenda Run-time analysis of BFS (DFS)

Stacks and Queues Last in First out First in First out We will need to keep track of visited nodes during our traversals. First in First out

But first… How do we represent graphs? When using an algorithm to solve a problem, the runtime depends on how data is organized.

Graph representations 1 Better for sparse graphs and traversals Adjacency matrix Adjacency List (u,v) in E? O(1) O(n) [ O(nv) ] All neighbors of u? O(n) O(nu) O(n2) Space? O(m+n)

Questions?

2m = Σ u in V nu Rest of the graph Give 2 pennies to each edge   2m = Σ u in V nu Rest of the graph Give 2 pennies to each edge Total # of pennies = 2m nv=3 u nu=4 v Each edges gives one penny to its end points # of pennies u receives = nu

Breadth First Search (BFS) Build layers of vertices connected to s L0 = {s} Assume L0,..,Lj have been constructed Lj+1 set of vertices not chosen yet but are connected to Lj Use CC[v] array Stop when new layer is empty Use linked lists

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