CS 241 Analysis of Algorithms

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

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

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

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

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

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

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

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

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

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

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

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

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

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

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

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

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

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

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

COMP108 Algorithmic Foundations

Section 10.4 Connectivity (up to paths and isomorphism, not including)

Announcements. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

Problem solving by search

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

Announcements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms

Planar Upward Drawings

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

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

Round 7: Graphs (part I)

CMSC 451: Lecture 2 Graph Basics Thursday, Aug 31, 2017

Constructive Geometric Constraint Solving

ECE 407 Computer Aided Design for Electronic Systems. Circuit Modeling and Basic Graph Concepts/Algorithms. Instructor: Maria K. Michael.

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

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

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

0.1. Exercise 1: the distances between four points in a graph

Graphs and Graph Searches

N=4 L=4. Our first non-linear data structure! A graph G consists of two sets G = {V, E} A set of V vertices, or nodes f

The University of Sydney MATH2969/2069. Graph Theory Tutorial 5 (Week 12) Solutions 2008

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

12. Traffic engineering

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

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

1. Determine whether or not the following binary relations are equivalence relations. Be sure to justify your answers.

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

Lecture 20: Minimum Spanning Trees (CLRS 23)

10/30/12. Today. CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James. DFS algorithm. Reachability Algorithms

Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

Present state Next state Q + M N

Scientific Programming. Graphs

QUESTIONS BEGIN HERE!

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

Solutions to Homework 5

CS September 2018

QUESTIONS BEGIN HERE!

1 Introduction to Modulo 7 Arithmetic

CSI35 Chapter 11 Review

NP-Completeness. CS3230 (Algorithm) Traveling Salesperson Problem. What s the Big Deal? Given a Problem. What s the Big Deal? What s the Big Deal?

Minimum Spanning Trees

Graph Theory. Vertices. Vertices are also known as nodes, points and (in social networks) as actors, agents or players.

Numbering Boundary Nodes

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

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

Multipoint Alternate Marking method for passive and hybrid performance monitoring

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

CS 103 BFS Alorithm. Mark Redekopp

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

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

Seven-Segment Display Driver

Outline. Binary Tree

Trees as operads. Lecture A formalism of trees

Plan. I Gale-Shapley Running Time. I Graphs. I Motivation and definitions I Graph traversal: BFS and DFS

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

CS553 Lecture Register Allocation 1

EE1000 Project 4 Digital Volt Meter

Chapter 18. Minimum Spanning Trees Minimum Spanning Trees. a d. a d. a d. f c

Nefertiti. Echoes of. Regal components evoke visions of the past MULTIPLE STITCHES. designed by Helena Tang-Lim

CS553 Lecture Register Allocation I 3

Graph Contraction and Connectivity

A 4-state solution to the Firing Squad Synchronization Problem based on hybrid rule 60 and 102 cellular automata

Preview. Graph. Graph. Graph. Graph Representation. Graph Representation 12/3/2018. Graph Graph Representation Graph Search Algorithms

(Minimum) Spanning Trees

S i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.

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

Garnir Polynomial and their Properties

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

(a) v 1. v a. v i. v s. (b)

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

Section 3: Antiderivatives of Formulas

Organization. Dominators. Control-flow graphs 8/30/2010. Dominators, control-dependence. Dominator relation of CFGs

XML and Databases. Outline. Recall: Top-Down Evaluation of Simple Paths. Recall: Top-Down Evaluation of Simple Paths. Sebastian Maneth NICTA and UNSW

14 Shortest Paths (November 8)

Analysis of Algorithms - Elementary graphs algorithms -

Transcription:

CS 241 Anlysis o Algorithms Prossor Eri Aron Ltur T Th 9:00m Ltur Mting Lotion: OLB 205 Businss HW6 u lry HW7 out tr Thnksgiving Ring: Ch. 22.1-22.3 1

Grphs (S S. B.4) Grphs ommonly rprsnt onntions mong rlt lmnts An unirt grph G = (V,E) is A st V o vrtis (nos), n A st E o gs (link pirs o nos), whih r iirtionl A irt grph (or igrph) G = (V,E) is A st V o vrtis (nos), n () Dirt grph () Unirt grph () Sugrph o () inu y vrtx st {1,2,3,6} So, in unirt grphs, gs r unorr pirs o vrtis, whrs in igrphs, gs r orr pirs. By onvntion, in n unirt grph G = (V,E), w onsir (u,v) n (v,u) to th sm g, so t most on o thos pirs will in E. A st E o uniirtionl gs (typilly rprsnt s rrows). Not tht sl-loops gs rom no to itsl r possil Convntions: For lgorithm nlysis, w my us V or V n E or E V is otn rrr to y n n E y m Grph Voulry Now showing on PBS: Mr. Rogrs, Grph Thortiin Lots o voulry: I = (u,v) \in E, thn is inint on oth u n v I = (u,v) \in E, thn v is jnt to u. Ajnt vrtis r nighors Th gr o vrtx is th numr o gs inint on it In igrphs, h vrtx hs n in-gr (th numr o gs pointing in to it) n n out-gr (th numr o gs pointing out rom it) A pth o lngth k rom vrtx u to vrtx u' is squn (v 0, v 1,..., v k ) o vrtis suh tht u = v 0, u' = v k n thr is n g twn h v i, i = 1,2,...,k. In igrph, pth xists twn vrtis n only i thr is squn o outgoing gs rom to A simpl pth is pth with ll istint vrtis I thr is pth p twn vrtis u n v, w sy v is rhl rom u vi p Importnt Thnil Osrvtion: I w r gonn tlk out grphs, w n wors or grph stu othrwis, it s rlly hr to tlk out. 2

Mor Grph Voulry So w n tlk out mor grphs! Grphs with th sm numr o vrtis n hv irnt numrs o gs. Wht s th most gs grph n hv, in trms o n? A sprs grph is on in whih E is muh lss thn V 2 A ns grph is on in whih E is los to V 2 (S CLRS, pg. 589) In igrph, pth (v 0, v 1,..., v k ) orms yl i v 0 = v k n th pth ontins t lst on g A yl is simpl i v 1, v 2,..., v k r istint. (Why not inlu v 0 in this?) g h A irt grph with no yls is irt yli grph, or DAG (R CLRS S. 22.1-22.3) Ajny List Rprsnttions A grph n rprsnt s n jny list For h vrtx v, thr s list o ll nos jnt to v Rprsnt s n rry o V == n lists Complxity: Storg sp: O(V + E) Exmpl: An unirt grph (For wht kins o grphs is this n iint storg rprsnttion?) Wht s th tim omplxity to in i n g is in grph? 3

Ajny List Rprsnttions A grph n rprsnt s n jny list For h vrtx v, thr s list o ll nos jnt to v Rprsnt s n rry o V == n lists Exmpl: igrph Ajny Mtrix Rprsnttions A grph oul lso rprsnt s n jny mtrix A V-y-V mtrix : For h pir (i,j) o vrtis, ntry (i,j) in th mtrix is 1 i (i,j) \in E, n 0 othrwis Complxity: Storg sp: O(V 2 ) g Exmpl: An unirt grph Thr is no spoon nxt to nything rom Th Ajny Mtrix 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 1 0 0 1 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 (For wht kins o grphs is this n iint storg rprsnttion?) Wht s th tim omplxity to in i n g is in grph? g g Rll: For igrphs, only outgoing gs r in E (thus in th mtrix) 4

Brth-First Srh (BFS) n Dpth-First Srh (DFS) Two ommon lgorithms or srhing (or trvrsing) grph Brth-First Srh: inormlly, isovr ll nos rhl within k stps (i.., gs) or isovring ny with k+1 stps Cn thought o s FIFO, or irst-sn, irst-isovr Dpth-First Srh: inormlly, isovring ll nos own on pth or xploring ny othr pth Cn thought o s LIFO, or most rntly sn, irstisovr Brth-First Srh (BFS) BFS: Mintins quu Q to mng vrtis; strts with sour vrtx s Initilly, ll vrtis xpt s r olor whit, n s is gry. BFS lgorithm mintins inormtion or h vrtx u: - u.olor (whit, gry, or lk) : inits sttus whit = not isovr yt gry = isovr, ut not inish lk = inish - u. : istn rom s to u; initilly or ll ut s=0 - u.π : prssor o u in BF tr Fins ll vrtis v rhl rom s y uiling rth-irst tr, whr th pth in th tr rom s to v hs th wst numr o gs o ll pths rom s to v 5

Brth-First Srh (BFS) Psuoo or BFS: Enquu(Q,s) s s to th rr o Q Dquu(Q) rmovs n rturns th itm t th h o Q Not: I G is not onnt, thn BFS will not visit th ntir grph (without som xtr provisions) Tim omplxity o BFS With j list rprsnttion? With j mtrix rprsnttion? BFS (G, s) 1. Enquu (Q,s) 2. whil Q 3. u = Dquu(Q) 4. or h v jnt to u 5. i v.olor == whit 6. v.olor = gry 7. v. = u. + 1 8. v.π = u 9. Enquu(Q,v) 10. u.olor = lk Dpth-First Srh (DFS) DFS grph xplortion: ollows gs out o most rntly isovr vrtx v tht still hs unxplor gs. Whn ll o v s gs r xplor, DFS ktrks to xplor gs inint on th vrtx rom whih v ws isovr Whn no u is irst isovr uring DFS, it is tim-stmp with isovry tim u. Whn ll u s jnt nos hv n visit, (long with ll th nos rhl rom u tht r whit), u is tim-stmp with inishing tim u. Explors nos s i mintining stk o visit nos Rsults in spnning tr o G i.., tr ompos o ll th nos o G n som (prhps ll) o th gs o G 6

Dpth-First Srh (DFS) DFS grph xplortion: ollows gs out o most rntly isovr vrtx v tht still hs unxplor gs. Whn ll o v s gs r xplor, DFS ktrks to xplor gs inint on th vrtx rom whih v ws isovr DFS mintins th ollowing inormtion or h vrtx u: - u.olor (whit, gry, or lk) : inits sttus whit = not isovr yt gry = isovr, ut not inish lk = inish - u. : isovry tim o no u - u. : inishing tim o no u - u.π : prssor o u in D-F tr Initilly, u.olor=whit, with u.= u.=, u.π = NIL or ll u, n tim = 0 Dpth-First Srh (DFS) Psuoo or rursiv DFS: Itrtiv vrsion oul us stk Nots: I G is not onnt, DFS will still visit th ntir grph Atr xution, or h vrtx u, u. < u. (s xpt!) No no will inish until ll its snnts r inish (s xpt!) Tim omplxity o DFS With j list rprsnttion? With j mtrix rprsnttion? DFS (G) 1. or h v G 2. i v.olor == whit 3. DFS-Visit (G,v) DFS-Visit (G,u) 1. u.olor = gry 2. u. = tim 3. tim = tim + 1 4. or h v jnt to u 5. i v.olor == whit 6. v.π = u 7. DFS-Visit(G,v) 8. u.olor = lk 9. u. = tim 10. tim = tim + 1 7

Wight Grphs n Shortst Pths oul th lum titl or ollortion twn xk n Dth C For Cuti. Wight Grphs n Shortst Pths Wll, it oul. Grphs n wight: Givn G=(V,E), thr is wight untion w tht mps h g in E to rl-vlu wight For wight grphs, n jny mtrix n stor th wight o n g in E (rthr thn just 0 or 1) Givn suh w, w sy th wight o pth w(p) or p = <v 0, v 1,, v k > is th sum o th wights o th gs on tht pth (i.., (v 0, v 1 ), (v 1, v 2 ), (v k-1, v k )) W thn sy th shortst pth wightδ(u,v) rom vrtx u to vrtx v is th lst wight o ny pth in G rom u to v A shortst pth rom u to v is ny pth rom u to v in G with tht wight Shortst Pth Prolms Kins o grph prolms s on ining shortst pths (y onvntion, prsum wight, irt grphs): Singl-sour shortst pths Vrious lgorithms or ss o it (Bllmn-For, Dijkstr) Singl-stintion shortst pths I w hv singl-sour shortst pths lgorithm, how oul w solv this? Singl-pir shortst pth How os this rlt to th singl-sour vrint? All-pirs shortst pths W ll tlk mor out this soon (Not: To rprsnt (shortst) pth in solving suh prolm, h vrtx is prsum to hv prssor il, whih stors its prssor on th pth ing onsir.) 8