Change in Schedule. I'm changing the schedule around a bit...

Similar documents
Introduction to Graphs. CS2110, Spring 2011 Cornell University

Synonyms. Hostile. Chilly. Direct. Sharp

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

Friday Four Square! 4:15PM, Outside Gates

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

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

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

CS106X Final Review. Rachel Gardner and Jared Bitz. slides adapted from Ashley Taylor, Anton Apostolatos, Nolan Handali, and Zachary Birnholz

CSE 373 NOVEMBER 20 TH TOPOLOGICAL SORT

csci 210: Data Structures Graph Traversals

CISC 3130 Data Structures Spring 2018

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 25: Review and Open Problems

Graphs & Digraphs Tuesday, November 06, 2007

CSE 373: Data Structures and Algorithms

(Refer Slide Time: 05:25)

CSE 100: GRAPH SEARCH

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

LECTURE 17 GRAPH TRAVERSALS

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

CSC2100-Data Structures

CSE 100: GRAPH ALGORITHMS

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

Spanning Trees. Lecture 22 CS2110 Spring 2017

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.

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

CS2013 Course Syllabus Spring 2017 Lecture: Friday 8:00 A.M. 9:40 A.M. Lab: Friday 9:40 A.M. 12:00 Noon


Binary Trees

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

Teach A level Compu/ng: Algorithms and Data Structures

Outline. Graphs. Divide and Conquer.

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we

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

Synonyms. Hostile. Chilly. Direct. Sharp

Lecture 3: Graphs and flows

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

Lecture 27: Learning from relational data

Graphs Introduction and Depth first algorithm

Minimum Spanning Trees

CS302 Data Structures using C++

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

9/17/2015 7:56 AM. CSCE 625 Programing Assignment #1 due: Tues, Sep 22 (by start of class) Objective

CS503 Advanced Programming I CS305 Computer Algorithms I

CS 310 Advanced Data Structures and Algorithms

12 Abstract Data Types

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

GRAPHS Lecture 19 CS2110 Spring 2013

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

CISC 3130 Data Structures Fall 2018

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

Search Slide 1/28. Search. Fall Semester. Artificial Intelligence

Trees Algorhyme by Radia Perlman

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

Course Review for Finals. Cpt S 223 Fall 2008

AP Computer Science 4325

COMP251: Algorithms and Data Structures. Jérôme Waldispühl School of Computer Science McGill University

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

Graphs - II CS 2110, Spring 2016

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

For a printable form of this assignment: assignment3.pdf. Assignment 3: Binary trees

CS 206 Introduction to Computer Science II

Graphs - II. Announcements. Where did I leave that book? Where did I leave that book? Where did I leave that book? CS 2110, Fall 2016

Homework Assignment #3 Graph

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131

Introduction to Data Structures

* Due 11:59pm on Sunday 10/4 for Monday lab and Tuesday 10/6 Wednesday Lab

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

CS 206 Introduction to Computer Science II

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

Announcements. Assignment 6 due right now. Assignment 7 (FacePamphlet) out, due next Friday, March 16 at 3:15PM

Friday, March 30. Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.

Course Review. Cpt S 223 Fall 2009

Algorithms: Lecture 10. Chalmers University of Technology

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

(Refer Slide Time: 02.06)

Course Name: B.Tech. 3 th Sem. No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours. Planned.

Computer Science 1 Study Union Practice Problems. What are the arguments to malloc? calloc? realloc? What do they do?

Announcements. Homework 1: Search. Project 1: Search. Midterm date and time has been set:

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

CMSC132, Practice Questions

Lecture 26: Graphs: Traversal (Part 1)

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

Lecture 9 Graph Traversal

BOSTON UNIVERSITY Metropolitan College MET CS342 Data Structures with Java Dr. V.Shtern (Fall 2011) Course Syllabus

The goal of this assignment is to implement and test Breadth-first search (BFS) on a simple navigation problem (path-finding).

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

Data Structure Advanced

York University AK/ITEC INTRODUCTION TO DATA STRUCTURES. Final Sample II. Examiner: S. Chen Duration: Three hours

Computer Science E-22 Practice Final Exam

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

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

CS2013 Course Syllabus Spring 2018 Lecture: Mon/Wed 2:00 P.M. 2:50 P.M. SH C259 Lab: Mon/Wed 2:50 P.M. 4:00 P.M. SH C259

CSE 373 Final Exam 3/14/06 Sample Solution

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

(Re)Introduction to Graphs and Some Algorithms

Breadth First Search. cse2011 section 13.3 of textbook

Transcription:

Graphs

Announcements() {

Change in Schedule I'm changing the schedule around a bit... Today: Graphs Tuesday: Shortest Path Algorithms Wednesday: Minimum Spanning Trees Tursday: Review Session for Midterm II

Final Final: Monday, August 12th, 7-10pm Location: Cubberly Auditorium Cumulative (but weighted towards post midterm material) Covers material up through Tuesday SCPD students and students who require special arrangements should email me in the next couple days We do the final early so we have time to grade it, get it back to you and resolve any grading issues.

} //Announcements

Data Structures Cheat Sheet Vector, Stack: dynamic array Queue: linked list or dynamic array Set, Map: Binary Search Tree HashSet, HashMap: Hash Table Lexicon: Trie

Graphs

A Social Network

http://strangemaps.files.wordpress.com/2007/02/fullinterstatemap-web.jpg

http://www.toothpastefordinner.com/

A graph is a mathematical structure for representing relationships.

A graph is a mathematical structure for representing relationships. A graph consists of a set of nodes connected by edges.

A graph is a mathematical structure for representing relationships. A graph consists of a set of nodes connected by edges.

A graph is a mathematical structure for representing relationships. A graph consists of a set of nodes connected by edges.

A graph is a mathematical structure for representing relationships. Nodes A graph consists of a set of nodes connected by edges.

A graph is a mathematical structure for representing relationships. Edges A graph consists of a set of nodes connected by edges.

Some graphs are directed.

Some graphs are undirected. CAN MAN RAN MAT CAT SAT RAT

Some graphs are undirected. CAN MAN RAN MAT CAT SAT RAT You can think of them as directed graphs with edges both ways.

Graphs Yo Teach, why are we studying graphs? We study graphs because a lot of problems can be modeled in terms of graphs Also, there are many off-the-shelf graph algorithms that we apply if we're able to formulate a problem as a graph problem.

Pathfinding Each intersection is a node Each street connecting intersections is an edge Find paths between intersections that minimize distance or travel time

Content-Aware Resizing

Content-Aware Resizing Each pixel is a node in a graph Each pixel is connected to adjacent pixels Find paths from the top of the image to the bottom that minimize the energy function

The Wikipedia Graph Wikipedia (and the web in general) is a graph! Each page is a node. There is an edge from one page to another if the first page links to the second.

Social Networks and Epidemics http://3278as3udzze1hdk0f2th5nf18c1.wpengine.netdna-cdn.com/wp-content/uploads/2010/09/social-networks-new-science1.jpg https://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&docid=mpb6juye9sdbdm&tbnid=vwbn0bttg7-zwm:&ved=0cauqjrw&url=http%3a%2f%2fblogs.cornell.edu %2Finfo2040%2F2011%2F09%2F17%2Fhow-network-structure-can-provide-advanced-warning-about-epidemics %2F&ei=rrP9Ufa8G6n0iwK9q4CoBQ&bvm=bv.50165853,d.cGE&psig=AFQjCNHljXC1ZggH6hQDrKxPM1CV7ocVXQ&ust=1375667391653650

How can we represent graphs in C++?

Representing Graphs We Wecan canrepresent representaagraph graphas as aamap mapfrom fromnodes nodesto tothe thelist list of ofnodes nodeseach eachnode nodeisis connected connectedto. to. Map<Node*, Vector<Node*>> Node* Vector<Node*> Node Connected To

What interesting things can we do with graphs?

Connected Components A connected component is a subset of the nodes in a graph such that: For every pair of nodes in the subset there exists a path between them No node in the subset is not connected any node not in the subset

Connected Components 1 Connected Component

Connected Components 2 Connected Components

Connected Components 3 Connected Components

Connected Components 6 Connected Components

Connected Components Detecting connected components in a graph is important because it can provide useful insights into the structure of graph e.g. How do people in a community separate themselves into separate groups. In order to detect connected components we first need to be able to iterate over nodes in a graph. We'll come back to connected components later.

Iterating over a Graph Given a linked list, there was just one way to traverse the list. Keep going forward. In a binary search tree, there are many traversal strategies: An inorder traversal that produces all the elements in sorted order. A postorder traversal used to delete all the nodes in the BST. There are many ways to iterate over a graph.

Iterating over a Graph All methods of iterating over a graph involve keeping track of 3 sets of nodes: Set of Nodes already visited Set of Nodes to look at next Everything else

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph

Iterating over a Graph All methods of iterating over a graph involve keeping track of 3 sets of nodes: Set of Nodes already visited Set of Nodes to look at next Everything else Methods of iterating over nodes differ in how they choose which node to look at next

Recursive Depth First Search To detect connected components we just want to see whether or not some path exists between them (we don't care about finding the shortest path). One way to detect connectivity would be to just pick an arbitrary direction and keep following it. When you run out of room to go in one direction, just go back and look in a different direction

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search

Recursive Depth-First Search To do a depth-first search (DFS) from a node u, do the following: If u is already marked, stop. Mark u. For each neighbor v of u: Recursively run DFS from v. The backtracking here is similar to the backtracking done in standard recursion.

Iterative Depth-First Search DFS is most commonly implemented iteratively using a Stack

Depth-first search A B C D E F

Depth-first search A B C D E F Set Stack

Depth-first search A B C D E F A Set Stack

Depth-first search A B C D E F Set Stack

Depth-first search A B C D E F Set A Stack

Depth-first search A B C D E F E B Set A Stack

Depth-first search A B C D E F E B Set A Stack

Depth-first search A B C D E F B Set A Stack

Depth-first search A B C D E F E Set A B Stack

Depth-first search A B C D E F C F E Set A D B Stack

Depth-first search A B C D E F C F E Set A D B Stack

Depth-first search A B C D E F F E Set A D B Stack

Depth-first search A B C D E F F D E B Set A Stack C

Depth-first search A B C D E F B F D E B Set A Stack C

Depth-first search A B C D E F B F D E B Set A Stack C

Depth-first search A B C D E F B F D E B Set A Stack C

Depth-first search A B C D E F F D E B Set A Stack C

Depth-first search A B C D E F F D E B Set A B Stack C

Depth-first search A B C D E F F D E B Set A B Stack C

Depth-first search A B C D E F D E B Set A B Stack C

Depth-first search A B C D E F E D F Set A B B Stack C

Depth-first search A B C D E F E D F Set A B B Stack C

Depth-first search A B C D E F E F Set A B B Stack C

Depth-first search A B C D E F D E F Set A B B Stack C

Depth-first search A B C D E F D E F Set A B B Stack C

Depth-first search A B C D E F D E F Set A B Stack C

Coding Depth-First Search

DFS and Connected Components Detecting connected components becomes relatively straightforward once we have Depth First Search. Not going to code it up, but I encourage you to!

Problems with DFS Useful when trying to explore everything. Not good at finding shortest paths.

Problems with DFS Useful when trying to explore everything. Not good at finding shortest paths. Stack

Problems with DFS Useful when trying to explore everything. Not good at finding shortest paths. A B Stack

Problems with DFS Useful when trying to explore everything. Not good at finding shortest paths. A B A B Stack

Breadth-First Search

1 1 1 1

2 2 1 2 2 1 2 1 1 2

2 2 1 2 2 1 2 1 1 2

Breadth-First Search Specialization of the general search algorithm where nodes to visit are put into a queue. Explores nodes one hop away, then two hops away, etc. Finds path with fewest edges from start node to all other nodes.

Note: The following animation has been simplified for pedagogic purposes. In reality there would be a Set keeping track of visited nodes and redundant adds to the Queue

Breadth-first search A B C D E F

Breadth-first search Queue A B C D E F

Breadth-first search Queue A A B C D E F

Breadth-first search Queue A B C D E F

Breadth-first search Queue B A B C D E F E

Breadth-first search Queue B A B C D E F E

Breadth-first search Queue E A B C D E F

Breadth-first search Queue E A B C D E F C

Breadth-first search Queue E A B C D E F C

Breadth-first search Queue A B C D E F C

Breadth-first search Queue A B C D E F C D F

Breadth-first search Queue A B C D E F C D F

Breadth-first search Queue D A B C D E F F

Breadth-first search Queue D A B C D E F F

Breadth-first search Queue F A B C D E F

Breadth-first search Queue F A B C D E F

Breadth-first search Queue A B C D E F

Breadth-first search Queue A B C D E F

Coding Breadth-First Search

CAN MAN RAN MAT CAT SAT RAT

CAN MAN RAN MAT CAT SAT RAT

CAN MAN RAN MAT CAT SAT RAT

CAN MAN RAN MAT CAT SAT RAT

CAN MAN RAN MAT CAT SAT RAT

CAN CAT RAN

Next Time Shortest Paths Dijkstra's Algorithm. A* Search.