Graphes: Manipulations de base et parcours

Similar documents
Graphs and Orders Cours MPRI

Chordal graphs MPRI

Last course. Last course. Michel Habib 28 octobre 2016

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS

Exercise set 2 Solutions

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Lecture 1. 1 Notation

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4)

Elements of Graph Theory

Introduction III. Graphs. Motivations I. Introduction IV

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

Discrete Mathematics Course Review 3

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7

Discrete Mathematics Lecture 4. Harper Langston New York University

Graph traversal is a generalization of tree traversal except we have to keep track of the visited vertices.

Algorithm Design and Analysis

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

Lecture 6: Graph Properties

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

Graph Algorithms (part 3 of CSC 282),

Solutions to Midterm 2 - Monday, July 11th, 2009

Parallel Breadth First Search

Small Survey on Perfect Graphs

Graphs (MTAT , 6 EAP) Lectures: Mon 14-16, hall 404 Exercises: Wed 14-16, hall 402

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

Vertical decomposition of a lattice using clique separators

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

Brief History. Graph Theory. What is a graph? Types of graphs Directed graph: a graph that has edges with specific directions

Assignment 4 Solutions of graph problems

Theory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck

Copyright 2000, Kevin Wayne 1

Math 170- Graph Theory Notes

REGULAR GRAPHS OF GIVEN GIRTH. Contents

Bipartite Roots of Graphs

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

1 Digraphs. Definition 1

Algorithmes certifiants

Graph theory. Po-Shen Loh. June We begin by collecting some basic facts which can be proved via bare-hands techniques.

CS2 Algorithms and Data Structures Note 9

Graph Theory S 1 I 2 I 1 S 2 I 1 I 2

Matching Theory. Figure 1: Is this graph bipartite?

Basics of Graph Theory

Module 11. Directed Graphs. Contents

WUCT121. Discrete Mathematics. Graphs

3.1 Basic Definitions and Applications

The Probabilistic Method

Planarity. 1 Introduction. 2 Topological Results

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

CS 3410 Ch 14 Graphs and Paths

CS781 Lecture 2 January 13, Graph Traversals, Search, and Ordering

Basic Combinatorics. Math 40210, Section 01 Fall Homework 4 Solutions

Tutorial 3: Shortest path Artificial Intelligence

Varying Applications (examples)

1 Definition of Reduction

CSE 20 DISCRETE MATH WINTER

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

Graph Theory. 1 Introduction to Graphs. Martin Stynes Department of Mathematics, UCC January 26, 2011

CS Data Structures and Algorithm Analysis

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

CSI 604 Elementary Graph Algorithms

Homework Assignment #3 Graph

Treewidth and graph minors

Partition Refinement:

8 Colouring Planar Graphs

Math.3336: Discrete Mathematics. Chapter 10 Graph Theory

CMSC th Lecture: Graph Theory: Trees.

5 Graphs

On Structural Parameterizations of the Matching Cut Problem

1 The Shortest Path Problem

HW Graph Theory SOLUTIONS (hbovik)

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

arxiv: v1 [math.co] 27 Feb 2015

Approximation Algorithms for Geometric Intersection Graphs

Matching and Planarity

Chapter 4. Relations & Graphs. 4.1 Relations. Exercises For each of the relations specified below:

Lecture Notes on Graph Theory

On vertex-coloring edge-weighting of graphs

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Majority and Friendship Paradoxes

Exact Algorithms Lecture 7: FPT Hardness and the ETH

Goals! CSE 417: Algorithms and Computational Complexity!

Worksheet for the Final Exam - Part I. Graphs

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Reference Sheet for CO142.2 Discrete Mathematics II

Disjoint directed cycles

Copyright 2000, Kevin Wayne 1

v V Question: How many edges are there in a graph with 10 vertices each of degree 6?

Unrestricted and Complete Breadth-First Search of Trapezoid Graphs in O(n) Time

Graph Algorithms (part 3 of CSC 282),

Introduction to Graph Theory

COLORING EDGES AND VERTICES OF GRAPHS WITHOUT SHORT OR LONG CYCLES

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Graph Theory II. Po-Shen Loh. June edges each. Solution: Spread the n vertices around a circle. Take parallel classes.

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Searching in Graphs (cut points)

A graph is finite if its vertex set and edge set are finite. We call a graph with just one vertex trivial and all other graphs nontrivial.

Graph Theory. Part of Texas Counties.

Assignment 1 Introduction to Graph Theory CO342

Graphs and Networks The (, D) problem

Title Edge-minimal graphs of exponent 2

Transcription:

Graphes: Manipulations de base et parcours Michel Habib habib@liafa.univ-paris-diderot.fr http://www.liafa.univ-paris-diderot.fr/~habib Cachan, décembre 2013

Notations Here we deal with finite loopless and simple undirected graphs. For such a graph G we denote by V (G) the set of its vertices and by E(G) the edge set By convention V = n and E = m

Bound on the number of edges Triangle free graphs Show that if G has no triangle then : E V 2 4 Planar graphs Show that if G is a simple planar graph (i.e. without loop and parallel edge) then : E 3 V 6

Sparse graphs satisfy : E(G) O( V (G) ) Planar graphs are sparse, but also many graphs coming from applications are sparse. For example the WEB graph is sparse. For sparse graphs one has to use an adjacency lists representation.

Matrice ordonnée par l ordre alphabétique des noms des URL

Un zoom autour de la diagonale

Implicit hypothesis : the memory words have k bits with k > log( V ) To be sure, consider the bit encoding level

Adjacency lists O( V + E ) memory words Adjacency test : xy is an arc in O( N(x) ) Adjacency Matrix O( V 2 ) memory words (can be compressed) Adjacency test : xy is an arc in O(1) Customized representations, a pointer for each arc...

For some large graphs, the Adjacency matrix, is not easy to obtain and manipulate. But the neighbourhood of a given vertex can be obtained. (WEB Graph or graphs is Game Theory)

Exercise Can the advantages of the 2 previous representations can be mixed in a unique new one? Adjacency lists : construction in O(n + m) Inicence matrix : cost of the query : xy E? in O(1) In other words Using O(n 2 ) space, but with linear time algorithms on graphs?

Quadratic space in linear time Select a 2-dimensional array GRAF of size n 2 construct an auxillary unidimensional array of size m EDGE : For j=1 to m xy being the j th edge of G GRAF [x, y] = j EDGE[j] = a pointer to the memory word GRAF [x, y] The construction of the EDGE array requires O(m) time Memory used n 2 + m O(n 2 )

xy E iff EDGE[GRAF [x, y]] contains a pointer pointing to the memory word GRAF [x, y] Therefore the query : xy E? Can be done in 2 tests O(1).

Quicksands A sentence like : To compute this invariant or this property of a given graph G one needs to see ( or visit) every edge at least once. False statement as for example the computation of twins resp. connected components on G knowing G.

Auto-complemented representations Initial Matrix 1 2 3 4 1 1 1 1 0 2 0 0 1 0 3 1 0 1 1 4 1 0 0 0 Tagged Matrix 1 2 3 4 1 0 1 0 0 2 1 0 0 0 3 0 0 0 1 4 0 0 1 0

At most 2n tags (bits). O(n + m ) with m << m. Dalhaus, Gustedt, McConnell 2000 What can be computed using such representations? Example : strong connected components of G, knowing G?

Find a minimum sized representation If G is undirected a minimum is unique.

What is an elementary operation for a graph? Traversing an edge or Visiting the neighbourhood? It explains the very few lower bounds known for graph algorithms on a RAM Machine. Our graph algorithms must accept any auto-complemented representation. Partition Refinement

Exercise Suppose that a graph G = (V, E) is given by its adjacency lists and let σ be some total ordering of its vertices. How can we sort the adjacency with respect to σ (increasing)? What is the complexity of this operation? Let σ be the total ordering of the vertices with decreasing degrees, how to compute σ?

Sorting an adjacency list Suppose that a graph G = (V, E) is given by its adjacency lists A and let σ be some total ordering of its vertices. How can we sort the adjacency with respect to σ (increasing)? One solution Build another adjacency list structure B from the old one by taking the vertices from σ(n) down to σ(1) read A(σ(i)) and add σ(i) in front of the lists of B corresponding to the neighbors of σ(i) At the end the lists of B are sorted in the right way.

Complexity Time : Linear time complexity (the size of the data structure A). Memory : Twice the size of the adjacency lists 2 A

Sorting the vertices by their degrees 1. Compute the degrees by scanning the adjacency lists in an array D 2. Use any per value sort algorithm (Radix or other) since all numbers are bounded by n

The previous solutions need that the data structure is available at once in the memory. This will be implicit in the remaining of the course, as well as the RAM model.

Graphs are good models The great importance of the right model It is crucial to use all the characteristics of the problem you want to solve and find a good model. Two examples from Peter Winkler s nice book on Mathematical Puzzles : All the discrete structures considered here are supposed to be finite. 1. An odd number of soldiers in a field in such a way that all pairwise distances are different. Each soldier is told to keep an eye on the nearest other soldier. Show that at least one soldier is not being watched. 2. A famous problem on rectangles : A large rectangle of the plane is partitioned into smaller rectangles, each of which has either integer height or integer width (or both). Prove that the large rectangle also has this property.

Graphs are good models Exercise 1 Let us consider the 2 nearest soldiers x,y. They both keep an eye on the other. If another soldier watch on x or y, then we are done because it exists at least one soldier that nobody watches. Else x,y is a 2-bond which is a connected component and we proceed by induction.

Graphs are good models Exercise 2 Start with the graph of the planar tiling and keep exactly 2 integers edges by rectangle. This yields a graph (possibly with parallel edges) in which all vertices have even degrees except the corners. Take a maximal path starting in one corner...

Graphs are good models Generic Search 1 2 4 7 3 6 5 Invariant At each step, an edge between a visited vertex and a unvisited one is selected

Graphs are good models Parcours générique

Graphs are good models Generic search S {s} for i 1 à n do Pick an unumbered vertex v of S σ(i) v foreach unumbered vertex w N(v) do if w / S then Add w to S end end end

Graphs are good models Parcours en largeur

Graphs are good models Parcours en largeur (BFS) Données: Un graphe G = (V, E) et un sommet source s Résultat: Un ordre total σ de V Initialiser la file S à s pour i 1 à n faire Extraire le sommet v de la tête de la file S σ(i) v pour chaque sommet non-numéroté w N(v) faire si w n est pas dans S alors Ajouter w en fin de la file S fin fin fin

Graphs are good models Parcours en profondeur

Graphs are good models Parcours en profondeur (DFS) Données: Un graphe G = (V, E) et un sommet source s Résultat: Un ordre total σ de V Initialiser la pile S à s pour i 1 à n faire Extraire le sommet v du haut de la pile S σ(i) v pour chaque sommet non-numéroté w N(v) faire si w n est pas dans S alors Ajouter w en haut de la pile S fin fin fin