COMP 250. Lecture 29. graph traversal. Nov. 15/16, 2017

Similar documents
CMPS 2200 Fall Graphs. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

Spanning Trees. BFS, DFS spanning tree Minimum spanning tree. March 28, 2018 Cinda Heeren / Geoffrey Tien 1

(Minimum) Spanning Trees

Depth First Search. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

Lecture 20: Minimum Spanning Trees (CLRS 23)

Graph Search (6A) Young Won Lim 5/18/18

Strongly connected components. Finding strongly-connected components

Applications of trees

5/1/2018. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees

Weighted Graphs. Weighted graphs may be either directed or undirected.

Improving Union. Implementation. Union-by-size Code. Union-by-Size Find Analysis. Path Compression! Improving Find find(e)

Theorem 1. An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.

CSE 332. Data Structures and Parallelism

CSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2

The University of Sydney MATH 2009

Divided. diamonds. Mimic the look of facets in a bracelet that s deceptively deep RIGHT-ANGLE WEAVE. designed by Peggy Brinkman Matteliano

4.1 Interval Scheduling. Chapter 4. Greedy Algorithms. Interval Scheduling: Greedy Algorithms. Interval Scheduling. Interval scheduling.

CS 103 BFS Alorithm. Mark Redekopp

Planar convex hulls (I)

CMSC 451: Lecture 4 Bridges and 2-Edge Connectivity Thursday, Sep 7, 2017

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

learning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms

DOCUMENT STATUS: RELEASE

In which direction do compass needles always align? Why?

Single Source Shortest Paths (with Positive Weights)

Graphs Breadth First Search

Priority Search Trees - Part I

SAMPLE CSc 340 EXAM QUESTIONS WITH SOLUTIONS: part 2

Minimum Spanning Trees (CLRS 23)

L.3922 M.C. L.3922 M.C. L.2996 M.C. L.3909 M.C. L.5632 M.C. L M.C. L.5632 M.C. L M.C. DRIVE STAR NORTH STAR NORTH NORTH DRIVE

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

CSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2

On Hamiltonian Tetrahedralizations Of Convex Polyhedra

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

MINI POST SERIES BALUSTRADE SYSTEM INSTALLATION GUIDE PRODUCT CODE: MPS-RP

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

Solutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1

MATERIAL SEE BOM ANGLES = 2 FINISH N/A

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

Lecture II: Minimium Spanning Tree Algorithms

2 Trees and Their Applications

DOCUMENT STATUS: CORE HEALTH & FITNESS, LLC IL-D2002-XXAAX IP,DUAL ADJUSTIBLE PULLEY MATERIAL SEE BOM FINISH N/A N/A SHEET SIZE: B SCALE: 1:33.

MAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017

ADORO TE DEVOTE (Godhead Here in Hiding) te, stus bat mas, la te. in so non mor Je nunc. la in. tis. ne, su a. tum. tas: tur: tas: or: ni, ne, o:

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

CS September 2018

Computer Graphics. Viewing & Projections

Functions and Graphs 1. (a) (b) (c) (f) (e) (d) 2. (a) (b) (c) (d)

CS 461, Lecture 17. Today s Outline. Example Run

I N A C O M P L E X W O R L D

Grade 7/8 Math Circles March 4/5, Graph Theory I- Solutions

CS 241 Analysis of Algorithms

d e c b a d c b a d e c b a a c a d c c e b

CSCI 104 Graph Representation and Traversals. Mark Redekopp David Kempe

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

Acogemos, Señor, Tu Mensaje De Amor/ Embrace And Echo Your Word

( ) ( ) ( ) 0. Conservation of Energy & Poynting Theorem. From Maxwell s equations we have. M t. From above it can be shown (HW)

7 ACM FOR FRAME 2SET 6 FRAME 2SET 5 ACM FOR MAIN FRAME 2SET 4 MAIN FRAME 2SET 3 POLE ASSLY 1 2 CROWN STRUCTURE ASSLY 1 1 CROWN ASSLY 1

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS


Planar Upward Drawings

Face Detection and Recognition. Linear Algebra and Face Recognition. Face Recognition. Face Recognition. Dimension reduction

Closed Monochromatic Bishops Tours

Graphs Depth First Search

Math 166 Week in Review 2 Sections 1.1b, 1.2, 1.3, & 1.4

Having a glimpse of some of the possibilities for solutions of linear systems, we move to methods of finding these solutions. The basic idea we shall

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

Graph Search Algorithms

OpenMx Matrices and Operators

MATERIAL SEE BOM ANGLES = 2 > 2000 DATE MEDIUM FINISH

DOCUMENT STATUS: LA-S5302-XXXXS LA, SSS, TRICEPS EXTENSION VERY

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

P a g e 5 1 of R e p o r t P B 4 / 0 9

Platform Controls. 1-1 Joystick Controllers. Boom Up/Down Controller Adjustments

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

Minimum Spanning Trees

17 Basic Graph Properties

Maximum Matching Width: new characterizations and a fast algorithm for dominating set

Proc. of the 23rd Intl. Conf. on Parallel Processing, St. Charles, Illinois, August 1994, vol. 3, pp. 227{ Hanan Samet

CHELOURANYAN CALENDAR FOR YEAR 3335 YEAR OF SAI RHAVË

CLKOUT CLKOUT VCC CLKOUT RESOUT OSCOUT ALE TEST AD0 66 AD2 INT0 INT0 AD INT1 AD INT2/INTA0 AD5 AD7 AD7 INT AD8 AD8 AD10

ELECTRONIC SUPPLEMENTARY INFORMATION

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

Minimum Spanning Trees (CLRS 23)

EE1000 Project 4 Digital Volt Meter

CSI35 Chapter 11 Review

Dental PBRN Study: Reasons for replacement or repair of dental restorations

minimize c'x subject to subject to subject to

SAMPLE LITANY OF THE SAINTS E/G. Dadd9/F. Aadd9. cy. Christ, have. Lord, have mer cy. Christ, have A/E. Dadd9. Aadd9/C Bm E. 1. Ma ry and. mer cy.

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

QUESTIONS BEGIN HERE!

Transcription:

COMP 250 Ltur 29 rp trvrsl Nov. 15/16, 2017 1

Toy Rursv rp trvrsl pt rst Non-rursv rp trvrsl pt rst rt rst 2

Hs up! Tr wr w mstks n t sls or S. 001 or toy s ltur. So you r ollown t ltur rorns n usn ts (orrt) sls, tn you wll not som rns. 3

Rll: tr trvrsl (rursv) ptrst Tr (root){ (root s not mpty){ root.vst = tru // prorr or l o root ptrst Tr( l ) 4

Grp trvrsl (rursv) N to spy strtn vrtx. Vst ll nos tt r rl y pt rom strtn vrtx. 5

Grp trvrsl (rursv) ptfrst_grp(v){ v.vst = tru or w su tt (v,w) s n E // w n v.jlst? // Hr vstn just mns rn 6

Grp trvrsl (rursv) ptfrst_grp(v){ v.vst = tru or w su tt (v,w) s n E // w n v.jlst! (w.vst) // vos yls ptfrst_grp(w) // Hr vstn just mns rn 7

Cll Stk or ptfrst() ptfrst_grp(v){ v.vst = tru or w su tt (v,w) s n E! (w.vst) ptfrst_grp(w) 8

Cll Stk or ptfrst() ptfrst_grp(v){ v.vst = tru or w su tt (v,w) s n E! (w.vst) ptfrst_grp(w) 9

Cll Stk or ptfrst() ptfrst_grp(v){ v.vst = tru or w su tt (v,w) s n E! (w.vst) ptfrst_grp(w) 10

Cll Stk or ptfrst() ptfrst_grp(v){ v.vst = tru or w su tt (v,w) s n E! (w.vst) ptfrst_grp(w) 11

Cll Stk or ptfrst() ptfrst_grp(v){ v.vst = tru or w su tt (v,w) s n E! (w.vst) ptfrst_grp(w) 12

root Cll Tr 13

Exmpl 2 Wt s t ll tr or ptfrst( )? Ajny Lst - (,) - (,,) - (,) - (,,) - (,,,) - (,,) - (,) - (,,) - (,) 14

Exmpl 2 ll tr or ptfrst() 15

Q: Non-rursv rp trvrsl? A: Smlr to tr trvrsl: Us stk or quu. 16

Rll: pt rst tr trvrsl (wt slt vrton) trtrvrslusnstk(root){ ntlz mpty stk s vst root s.pus(root) wl s s not mpty { ur = s.pop() or l o ur{ vst l s.pus(l) Vst no or pusn t onto t stk. Evry no n t tr ts vst, pus, n tn popp. 17

Gnrlz to rps rptrvrslusnstk(v){ ntlz mpty stk s v.vst = tru s.pus(v) wl (!s.mpty) { u = s.pop() or w n u.jlst{ (!w.vst){ w.vst = tru s.pus(w) // t only nw prt 18

Exmpl: rptrvrslusnstk() 19

Exmpl: rptrvrslusnstk() T trvrsl ns tr, ut t s not ll tr. Wy not? s popp n ot n r pus. 20

Exmpl: rptrvrslusnstk() s popp n ot n r pus. 21

Exmpl: rptrvrslusnstk() s popp n s pus. 22

Exmpl: rptrvrslusnstk() s popp n s pus. 23

Exmpl: rptrvrslusnstk() s popp n s pus. 24

Exmpl: rptrvrslusnstk() s popp n s pus. 25

Exmpl: rptrvrslusnstk() Orr o nos vst: 26

Rll: rt rst tr trvrsl (s ltur 20) or lvl vst ll nos t lvl trtrvrslusnquu(root){ ntlz mpty quu q q.nquu(root) wl q s not mpty { ur = q.quu() vst ur or l o ur q.nquu(l) j k 27

Brt rst rp trvrsl Gvn n nput vrtx, n ll vrts tt n r y pts o lnt 1, 2, 3, 4,. 28

Brt rst rp trvrsl rptrvrslusnquu(v){ ntlz mpty quu q v.vst = tru q.nquu(v) wl (! q.mpty) { u = q.quu() or w n u.jlst{ (!w.vst){ w.vst = tru q.nquu(w) 29

Exmpl rptrvrslusnquu() quu 30

Exmpl rptrvrslusnquu() quu 31

Exmpl rptrvrslusnquu() quu Bot, r vst n nquu or s quu. 32

Exmpl rptrvrslusnquu() quu 33

rptrvrslusnquu() It ns tr wos root s t strtn vrtx. It ns t sortst pt (numr o vrts) to ll vrts rl rom strtn vrtx. 34

Exmpl: rptrvrslusnquu() 1 35

Exmpl: rptrvrslusnquu() 1 2 3 36

Exmpl: rptrvrslusnquu() 1 2 4 3 5 37

Exmpl: rptrvrslusnquu() 1 2 4 3 5 6 38

Exmpl: rptrvrslusnquu() 6 1 2 4 3 5 7 39

Exmpl: rptrvrslusnquu() 1 2 4 3 5 7 6 8 40

Exmpl: rptrvrslusnquu() 1 2 4 3 5 7 6 8 41

Exmpl: rptrvrslusnquu() 1 2 4 3 5 7 6 8 9 42

Exmpl: rptrvrslusnquu() 1 2 4 3 5 7 6 8 9 43

Exmpl: rptrvrslusnquu() T trvrsl ns tr, ut t s not ll tr. Wy not? 44

Rll: How to mplmnt Grp lss n Jv? lss Grp<T> { HsMp< Strn, Vrtx<T> > vrtxmp; lss Vrtx<T> { ArryLst<E> T ooln jlst; lmnt; vst; lss E { Vrtx oul : nvrtx; wt;

HEADS UP! Pror to trvrsl,. or w n V w.vst = ls How to mplmnt ts? 46

HEADS UP! Pror to trvrsl,. or w n V w.vst = ls How to mplmnt ts? lss Grp<T> { HsMp< Strn, Vrtx<T> > : pul vo rstvst() { vrtxmp; 47

HEADS UP! Pror to trvrsl,. or w n V w.vst = ls How to mplmnt ts? lss Grp<T> { HsMp< Strn, Vrtx<T> > vrtxmp; : pul vo rstvst() { or( Vrtx<T> v : vrtxmp.vlus() ){ v.vst = ls; [ASIDE: I somtn unnssrly omplt on t S.001 sls. Wt I v ov s ttr. ] 48