Graphs. Outline. Graphs. Data structures for graphs ORD SFO LAX DFW. Definition Applications Terminology Properties ADT

Σχετικά έγγραφα
Αλγόριθμοι και πολυπλοκότητα Depth-First Search

Αλγόριθμοι και πολυπλοκότητα Graphs

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Δομές Δεδομένων. Ιωάννης Γ. Τόλλης Τμήμα Επιστήμης Υπολογιστών Πανεπιστήμιο Κρήτης

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Δομές Δεδομένων. Ιωάννης Γ. Τόλλης Τμήμα Επιστήμης Υπολογιστών Πανεπιστήμιο Κρήτης

Αλγόριθμοι και πολυπλοκότητα Οριζόντια διερεύνηση

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Δομές Δεδομένων. Ιωάννης Γ. Τόλλης Τμήμα Επιστήμης Υπολογιστών Πανεπιστήμιο Κρήτης

Αλγόριθμοι και πολυπλοκότητα Directed Graphs

Fractional Colorings and Zykov Products of graphs

Nowhere-zero flows Let be a digraph, Abelian group. A Γ-circulation in is a mapping : such that, where, and : tail in X, head in

Αλγόριθμοι και πολυπλοκότητα Minimum Spanning Trees

Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής

Αλγόριθμοι και πολυπλοκότητα NP-Completeness (2)

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

Abstract Storage Devices

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

EE512: Error Control Coding

Section 8.3 Trigonometric Equations

Σχέσεις, Ιδιότητες, Κλειστότητες

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

2 Composition. Invertible Mappings

CHAPTER 48 APPLICATIONS OF MATRICES AND DETERMINANTS

ΤΜΗΜΑ ΗΛΕΚΤΡΟΛΟΓΩΝ ΜΗΧΑΝΙΚΩΝ ΚΑΙ ΜΗΧΑΝΙΚΩΝ ΥΠΟΛΟΓΙΣΤΩΝ

Θεωρία Γραφημάτων Θεμελιώσεις-Αλγόριθμοι-Εφαρμογές

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

Main source: "Discrete-time systems and computer control" by Α. ΣΚΟΔΡΑΣ ΨΗΦΙΑΚΟΣ ΕΛΕΓΧΟΣ ΔΙΑΛΕΞΗ 4 ΔΙΑΦΑΝΕΙΑ 1

The Simply Typed Lambda Calculus

ΑΚΑ ΗΜΙΑ ΕΜΠΟΡΙΚΟΥ ΝΑΥΤΙΚΟΥ ΜΑΚΕ ΟΝΙΑΣ ΣΧΟΛΗ ΜΗΧΑΝΙΚΩΝ ΠΤΥΧΙΑΚΗ ΕΡΓΑΣΙΑ

Minimum Spanning Tree: Prim's Algorithm

Approximation of distance between locations on earth given by latitude and longitude

Overview. Transition Semantics. Configurations and the transition relation. Executions and computation

ΚΥΠΡΙΑΚΟΣ ΣΥΝΔΕΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY 21 ος ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ Δεύτερος Γύρος - 30 Μαρτίου 2011

Network Algorithms and Complexity Παραλληλοποίηση του αλγορίθμου του Prim. Αικατερίνη Κούκιου

Lecture 2: Dirac notation and a review of linear algebra Read Sakurai chapter 1, Baym chatper 3

Γράφηµα (Graph) Εργαστήριο 10. Εισαγωγή

The challenges of non-stable predicates

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 5: Component Adaptation Environment (COPE)

Physical DB Design. B-Trees Index files can become quite large for large main files Indices on index files are possible.

Statistical Inference I Locally most powerful tests

Other Test Constructions: Likelihood Ratio & Bayes Tests

Second Order RLC Filters

Capacitors - Capacitance, Charge and Potential Difference

On a four-dimensional hyperbolic manifold with finite volume

[1] P Q. Fig. 3.1

Every set of first-order formulas is equivalent to an independent set

the total number of electrons passing through the lamp.

Parametrized Surfaces

ΑΛΓΟΡΙΘΜΟΙ Άνοιξη I. ΜΗΛΗΣ

ΑΛΓΟΡΙΘΜΟΙ Άνοιξη I. ΜΗΛΗΣ

Instruction Execution Times

Homework 3 Solutions

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

Exercises 10. Find a fundamental matrix of the given system of equations. Also find the fundamental matrix Φ(t) satisfying Φ(0) = I. 1.

Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)

«Χρήσεις γης, αξίες γης και κυκλοφοριακές ρυθμίσεις στο Δήμο Χαλκιδέων. Η μεταξύ τους σχέση και εξέλιξη.»

Chapter 3: Ordinal Numbers

14 Lesson 2: The Omega Verb - Present Tense

Optimal Impartial Selection

New bounds for spherical two-distance sets and equiangular lines

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

(C) 2010 Pearson Education, Inc. All rights reserved.

TMA4115 Matematikk 3

Στο εστιατόριο «ToDokimasesPrinToBgaleisStonKosmo?» έξω από τους δακτυλίους του Κρόνου, οι παραγγελίες γίνονται ηλεκτρονικά.

ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΥΠΡΟΥ ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ. ΕΠΛ342: Βάσεις Δεδομένων. Χειμερινό Εξάμηνο Φροντιστήριο 10 ΛΥΣΕΙΣ. Επερωτήσεις SQL

Section 7.6 Double and Half Angle Formulas

Models for Probabilistic Programs with an Adversary

Areas and Lengths in Polar Coordinates

Areas and Lengths in Polar Coordinates

Homomorphism in Intuitionistic Fuzzy Automata

Finite Field Problems: Solutions

k A = [k, k]( )[a 1, a 2 ] = [ka 1,ka 2 ] 4For the division of two intervals of confidence in R +

Practice Exam 2. Conceptual Questions. 1. State a Basic identity and then verify it. (a) Identity: Solution: One identity is csc(θ) = 1

Partial Differential Equations in Biology The boundary element method. March 26, 2013

Distances in Sierpiński Triangle Graphs

Matrices and Determinants

Potential Dividers. 46 minutes. 46 marks. Page 1 of 11

Tridiagonal matrices. Gérard MEURANT. October, 2008

Block Ciphers Modes. Ramki Thurimella

ΑΛΓΟΡΙΘΜΟΙ Άνοιξη I. ΜΗΛΗΣ

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016

Αλγόριθμοι και πολυπλοκότητα NP-Completeness

SCHOOL OF MATHEMATICAL SCIENCES G11LMA Linear Mathematics Examination Solutions

C.S. 430 Assignment 6, Sample Solutions

6.1. Dirac Equation. Hamiltonian. Dirac Eq.

Second Order Partial Differential Equations

Γράφοι. Ορολογία. Ορισµός: G = (V, E) όπου. Ορολογία (συνέχεια) γράφος ή γράφηµα (graph) V:ένα σύνολο E:µια διµελής σχέση στο V

Πανεπιστήμιο Δυτικής Μακεδονίας. Τμήμα Μηχανικών Πληροφορικής & Τηλεπικοινωνιών. Τεχνητή Νοημοσύνη. Ενότητα 2: Αναζήτηση (Search)

Code Breaker. TEACHER s NOTES

The Probabilistic Method - Probabilistic Techniques. Lecture 7: The Janson Inequality

Srednicki Chapter 55

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Δομές Δεδομένων. Ιωάννης Γ. Τόλλης Τμήμα Επιστήμης Υπολογιστών Πανεπιστήμιο Κρήτης

ECON 381 SC ASSIGNMENT 2

Homework 8 Model Solution Section

The ε-pseudospectrum of a Matrix

CHAPTER 12: PERIMETER, AREA, CIRCUMFERENCE, AND 12.1 INTRODUCTION TO GEOMETRIC 12.2 PERIMETER: SQUARES, RECTANGLES,

Review Test 3. MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Lanczos and biorthogonalization methods for eigenvalues and eigenvectors of matrices

DESIGN OF MACHINERY SOLUTION MANUAL h in h 4 0.

Transcript:

Graphs SO 337 LX 843 743 233 OR 802 W Hiroaki Kobayashi Outline Graphs efinition pplications Terminology Properties T ata structures for graphs dge list structure djacency list structure djacency matrix structure Hiroaki Kobayashi 2

Graph graph is a pair (V, ), where V is a set of nodes, called vertices is a collection of pairs of vertices, called edges Vertices and edges are positions and store elements xample: vertex represents an airport and stores the three-letter airport code n edge represents a flight route between two airports and stores the mileage of the route PV OR SO LG HNL 2555 337 LX 843 743 233 802 W 387 849 20 42 099 MI Hiroaki Kobayashi 3 dge Types irected edge ordered pair of vertices (u,v) first vertex u is the origin second vertex v is the destination e.g., a flight Undirected edge unordered pair of vertices (u,v) e.g., a flight route irected graph all the edges are directed e.g., route network Undirected graph all the edges are undirected e.g., flight network OR OR flight 206 849 miles PV PV Hiroaki Kobayashi 4

pplications lectronic circuits Printed circuit board Integrated circuit Transportation networks Highway network light network omputer networks Local area network Internet Web atabases ntity-relationship diagram cslaba Paul cs.brown.edu att.net cslabb cox.net brown.edu avid math.brown.edu John qwest.net Hiroaki Kobayashi 5 Terminology nd vertices (or endpoints) of an edge U and V are the endpoints of a dges incident on a vertex a, d, and b are incident on V djacent vertices U and V are adjacent egree of a vertex X has degree 5 Parallel edges h and i are parallel edges Self-loop j is a self-loop U a c V d W f b e X Y g h i Z j Hiroaki Kobayashi 6

Terminology (cont.) Path sequence of alternating vertices and edges begins with a vertex ends with a vertex each edge is preceded and followed by its endpoints Simple path path such that all its vertices and edges are distinct xamples P =(V,b,X,h,Z) is a simple path P 2 =(U,c,W,e,X,g,Y,f,W,d,V) is a path that is not simple U a c V d P 2 W f b e P X g Y h Z Hiroaki Kobayashi 7 Terminology (cont.) ycle circular sequence of alternating vertices and edges each edge is preceded and followed by its endpoints Simple cycle cycle such that all its vertices and edges are distinct xamples =(V,b,X,g,Y,f,W,c,U,a, ) is a simple cycle 2 =(U,c,W,e,X,g,Y,f,W,d,V,a, ) is a cycle that is not simple U a c V d 2 W f b X e Y g h Z Hiroaki Kobayashi 8

Properties Property Σ v deg(v) = 2m Proof: each edge is counted twice Property 2 In an undirected graph with no self-loops and no multiple edges m n (n )/2 Proof: each vertex has degree at most (n ) simple graph with n vertices has O(n 2 ) edges Notation n m deg(v) number of vertices number of edges degree of vertex v xample n = 4 m = 6 deg(v) = 3 Hiroaki Kobayashi 9 What is the bound for a directed graph? Main Methods of the Graph T Vertices and edges are positions store elements ccessor methods avertex() incidentdges(v) endvertices(e) isirected(e) origin(e) destination(e) opposite(v, e) aredjacent(v, w) Update methods insertvertex(o) insertdge(v, w, o) insertirecteddge(v, w, o) removevertex(v) removedge(e) Generic methods numvertices() numdges() vertices() edges() Hiroaki Kobayashi 0

dge List Structure Vertex object element reference to position in vertex sequence dge object element origin vertex object destination vertex object reference to position in edge sequence Vertex sequence sequence of vertex objects dge sequence sequence of edge objects v a a u b Hiroaki Kobayashi c u v w z w d b c d z djacency List Structure dge list structure Incidence sequence for each vertex sequence of references to edge objects of incident edges ugmented edge objects references to associated positions in incidence sequences of end vertices a v b u w u v w a b Hiroaki Kobayashi 2

djacency Matrix Structure dge list structure ugmented vertex objects Integer key (index) associated with vertex 2-array adjacency array Reference to edge object for adjacent vertices Null for non nonadjacent vertices u a 0 u v 2 w a 0 2 0 v b 2 w b Hiroaki Kobayashi 3 symptotic Performance n vertices, m edges no parallel edges no self-loops ounds are big-oh Space incidentdges(v) aredjacent (v, w) insertvertex(o) insertdge(v, w, o) removevertex(v) removedge(e) dge List n + m m m m djacency List n + m deg(v) min(deg(v), deg(w)) deg(v) djacency Matrix n 2 n 2 n 2 Hiroaki Kobayashi 4 n

epth-irst Search Hiroaki Kobayashi 5 Outline efinitions Subgraph onnectivity Spanning trees and forests epth-first search lgorithm xample Properties nalysis pplications of S Path finding ycle finding Hiroaki Kobayashi 6

Subgraphs subgraph S of a graph G is a graph such that The vertices of S are a subset of the vertices of G The edges of S are a subset of the edges of G spanning subgraph of G is a subgraph that contains all the vertices of G Subgraph Spanning subgraph Hiroaki Kobayashi 7 onnectivity graph is connected if there is a path between every pair of vertices connected component of a graph G is a maximal connected subgraph of G onnected graph Non connected graph with two connected components Hiroaki Kobayashi 8

Trees and orests (free) tree is an undirected graph T such that T is connected T has no cycles This definition of tree is different from the one of a rooted tree forest is an undirected graph without cycles The connected components of a forest are trees Tree orest Hiroaki Kobayashi 9 Spanning Trees and orests spanning tree of a connected graph is a spanning subgraph that is a tree spanning tree is not unique unless the graph is a tree Spanning trees have applications to the design of communication networks spanning forest of a graph is a spanning subgraph that is a forest Graph Spanning tree Hiroaki Kobayashi 20

epth-irst Search epth-first search (S) is a general technique for traversing a graph S traversal of a graph G Visits all the vertices and edges of G etermines whether G is connected omputes the connected components of G omputes a spanning forest of G S on a graph with n vertices and m edges takes O(n + m ) time S can be further extended to solve other graph problems ind and report a path between two given vertices ind a cycle in the graph Hiroaki Kobayashi 2 S lgorithm The algorithm uses a mechanism for setting and getting labels of vertices and edges lgorithm S(G) Input graph G Output labeling of the edges of G as discovery edges and back edges for all u G.vertices() setlabel(u, UNXPLOR) for all e G.edges() setlabel(e, UNXPLOR) for all v G.vertices() if getlabel(v) = UNXPLOR S(G, v) lgorithm S(G, v) Input graph G and a start vertex v of G Output labeling of the edges of G in the connected component of v as discovery edges and back edges setlabel(v, VISIT) for all e G.incidentdges(v) if getlabel(e) = UNXPLOR w opposite(v,e) if getlabel(w) = UNXPLOR setlabel(e, ISOVRY) S(G, w) else setlabel(e, K) Hiroaki Kobayashi 22

xample unexplored vertex visited vertex unexplored edge discovery edge back edge Hiroaki Kobayashi 23 xample (cont.) Hiroaki Kobayashi 24

S and Maze Traversal The S algorithm is similar to a classic strategy for exploring a maze We mark each intersection, corner and dead end (vertex) visited We mark each corridor (edge ) traversed We keep track of the path back to the entrance (start vertex) by means of a rope (recursion stack) Hiroaki Kobayashi 25 Properties of S Property S(G, v) visits all the vertices and edges in the connected component of v Property 2 The discovery edges labeled by S(G, v) form a spanning tree of the connected component of v Hiroaki Kobayashi 26

nalysis of S Setting/getting a vertex/edge label takes O() time ach vertex is labeled twice once as UNXPLOR once as VISIT ach edge is labeled twice once as UNXPLOR once as ISOVRY or K Method incidentdges is called once for each vertex S runs in O(n + m) time provided the graph is represented by the adjacency list structure Recall that Σ v deg(v) = 2m Hiroaki Kobayashi 27 Path inding We can specialize the S algorithm to find a path between two given vertices u and z using the template method pattern We call S(G, u) with u as the start vertex We use a stack S to keep track of the path between the start vertex and the current vertex s soon as destination vertex z is encountered, we return the path as the contents of the stack lgorithm paths(g, v, z) setlabel(v, VISIT) S.push(v) if v = z return S.elements() for all e G.incidentdges(v) if getlabel(e) = UNXPLOR w opposite(v,e) if getlabel(w) = UNXPLOR setlabel(e, ISOVRY) S.push(e) paths(g, w, z) S.pop(e) else setlabel(e, K) S.pop(v) Hiroaki Kobayashi 28

ycle inding We can specialize the S algorithm to find a simple cycle using the template method pattern We use a stack S to keep track of the path between the start vertex and the current vertex s soon as a back edge (v, w) is encountered, we return the cycle as the portion of the stack from the top to vertex w lgorithm cycles(g, v) setlabel(v, VISIT) S.push(v) for all e G.incidentdges(v) if getlabel(e) = UNXPLOR w opposite(v,e) S.push(e) if getlabel(w) = UNXPLOR setlabel(e, ISOVRY) paths(g, w) S.pop(e) else T new empty stack repeat o S.pop() T.push(o) until o = w return T.elements() S.pop(v) Hiroaki Kobayashi 29 readth-irst Search L L 2 Hiroaki Kobayashi 30

Outline readth-first search lgorithm xample Properties nalysis pplications Hiroaki Kobayashi 3 readth-irst Search readth-first search (S) is a general technique for traversing a graph S traversal of a graph G Visits all the vertices and edges of G etermines whether G is connected omputes the connected components of G omputes a spanning forest of G S on a graph with n vertices and m edges takes O(n + m ) time S can be further extended to solve other graph problems ind and report a path with the minimum number of edges between two given vertices ind a simple cycle, if there is one Hiroaki Kobayashi 32

S lgorithm The algorithm uses a mechanism for setting and getting labels of vertices and edges lgorithm S(G) Input graph G Output labeling of the edges and partition of the vertices of G for all u G.vertices() setlabel(u, UNXPLOR) for all e G.edges() setlabel(e, UNXPLOR) for all v G.vertices() if getlabel(v) = UNXPLOR S(G, v) lgorithm S(G, s) new empty sequence.insertlast(s) setlabel(s, VISIT) i 0 while L i.ismpty() L i + new empty sequence for all v L i.elements() for all e G.incidentdges(v) if getlabel(e) = UNXPLOR w opposite(v,e) if getlabel(w) = UNXPLOR setlabel(e, ISOVRY) setlabel(w, VISIT) L i +.insertlast(w) else setlabel(e, ROSS) i i + Hiroaki Kobayashi 33 xample unexplored vertex visited vertex unexplored edge discovery edge cross edge L L L Hiroaki Kobayashi 34

xample (cont.) L L L 2 L L L 2 L 2 Hiroaki Kobayashi 35 xample (cont.) L L L 2 L 2 L L 2 Hiroaki Kobayashi 36

Properties Notation G s : connected component of s Property S(G, s) visits all the vertices and edges of G s Property 2 The discovery edges labeled by S(G, s) form a spanning tree T s of G s Property 3 or each vertex v in L i The path of T s from s to v has i edges very path from s to v in G s has at least i edges L L 2 Hiroaki Kobayashi 37 nalysis Setting/getting a vertex/edge label takes O() time ach vertex is labeled twice once as UNXPLOR once as VISIT ach edge is labeled twice once as UNXPLOR once as ISOVRY or ROSS ach vertex is inserted once into a sequence L i Method incidentdges is called once for each vertex S runs in O(n + m) time provided the graph is represented by the adjacency list structure Recall that Σ v deg(v) = 2m Hiroaki Kobayashi 38

pplications Using the template method pattern, we can specialize the S traversal of a graph G to solve the following problems in O(n + m) time ompute the connected components of G ompute a spanning forest of G ind a simple cycle in G, or report that G is a forest Given two vertices of G, find a path in G between them with the minimum number of edges, or report that no such path exists Hiroaki Kobayashi 39