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

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

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

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

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

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

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

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

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

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

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

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

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

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?

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

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

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

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

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

COMP108 Algorithmic Foundations

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

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

Constructive Geometric Constraint Solving

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

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

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

Chapter 9. Graphs. 9.1 Graphs

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

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

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

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

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

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

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

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

Planar Upward Drawings

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

12. Traffic engineering

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

Minimum Spanning Trees

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

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

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?

Scientific Programming. Graphs

Numbering Boundary Nodes

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

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

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

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

Graph Contraction and Connectivity

Solutions to Homework 5

QUESTIONS BEGIN HERE!

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

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

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

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

Problem solving by search

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

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

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

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

QUESTIONS BEGIN HERE!

Trees as operads. Lecture A formalism of trees

Discovering Pairwise Compatibility Graphs

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

Section 3: Antiderivatives of Formulas

Round 7: Graphs (part I)

Computational Biology, Phylogenetic Trees. Consensus methods

1 Introduction to Modulo 7 Arithmetic

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

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

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

CS September 2018

Seven-Segment Display Driver

Graphs and Graph Searches

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

CSI35 Chapter 11 Review

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

Present state Next state Q + M N

A 43k Kernel for Planar Dominating Set using Computer-Aided Reduction Rule Discovery

Multipoint Alternate Marking method for passive and hybrid performance monitoring

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

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

Quartets and unrooted level-k networks

This chapter covers special properties of planar graphs.

Outline. Binary Tree

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

Page 1. Question 19.1b Electric Charge II Question 19.2a Conductors I. ConcepTest Clicker Questions Chapter 19. Physics, 4 th Edition James S.

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

CIT 596 Theory of Computation 1. Graphs and Digraphs

Two Approaches to Analyzing the Permutations of the 15 Puzzle

Graph Theory. Simple Graph G = (V, E). V={a,b,c,d,e,f,g,h,k} E={(a,b),(a,g),( a,h),(a,k),(b,c),(b,k),...,(h,k)}

IEEE TRANSACTIONS ON COMPUTATIONAL BIOLOGY AND BIOINFORMATICS, VOL. TK, NO. TK, MONTHTK YEARTK 1. Hamiltonian Walks of Phylogenetic Treespaces

CS 103 BFS Alorithm. Mark Redekopp

Transcription:

CS2: Grphs Prihr Ch. 4 Rosn Ch. Grphs A olltion of nos n gs Wht n this rprsnt? n A omputr ntwork n Astrtion of mp n Soil ntwork CS2 - Hsh Tls 2 Dirt Grphs Grphs/Ntworks Aroun Us A olltion of nos n irt gs Somtims w wnt to rprsnt irtionlity: n Uniirtionl ntwork onntions n On wy strts n Th w http://nousls.om/wp-ontnt/uplos/2/2/ figur--mning-irultion.png http://lin-r-th-inking.logspot.om/2/2/ visulizing-goti-informtion-with.html CS2 - Hsh Tls

Grph Trminology Grph Trminology G=(V, E) Vrtis Egs Egs Two vrtis r jnt if thy r onnt y n g. An g is inint on two vrtis Dgr of vrtx: numr of gs inint on it A sugrph of grph G = (V,E) is grph (V,E ) suh tht V is sust of V n, E is sust of E sugrph u Vrtis/ Nos v Grph trminology: 4. in Prihr,. in Rosn Pths Grph Trminology n Pth: squn of gs Slf loop (loop): n g tht onnts vrtx to itslf v v 2 2 v 4 n (, 2, 3 ) is pth of lngth 3 from v to v 4 n In simpl grph pth n rprsnt s squn of vrtis Simpl grph: no slf loops n no two gs onnt th sm vrtis Multigrph: my hv multipl gs onnting th sm vrtis v 3 3 Psuogrph: multigrph with slf-loops 2

Complt Grphs n Simpl grph tht ontins xtly on g twn h pir of istint vrtis. Cyls Th yl C n, n 3, onsists of n vrtis v, v 2,, v n n gs {v, v 2 }, {v 2, v 3 },., n {v n-, v n }. Complt Grph Whls n-cus (n-imnsionl hypru) n W otin th whl W n whn w n itionl vrtx to th yl C n, for n 3, n onnt this nw vrtx to h of th n vrtis in C n, y nw gs Hypru 2 3

Th gr of vrtx Exmpl n Th gr of vrtx in n unirt grph q th numr of gs inint with it q xpt tht loop t vrtx ontriuts twi to th gr of tht vrtx. f g 4 g() = 2 g() = g(f) = 4 g() = g() = 3 g(g) = Som Grph Thorms Biprtit Grphs n Hnshking: Lt G=(V,E) n unirt grph with gs. Thn 2 = v V g(v) n An unirt grph hs n vn numr of vrtis of o gr. n Lt G=(V,E) grph with irt gs. Thn g (v) = g + (v) = E v V v V n n n A simpl grph on whih th vrtx st V n prtition into two isjoint sts V n V2 suh tht vry g onnts vrtx in V to on in V2. Biprtit? f g Thorm: A simpl grph is iprtit iff it is possil to ssign on of two iffrnt olors to h vrtx of th grph so tht no two jnt vrtis r ssign th sm olor. f 4

Dirt Grphs w Ingr: numr of inoming gs Outgr: numr of outgoing gs n n Connt Componnts An unirt grph is ll onnt if thr is pth twn vry pir of vrtis of th grph. A onnt omponnt of grph G is onnt sugrph of G tht is not propr sugrph of nothr onnt sugrph of G. v G={{,,,,,f,g},E} G ={{,,},E } G 2 ={{,,f,g}, E 2 } f g Grph ADT n Crt n Empty? n Numr of vrtis? n Numr of gs? n Eg xists twn two vrtis? n A vrtx n A n g twn two vrtis n Dlt vrtx (n ny onnt gs) n Dlt th g twn two vrtis n Rtriv vrtx Clsss for Unirt Grph with Instn Vrils n Eg: q vrtx, vrtx2 q wight n Grph: q Numr of gs, numr of vrtis q orgniz olltion of vrtis n gs

Grph Dt Struturs - Ajny Mtrix n Vrtis q lls mpp into inis q on vrtx mpp to on inx q Vlus: n ooln to init prsn/sn of g in (un)irt grph n int to init vlu of wight g n Egs q squr mtrix of gs n siz = numr of vrtis n g: two (vrtx) inis n usful for ns grphs Ajny Mtrix Exmpl Ll Inx A B C 2 D 3 E 4 mpping of vrtx lls to rry inis B D A E C 2 3 4 2 3 4 Ajny Mtrix: rry of gs inx y vrtx Grph Dt Struturs - Ajny List Ajny List Exmpl n Vrtis q mpp to list of jnis q jny: g n Egs: lists of jnis q link-list of out-going gs pr vrtx n usful for sprs grphs B D A E C B D A E C Inx A B 2 C 3 D 4 E Ll B E A B C D mpping of vrtx lls to list of gs 6

Whih Implmnttion Is Bst? Implmnttion: Eg Clss n Whih implmnttion st supports ommon Grph Oprtions: q Is thr n g twn vrtx i n vrtx j? q Fin ll vrtis jnt to vrtx j n Whih st uss sp? Clss Eg { privt Intgr v,w; // vrtis privt int wight; puli Eg(Intgr first, Intgr son, int gwight){ v = first; w = son; wight = gwight; } puli int gtwight() { rturn wight; } puli Intgr gtv() { rturn v; } puli Intgr gtw() { rturn w; } Implmnttion: Grph Clss lss Grph { privt int numvrtis; privt int numegs; privt Vtor<TrMp<Intgr, Intgr>> jlist; puli Grph(int n) { numvrtis = n; numegs = ; jlist = nw Vtor<TrMp<Intgr, Intgr>>(); for (int i=; i<numvrtis; i++) { jlist.(nw TrMp<Intgr, Intgr>()); } } Implmnttion: Grph Clss Mthos puli int gtnumvrtis() puli int gtnumegs() puli int gtegwight(intgr v, Intgr w) puli voi Eg(Intgr v, Intgr w) puli voi Eg(Eg ) puli voi rmoveg(eg ) puli Eg fineg(intgr v, Intgr w)

Six Dgrs of Kvin Bon mg ryn john mlkovih pollo 3 tom hnks lint stwoo kvin on lur linny jk niholson morgn frmn mihll pfiffr n Ator x hs Kvin Bon Numr of n if th shortst pth twn x n Kvin Bon hs lngth n Shortst Pth Algorithms (Dijkstr s Algorithm) n Grph G(V,E) with non-ngtiv wights ( istns ) n Comput shortst istns from vrtx s to vry othr vrtx in th grph Grph m with th hlp of th orl of Bon: http://orlofon.org/ Shortst Pth Algorithms (Dijkstr s Algorithm) Shortst Pth Algorithms (Dijkstr s Algorithm) n Algorithm q Mintin rry (minimum istn stimts) n Init: [s]=, [v]= v V-s q Priority quu of vrtis not yt visit q slt minimum istn vrtx, visit v, upt nighors n Intrtiv Dijkstr s lgorithm: q http://stunts.i.uptrs.gr/~ppgl/projt/ kf.htm 2

Shortst Pth Algorithms (Dijkstr s Algorithm): Initiliz Shortst Pth Algorithms (Dijkstr s Algorithm): stp / / -- -- 2 2 Shortst Pth Algorithms (Dijkstr s Algorithm): stp 2 / / -- -- / / / 4/ 4 Shortst Pth Algorithms (Dijkstr s Algorithm): stp 3 / / -- -- / / / 4/ / / / / 2 2

Shortst Pth Algorithms (Dijkstr s Algorithm): stp 4 / / -- -- / / / 4/ / / / / / / / / Shortst Pth Algorithms (Dijkstr s Algorithm): Don / / / / 2 2 Minimum istn from to : Minimum istn from to : Minimum istn from to : Minimum istn from to : Exmpl Dijkstr s Algorithm Dijkstr(G: grph with vrtis v v n- n wights w[u][v])!!// omputs shortst istn of vrtx to vry othr vrtx!!rt st vrtxst tht ontins only vrtx!![] =!!for (v = through n-)!!![v] = infinity!!for (stp = 2 through n)!!!fin th smllst [v] suh tht v is not in vrtxst!!! v to vrtxst!!!for (ll vrtis u not in vrtxst)!!!!if ([u] > [v] + w[v][u])!!!!![u] = [v] + w[v][u]! 4

Shortst Pth Algorithms Using Priority Quu (Dijkstr s Algorithm): stp Shortst Pth Algorithms (Dijkstr s Algorithm): stp 2 4 [,],[,] 2 [,],[,],[4,] 2 Shortst Pth Algorithms (Dijkstr s Algorithm): stp 3 Shortst Pth Algorithms (Dijkstr s Algorithm): stp 4 [,],[,] 2 [,] 2

Shortst Pth Algorithms (Dijkstr s Algorithm): Don Dijkstr s Algorithm n How to otin th shortst pths? q At h vrtx mintin pointr tht tlls you th vrtx from whih you rriv. 2 2