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

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

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

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

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

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:

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

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

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

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

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

CS 241 Analysis of Algorithms

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

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

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

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

1 Introduction to Modulo 7 Arithmetic

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

QUESTIONS BEGIN HERE!

QUESTIONS BEGIN HERE!

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

Present state Next state Q + M N

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

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

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

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

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

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

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

Multipoint Alternate Marking method for passive and hybrid performance monitoring

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

Designing A Concrete Arch Bridge

Planar Upward Drawings

Problem solving by search

COMP108 Algorithmic Foundations

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

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

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

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. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk

Lecture 20: Minimum Spanning Trees (CLRS 23)

Round 7: Graphs (part I)

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

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

Constructive Geometric Constraint Solving

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

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

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

CS September 2018

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

CS 103 BFS Alorithm. Mark Redekopp

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

Complete Solutions for MATH 3012 Quiz 2, October 25, 2011, WTT

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

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

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

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

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

Seven-Segment Display Driver

(Minimum) Spanning Trees

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

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

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

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

The University of Sydney MATH 2009

EE1000 Project 4 Digital Volt Meter

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

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

12. Traffic engineering

Trees as operads. Lecture A formalism of trees

Minimum Spanning Trees

Numbering Boundary Nodes

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

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?

Walk Like a Mathematician Learning Task:

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

Scientific Programming. Graphs

OpenMx Matrices and Operators

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

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

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

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

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

Solutions to Homework 5

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

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

Outline. Binary Tree

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

Strongly connected components. Finding strongly-connected components

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

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

Garnir Polynomial and their Properties

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

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

Aquauno Video 6 Plus Page 1

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

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

Transcription:

lulu jwtt pnlton sin towr ounrs hpl lpp lu Our irst non-linr t strutur! rph G onsists o two sts G = {V, E} st o V vrtis, or nos st o E s, rltionships twn nos surph G onsists o sust o th vrtis n s o G jnt vrtis r two vrtis join y n i h rin o-workr tr Mry lrt rothrs rin lrt rotin 1 rotin 2 rotin 5 Movi 1 tor 1 Movi 2 tor 3 tor 2 Movi 3 tor 4 rotin 9 N=4 L=4 Ntwork in: Grph hory 2012

i pth twn two vrtis squn o s tht ins t th irst vrtx n ns t th othr vrtx simpl pth pth tht psss throuh vrtx t most on yl pth tht ins n ns t th sm vrtx h omplt rph rph tht hs n twn h pir o istint vrtis How mny s os omplt rph with n nos hv? simpl yl yl tht os not pss throuh vrtx mor thn on onnt rph rph tht hs pth twn h pir o istint vrtis isonnt rph rph tht hs t lst on pir o vrtis without pth twn thm i h irt rph Eh is irt, or n r, or link My hv two rs twn ivn pir o vrtis, on in h irtion Vrtx y is jnt to vrtx x i (i n only i) thr is irt rom x to y irt pth squn o irt s twn two vrtis irt yli Grph (G) irt rph with no yls oston n rniso Nw ork How w rs n you rmov to mk th rph G? nt

iht rph rph whos s hv wihts iht is th ost or mnitu o th rltionship rprsnt y th oston 170 n rniso Nw ork 2600 850 nt puli intr Grph<> // prtil puli ooln isempty() // rturns tru i rph is mpty puli int n() // rturns th numr o vrtis in rph puli int m() // rturns th numr o s in rph puli voi Vrtx( v) // Insrt vrtx in rph puli voi rmovvrtx( v) // lts vrtx rom rph lon with ny s twn th vrtx n othr vrtis puli voi E( v1, v2) // Insrt n twn two ivn vrtis in rph puli voi rmove( v1, v2) // lts th twn two ivn vrtis in rph puli invrtx(trin ky) // trivs n rturns th vrtx tht ontins ivn srh ky puli ooln ise( v1, v2) // rturns tru i n xists twn two ivn vrtis puli LinkList<> tnihors ( v) // O UNIECE GH // trivs n rturns list o th vrtis jnt to vrtx v jny mtrix or rph with n vrtis numr 0, 1,, n 1 ooln n n rry mtrix rs suh tht rs[i][j] = 1 (tru) i thr is n r rom vrtx i to vrtx j 0 (ls) i thr is no r rom vrtx i to vrtx j Vrtis 0 1 2 3 rs 0 1 2 3 0 0 0 1 1 1 2 3 0 0 1 0 1 1 0 0 0 0 1 0 ht proprty os th mtrix o n unirt rph hv?

import jv.util.*; import jv.io.*; puli lss jmtgrph<> implmnts Grph<> { privt inl int NO_OUN = -1; privt inl int EUL_CCI = 10; privt int n; // numr o vrtis in th rph privt ooln[][] rs; // jny mtrix o rs privt [] vrtis; // vlus o vrtis n jny list or rph with n vrtis numr 0, 1,, n 1 Consists o n link lists h i th link list hs list ntry or vrtx j i th rph ontins n r rom vrtx i to vrtx j puli jmtgrph(){ n = 0; this.rs = nw ooln[eul_cci][eul_cci]; this.vrtis = ([])(nw Ojt[EUL_CCI]); } ont rs / / / / hih rprsnttion supports ttr ths two rqunt oprtions on rphs? ise(v, w) trmin whthr thr is n rom vrtx v to vrtx w tnihors(v) turn list o ll vrtis link to rom ivn vrtx v jny mtrix or wiht rph with n vrtis numr 0, 1,, n 1 n n n rry mtrix E suh tht E[i][j] = h wiht o th r rom vrtx i to vrtx j i thr is n rom i to j i thr is no rom vrtx i to vrtx j 5 4 2 8 E 0 4 5 0 8 4 8 0 2 5 2 0

Multipl Es jny list or wiht unirt rph Eh list ntry ontins th ll n wiht rts h s i it wr two rs in opposit irtions Multirph Not rph llows multipl s twn vrtis Multipl s init multipl rltions twn vrtis 5 4 2 8 E 8 / 4 4 5 5 / 8 2 / 2 / i r: pil Grph tr is onnt rph in whih thr is xtly on simpl pth onn:n ny two nos How mny s os tr with n nos hv? ye: rt n simpl rph visuliztion ownlo it rom http://www.yworks.om/n/prouts_y_out.html ou n rt ny rph y likin (or vrtis) n likin-n-rin (or s) Lots o rph ormts support. Us.t G ormt: txt il listin lins o: vrtxi vrtxnm (or vrtis) # vrtxi pirs (or rs) On you uplo il, hoos Lyout > Cirulr to s it li out nily.

rph-trvrsl lorithm Visits ll th vrtis tht it n rh strtin t som vrtx Visits ll vrtis o th rph i th rph is onnt (tivly omputin Connt Componnts) Must not loop orvr, i rph ontins yl Must nvr visit vrtx mor thn on Connt omponnt (or unirt rphs) = h sust o vrtis visit urin trvrsl tht ins t ivn vrtx tronly onnt omponnt (or irt rphs) = h sust o vrtis visit urin trvrsl tht ins t ny o its mmrs Hih lns irlin Compny (Hir) rolm or h ustomr rqust, init whthr squn o Hir lihts xists rom th oriin ity to th stintion ity h liht mp or Hir is irt rph r twn vrtis mns hr is liht twn itis irt pth mns hr is squn o liht onntions h solu:on prorms n xhus'v srh innin t th oriin ity, tris vry possil squn o lihts un:l ithr ins squn tht ts to th s:n:on ity trmins tht no suh squn xists h tk is usul in ornizin n xhus:v srh It hlps you rmmr how you ot th th urrnt point ktrkin n us to rovr rom wron hoi o ity

(oriincity): rhin th liht Mp stk = nw tk<e>(); stk.push(oriincity); whil ( squn o lihts rom oriincity to stincity hs not n oun) { } i (you nnot o nywhr rom th ity on top o stk) stk.pop(); // ktrk ls slt nihor, nothrcity, rom th ity on top o stk; stk.push(nothrcity);... n rmmr whr you v n stk = nw tk<e>(); Clr Mrks; stk.push(oriincity); Mrk(oriinCity) s visit; whil ( squn o lihts rom oriincity to stincity hs not n oun) { } i (you nnot in n unvisit ity rom th ity on top o stk) stk.pop(); // ktrk ls slt n unvisit nihor, nothrcity, rom th ity on top o stk; stk.push(nothrcity); Mrk(nothrCity) s visit; pth-irst-rh Exmpl: rom ->Z oul (oc) work or unirt rphs? List visit (mrk) tk stk Z Z stk = nw tk<e>(); Clr Mrks; stk.push(oriincity); Mrk(oriinCity) s visit; whil ( squn o lihts rom oriincity to stincity } hs not n oun) { i (you nnot in n unvisit ity rom th ity on top o stk) stk.pop(); // ktrk ls slt n unvisit nihor, nothrcity, rom th ity on top o stk; stk.push(nothrcity); Mrk(nothrCity) s visit; Z Q

Lyrinth: Umrto Eo viss hsus Mzs s Grphs o in th wy out o lyrinth thr is only on mns. t vry nw juntion, nvr sn or, th pth w hv tkn will mrk with thr sins. I you s tht th juntion hs lry n visit, you will mk only on mrk on th pth you hv tkn. I ll th prturs hv lry n mrk, thn you must rtr your stps. ut i on or two prturs o th juntion r still without sins, you will hoos ny on, mkin two sins on it. roin throuh n prtur tht rs only on sin, you will mk two mor, so tht now th prtur rs thr. ll th prts o th lyrinth must hv n visit i, rrivin t juntion, you nvr tk pss with thr sins, unlss non o th othr psss is now without sins. C E C EI H G E C E G H G H G stin or Conntivity usin (oc) Connt: n unirt rph or whih thr is pth rom ny no to ny othr no Z Is this rph onnt? Connt omponnt: onnt su-rph Cn w us to in ll onnt omponnts? Q