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

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

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)}

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

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

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

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 241 Analysis of Algorithms

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

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

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

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

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

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

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

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

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

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

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

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

Planar Upward Drawings

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

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

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

Constructive Geometric Constraint Solving

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

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

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

Minimum Spanning Trees

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

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

Present state Next state Q + M N

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

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

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

1 Introduction to Modulo 7 Arithmetic

Problem solving by search

12. Traffic engineering

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

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

CS 103 BFS Alorithm. Mark Redekopp

Walk Like a Mathematician Learning Task:

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

CS September 2018

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

QUESTIONS BEGIN HERE!

Instructions for Section 1

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?

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

Multipoint Alternate Marking method for passive and hybrid performance monitoring

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

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

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

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

Analysis for Balloon Modeling Structure based on Graph Theory

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

CS553 Lecture Register Allocation I 3

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

Garnir Polynomial and their Properties

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

Chapter 9. Graphs. 9.1 Graphs

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

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

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

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

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

10. EXTENDING TRACTABILITY

Scientific Programming. Graphs

QUESTIONS BEGIN HERE!

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

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

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

Searching Linked Lists. Perfect Skip List. Building a Skip List. Skip List Analysis (1) Assume the list is sorted, but is stored in a linked list.

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Seven-Segment Display Driver

Examples and applications on SSSP and MST

Analysis of Algorithms - Elementary graphs algorithms -

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

Trees as operads. Lecture A formalism of trees

MA1506 Tutorial 2 Solutions. Question 1. (1a) 1 ) y x. e x. 1 exp (in general, Integrating factor is. ye dx. So ) (1b) e e. e c.

EE1000 Project 4 Digital Volt Meter

Analysis of Algorithms - Elementary graphs algorithms -

Jonathan Turner Exam 2-10/28/03

Lecture 20: Minimum Spanning Trees (CLRS 23)

Solutions to Homework 5

13. Binary tree, height 4, eight terminal vertices 14. Full binary tree, seven vertices v 7 v13. v 19

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

Last time: introduced our first computational model the DFA.

CSI35 Chapter 11 Review

CS553 Lecture Register Allocation 1

Graph Contraction and Connectivity

This chapter covers special properties of planar graphs.

Transcription:

Grphs & Grph Algorithms Ltur CS Fll 5 Announmnts Upoming tlk h Mny Crrs o Computr Sintist Or how Computr Sin gr mpowrs you to o muh mor thn o Dn Huttnlohr, Prossor in th Dprtmnt o Computr Sin n Johnson Grut Shool o Mngmnt 5: PM, Wnsy, Novmbr 9th Upson Loung FREE PIZZA! ACSU (Assoition o Computr Sin Unrgruts) his is not Grph hs r Grphs 9 8 7 6 5 4 st Qtr n Qtr r Qtr 4th Qtr Est Wst North K 5 K, =...not th kin w mn, nywy Applitions o Grphs Communition ntworks Routing n shortst pth problms Commoity istribution (low) ri ontrol Rsour llotion Gomtri moling... 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

Exmpl Dirt Grph Exmpl Unirt Grph Exmpl: V = {,b,,,, E = {(,b), (,), (,), (b,), (b,), (b,), (,), (,), (,), (,), (,) V = 6, E = b An unirt grph is just lik irt grph, xpt th gs r unorr pirs (sts) {u,v Exmpl: b V = {,b,,,, E = {{,b, {,, {,, {b,, {b,, {b,, {,, {,, {,, {,, {, b Som 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 by n g h outgr o vrtx u in irt grph is th numbr o gs or whih u is th sour h ingr o vrtx v in irt grph is th numbr o gs or whih v is th sink h gr o vrtx u in n unirt grph is th numbr o gs o whih u is n npoint b Mor Grph rminology 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 numbr 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 b A grph is yli i it hs no yls A irt yli grph is ll g his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs

his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs his i ls to n lgorithm vrtis until th grph ispprs

opologil Sort Just omput topologil sort o th g A numbring o th vrtis suh tht ll gs go rom lowr- to highr-numbr vrtis his i ls to n lgorithm vrtis until th grph ispprs Usul in job shuling with prn onstrints 4 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 jobs Eg (u,v) is prsnt i jobs u n v h rquir ss to th sm shr rsour, n thus nnot xut simultnously Colors r tim slots to shul th jobs Minimum numbr o olors n to olor th grph = minimum numbr o tim slots rquir Plnrity A grph is plnr i it n b mb in th pln with no gs rossing Is this grph plnr?

Plnrity A grph is plnr i it n b mb in th pln with no gs rossing Plnrity A grph is plnr i it n b mb 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, (possibly with othr nos long th gs shown) h Four-Color horm Evry plnr grph is 4-olorbl (Appl & Hkn, 976) Biprtit Grphs Biprtit Grphs A irt or unirt grph is biprtit i th vrtis n b prtition into two sts suh tht ll gs go btwn th two sts h ollowing r quivlnt G is biprtit G is -olorbl G hs no yls o o lngth

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 5 8 Ajny List h list or u ontins v, i thr is n g rom u to v tht hs ost 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 = numbr o vrtis m = numbr o gs m u = numbr 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 problm tht ours otn Fin th lst-ost rout btwn Ith n Dtroit Rsult pns on our notion o ost lst milg lst tim hpst lst boring All o ths osts n b rprsnt s g osts on grph How o w in shortst pth?

Shortst Pths or Unwight Grphs S A B C D E F bsdistn(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 bsdistn How mny tims n vrtx b 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 bsdistn(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 bs Pik up t s; mrk h no s it lv th tbl Not: Ngtiv g-osts r not llow 5 9 S A B 9 4 C D E F 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, but 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 Problm: 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 b brought 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) );

Dijkstr s Algorithm or Digrphs Algorithm works on both unirt n irt grphs without moiition As bor: Ngtiv g-osts r not llow 5 9 S A B 9 4 C D E F 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) ); Gry Algorithms 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 problms h gol is to in th bst solution Works whn th problm hs th gry-hoi proprty A globl optimum n b rh by mking lolly optimum hois Problm: Givn n mount o mony, in th smllst numbr o oins to mk tht mount Solution: Us Gry Algorithm Giv s mny lrg oins s you n his gry strtgy prous th optimum numbr o oins or th US oin systm Dirnt mony systm gry strtgy my il For xmpl: suppos th US introus 4 oin