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

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

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

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

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

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

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

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

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

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

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

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

CS 241 Analysis of Algorithms

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

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

COMP108 Algorithmic Foundations

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

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

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

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

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

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

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

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

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

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

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

Planar Upward Drawings

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

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

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

Constructive Geometric Constraint Solving

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

12. Traffic engineering

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

Present state Next state Q + M N

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

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

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

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

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

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

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

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

1 Introduction to Modulo 7 Arithmetic

Minimum Spanning Trees

CS September 2018

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

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

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

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

Problem solving by search

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?

Multipoint Alternate Marking method for passive and hybrid performance monitoring

Chapter 9. Graphs. 9.1 Graphs

The Plan. Honey, I Shrunk the Data. Why Compress. Data Compression Concepts. Braille Example. Braille. x y xˆ

Seven-Segment Display Driver

CS 103 BFS Alorithm. Mark Redekopp

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

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

Register Allocation. How to assign variables to finitely many registers? What to do when it can t be done? How to do so efficiently?

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

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

Garnir Polynomial and their Properties

CS553 Lecture Register Allocation I 3

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

Walk Like a Mathematician Learning Task:

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

EE1000 Project 4 Digital Volt Meter

Scientific Programming. Graphs

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

QUESTIONS BEGIN HERE!

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

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

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

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

Trees as operads. Lecture A formalism of trees

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

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

Lecture 20: Minimum Spanning Trees (CLRS 23)

Instructions for Section 1

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

CSI35 Chapter 11 Review

QUESTIONS BEGIN HERE!

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

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

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

Outline. Binary Tree

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

Compression. Compression. Compression. This part of the course... Ifi, UiO Norsk Regnesentral Vårsemester 2005 Wolfgang Leister

Quartets and unrooted level-k networks

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

Section 3: Antiderivatives of Formulas

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

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

Jonathan Turner Exam 2-10/28/03

Solutions to Homework 5

CS553 Lecture Register Allocation 1

Decimals DECIMALS.

Transcription:

Grphs & Grph Algorithms Ltur CS Spring 6 Announmnts A6 rls toy: Risk Strt signing with your prtnr sp Prlim usy Not grphs hs r Grphs K 5 K, =...not th kin w mn, nywy Applitions o Grphs Communition ntworks Routing n shortst pth prolms Commoity istriution (low) ri ontrol Rsour llotion Gomtri moling... Grphs n us to rprsnt mny things Grph Dinitions A irt grph (or igrph) is pir (V,E) whr V is st E is st o orr pirs (u,v) whr u,v V Usully rquir u v (no sl-loops) An lmnt o V is ll vrtx (pl. vrtis) or no An lmnt o E is ll n g or r V = siz o V, otn not n E = siz o E, otn not m grph lgorithms hv mny pplitions

Exmpl Dirt Grph Exmpl Unirt Grph Exmpl: An unirt grph is just lik irt grph, xpt th gs r unorr pirs (sts) {u,v V = {,,,,, E = { (,), (,), (,), (,), (,), (,), (,), (,), (,), (,), (,) V = 6, E = Exmpl: V = {,,,,, E = { {,, {,, {,, {,, {,, {,, {,, {,, {,, {,, {, Som Grph rminology Mor Grph rminology Vrtis u n v r ll th sour n sink o th irt g (u,v), rsptivly Vrtis u n v r ll th npoints o (u,v) wo vrtis r jnt i thy r onnt y n g h outgr o vrtx u in irt grph is th numr o gs or whih u is th sour h ingr o vrtx v in irt grph is th numr o gs or whih v is th sink h gr o vrtx u in n unirt grph is th numr o gs o whih u is n npoint v v 5 A pth is squn v,v,v,...,v p o vrtis suh tht (v i,v i+ ) E, i p h lngth o pth is its numr o gs In this xmpl, th lngth is 5 A pth is simpl i it os not rpt ny vrtis A yl is pth v,v,v,...,v p suh tht v = v p A yl is simpl i it os not rpt ny vrtis xpt th irst n lst A grph is yli i it hs no yls A irt yli grph is ll g Is this g? Is this g? his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs

Is this g? Is this g? his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs Is this g? Is this g? his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs Is this g? Is this g? his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs

Is this g? opologil Sort Just omput topologil sort o th g A numring o th vrtis suh tht ll gs go rom lowr- to highr-numr vrtis his i ls to n lgorithm vrtis until th grph ispprs Dg is lik tr ut nos n hv multipl prnts : : : :4 : :5 4 A g: gnrliztion o tr w/ multipl prnts Usul in jo shuling with onstrints 5 Grph Coloring A oloring o n unirt grph is n ssignmnt o olor to h no suh tht no two jnt vrtis gt th sm olor Grph Coloring A oloring o n unirt grph is n ssignmnt o olor to h no suh tht no two jnt vrtis gt th sm olor How mny olors r n to olor this grph? How mny olors r n to olor this grph? An Applition o Coloring Vrtis r jos Eg (u,v) is prsnt i jos u n v h rquir ss to th sm shr rsour, n thus nnot xut simultnously Colors r tim slots to shul th jos Minimum numr o olors n to olor th grph = minimum numr o tim slots rquir Plnrity A grph is plnr i it n m in th pln with no gs rossing Is this grph plnr? 4

Plnrity A grph is plnr i it n m in th pln with no gs rossing Plnrity A grph is plnr i it n m in th pln with no gs rossing Is this grph plnr? Ys Is this grph plnr? Ys Dtting Plnrity Kurtowski's horm K 5 K, A grph is plnr i n only i it os not ontin opy o K 5 or K, (possily with othr nos long th gs shown) h Four-Color horm Evry plnr grph is 4-olorl (Appl & Hkn, 976) Biprtit Grphs A irt or unirt grph is iprtit i th vrtis n prtition into two sts suh tht ll gs go twn th two sts Cn rprsnt rltionship twn two sts,.g. is tking twn stunts n lsss Biprtit Grphs h ollowing r quivlnt G is iprtit G is -olorl G hs no yls o o lngth 5

rvling Slsprson Boston Ith Copnhgn 556 4 6 5 Nw York Lonon 89 6 Amstrm 78 Pris Wshington Munih 66 4 55 49 56 44 8 Rom Atlnt Fin pth o minimum istn tht visits vry ity Implmnting Digrphs Ajny Mtrix g[u][v] is tru i thr is n g rom u to v Ajny List h list or u ontins v i thr is n g rom u to v Implmnting Wight Digrphs Ajny Mtrix g[u][v] is i thr is n g o ost rom u to v 8 5 8 Ajny List h list or u ontins v, i thr is n g rom u to v tht hs ost 5 5 8 Implmnting Unirt Grphs Ajny Mtrix g[u][v] is tru i thr is n g rom u to v Ajny List h list or u ontins v i thr is n g rom u to v Ajny Mtrix or Ajny List? n = numr o vrtis m = numr o gs m u = numr o gs lving u Ajny Mtrix Uss sp O(n ) Cn itrt ovr ll gs in tim O(n ) Cn nswr Is thr n g rom u to v? in O() tim Bttr or ns (i.., lots o gs) grphs Ajny List Uss sp O(m+n) Cn itrt ovr ll gs in tim O(m+n) Cn nswr Is thr n g rom u to v? in O(m u ) tim Bttr or sprs (i.., wr gs) grphs Gol: Fin Shortst Pth in Grph Fining th shortst (min-ost) pth in grph is prolm tht ours otn Fin th lst-ost rout twn Ith n Dtroit Rsult pns on our notion o ost lst milg lst tim hpst lst oring All o ths osts n rprsnt s g osts on grph How o w in shortst pth? 6

S Shortst Pths or Unwight Grphs A B C D E F sdistn(s): // s is th strt vrtx // ist[v] is lngth o s-to-v pth // Initilly ist[v] = or ll v ist[s] = ; Q.insrt(s); whil (Q nonmpty) { v = Q.gt(); or (h w jnt to v) { i (ist[w] == ) { ist[w] = ist[v]+; Q.insrt(w); Anlysis or sdistn How mny tims n vrtx pl in th quu? How muh tim or th orloop? Dpns on rprsnttion Ajny Mtrix: O(n) Ajny List: O(m v ) im: O(n ) or j mtrix O(m+n) or j list sdistn(s): // s is th strt vrtx // ist[v] is lngth o s-to-v pth // Initilly ist[v] = or ll v ist[s] = ; Q.insrt(s); whil (Q nonmpty) { v = Q.gt(); or (h w jnt to v) { i (ist[w] == ) { ist[w] = ist[v]+; Q.insrt(w); I hr r Eg Costs? I # A ls nos so tht ll g osts r But wht i g osts r lrg? Wht i th osts rn t intgrs? I # Nothing intrsting hppns t th ls nos Cn t w just jump h to th nxt rl no Rul: lwys o th losst (rl) no irst Us th rry ist[ ] to Rport nswrs Kp trk o wht to o nxt Dijkstr s Algorithm Intuition Egs r thrs; vrtis r s Pik up t s; mrk h no s it lv th tl Not: Ngtiv g-osts r not llow S 5 A B 9 4 C D E F 9 s is th strt vrtx (i,j) is th ost rom i to j Initilly, vrtis r unmrk ist[v] is lngth o s-to-v pth Initilly, ist[v] =, or ll v ijsktr(s): ist[s] = ; whil (som vrtis r unmrk) { v = unmrk vrtx with smllst ist; Mrk v; or (h w j to v) { ist[w] = min ( ist[w], ist[v] + (v,w) ); Dijkstr s Algorithm using Aj Mtrix Dijkstr s Algorithm using Aj List Whil-loop is on n tims Within th loop Choosing v tks O(n) tim Coul o this str using PQ, ut no rson to For-loop tks O(n) tim otl tim = O(n ) s is th strt vrtx (i,j) is th ost rom i to j Initilly, vrtis r unmrk ist[v] is lngth o s-to-v pth Initilly, ist[v] =, or ll v ijsktr(s): ist[s] = ; whil (som vrtis r unmrk) { v = unmrk vrtx with smllst ist; Mrk v; or (h w j to v) { ist[w] = min ( ist[w], ist[v] + (v,w) ); Looks lik w n PQ Prolm: prioritis r upt s lgorithm runs Cn insrt pir (v,ist[v]) in PQ whnvr ist[v] is upt At most m things in PQ im O(n + m log m) Using mor omplit PQ (.g., Piring Hp), tim n rought own to O(m + n log n) s is th strt vrtx (i,j) is th ost rom i to j Initilly, vrtis r unmrk ist[v] is lngth o s-to-v pth Initilly, ist[v] =, or ll v ijsktr(s): ist[s] = ; whil (som vrtis r unmrk) { v = unmrk vrtx with smllst ist; Mrk v; or (h w j to v) { ist[w] = min ( ist[w], ist[v] + (v,w) ); 7

Dijkstr s Algorithm or Digrphs Gry Algorithms Algorithm works on oth unirt n irt grphs without moiition As or: Ngtiv g-osts r not llow S 5 A B 9 4 C D E F 9 s is th strt vrtx (i,j) is th ost rom i to j Initilly, vrtis r unmrk ist[v] is lngth o s-to-v pth Initilly, ist[v] =, or ll v ijsktr(s): ist[s] = ; whil (som vrtis r unmrk) { v = unmrk vrtx with smllst ist; Mrk v; or (h w j to v) { ist[w] = min ( ist[w], ist[v] + (v,w) ); Dijkstr s Algorithm is n xmpl o Gry Algorithm h Gry Strtgy is n lgorithm sign thniqu Lik Divi & Conqur h Gry Strtgy is us to solv optimiztion prolms h gol is to in th st solution Works whn th prolm hs th gry-hoi proprty A glol optimum n rh y mking lolly optimum hois Prolm: Givn n mount o mony, in th smllst numr o oins to mk tht mount Solution: Us Gry Algorithm Giv s mny lrg oins s you n his gry strtgy prous th optimum numr o oins or th US oin systm Dirnt mony systm gry strtgy my il For xmpl: suppos th US introus 4 oin 8