MAT 7003 : Mathematical Foundations. (for Software Engineering) J Paul Gibson, A207.

Similar documents
Graph and Digraph Glossary

Foundations of Discrete Mathematics

Chapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.

Chapter 2 Graphs. 2.1 Definition of Graphs

Chapter 9 Graph Algorithms

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Chapter 9 Graph Algorithms

March 20/2003 Jayakanth Srinivasan,

Chapter 9 Graph Algorithms

Lecture 5: Graphs & their Representation

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

Graphs. Introduction To Graphs: Exercises. Definitions:

Discrete mathematics II. - Graphs

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap

CSC Intro to Intelligent Robotics, Spring Graphs

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

Outline. Introduction. Representations of Graphs Graph Traversals. Applications. Definitions and Basic Terminologies


Graph Theory. Probabilistic Graphical Models. L. Enrique Sucar, INAOE. Definitions. Types of Graphs. Trajectories and Circuits.

Introduction to Graph Theory

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

Binary Trees

An Introduction to Graph Theory

Elements of Graph Theory

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

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

1 Digraphs. Definition 1

Algorithm Design (8) Graph Algorithms 1/2

Graphs: basic concepts and algorithms

Introduction III. Graphs. Motivations I. Introduction IV

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

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

Data Structure. IBPS SO (IT- Officer) Exam 2017

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

Directed Graph and Binary Trees

GRAPHICAL ALGORITHMS. UNIT _II Lecture-12 Slides No. 3-7 Lecture Slides No Lecture Slides No

CMSC 380. Graph Terminology and Representation

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

Trees. Reading: Weiss, Chapter 4. Cpt S 223, Fall 2007 Copyright: Washington State University

Graph Theory CS/Math231 Discrete Mathematics Spring2015

CS521 \ Notes for the Final Exam

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

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

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

CS 310 Advanced Data Structures and Algorithms

Chapter 11: Graphs and Trees. March 23, 2008

Konigsberg Bridge Problem

Figure 4.1: The evolution of a rooted tree.

Lecture 22 Tuesday, April 10

Solutions. Suppose we insert all elements of U into the table, and let n(b) be the number of elements of U that hash to bucket b. Then.

Artificial Intelligence

Data Structures Brett Bernstein

Trees. Eric McCreath

Graph. Vertex. edge. Directed Graph. Undirected Graph

CS24 Week 8 Lecture 1

Analysis of Algorithms

DEFINITION OF GRAPH GRAPH THEORY GRAPHS ACCORDING TO THEIR VERTICES AND EDGES EXAMPLE GRAPHS ACCORDING TO THEIR VERTICES AND EDGES

4. (a) Draw the Petersen graph. (b) Use Kuratowski s teorem to prove that the Petersen graph is non-planar.

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

MATH 363 Final Wednesday, April 28. Final exam. You may use lemmas and theorems that were proven in class and on assignments unless stated otherwise.

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

1. Why Study Trees? Trees and Graphs. 2. Binary Trees. CITS2200 Data Structures and Algorithms. Wood... Topic 10. Trees are ubiquitous. Examples...

Algorithms. AVL Tree

Practice Final Exam 1

Graph Algorithms Using Depth First Search

ROOT: A node which doesn't have a parent. In the above tree. The Root is A.

Computational Discrete Mathematics

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

Trees. A tree is a directed graph with the property

Discrete mathematics

12 Abstract Data Types

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory

Trees (Part 1, Theoretical) CSE 2320 Algorithms and Data Structures University of Texas at Arlington

Logic: The Big Picture. Axiomatizing Arithmetic. Tautologies and Valid Arguments. Graphs and Trees

CSC 172 Data Structures and Algorithms. Lecture 24 Fall 2017

CS 151. Binary Trees. Friday, October 5, 12

Final Examination CSE 100 UCSD (Practice)

7.3 Spanning trees Spanning trees [ ] 61

Introduction to Mathematical Programming IE406. Lecture 16. Dr. Ted Ralphs

Combinatorics Summary Sheet for Exam 1 Material 2019

CS Transform-and-Conquer

Trees. (Trees) Data Structures and Programming Spring / 28

Graphs & Digraphs Tuesday, November 06, 2007

CS6702 GRAPH THEORY AND APPLICATIONS QUESTION BANK

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

Index. stack-based, 400 A* algorithm, 325

Trees Rooted Trees Spanning trees and Shortest Paths. 12. Graphs and Trees 2. Aaron Tan November 2017

Friday Four Square! 4:15PM, Outside Gates

Introduction to Computers and Programming. Concept Question

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

CSI 604 Elementary Graph Algorithms

CS 441 Discrete Mathematics for CS Lecture 24. Relations IV. CS 441 Discrete mathematics for CS. Equivalence relation

DATA STRUCTURES AND ALGORITHMS

Trees Algorhyme by Radia Perlman

[ DATA STRUCTURES ] Fig. (1) : A Tree

Definition of Graphs and Trees. Representation of Trees.

Advanced Data Structures and Algorithms

Transcription:

MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson, A207 paul.gibson@it-sudparis.eu http://www-public.it-sudparis.eu/~gibson/teaching/mat7003/ Graphs and Trees http://www-public.it-sudparis.eu/~gibson/teaching/mat7003/l2-graphsandtrees.pdf 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.1

Graphs A graph is a: set of points, and lines connecting some (possibly empty) subset of the points. The points of a graph are most commonly known as graph vertices, but may also be called "nodes" or simply "points." (NOTE: every vertex in a graph must be distinguishable from every other vertex in that graph.) Similarly, the lines connecting the vertices of a graph are most commonly known as graph edges, but may also be called "arcs" or "lines." 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.2

Graphs come in a wide variety of different sorts The most common type is graphs in which at most one edge (i.e., either one edge or no edges) may connect any two vertices. Such graphs are called simple graphs. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.3

Graphs come in a wide variety of different sorts If multiple edges are allowed between vertices, the graph is known as a multigraph. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.4

Graphs come in a wide variety of different sorts Vertices are usually not allowed to be selfconnected, but this restriction is sometimes relaxed to allow such "graph loops." A graph that may contain multiple edges and graph loops is called a pseudograph. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.5

Graphs come in a wide variety of different sorts: labellings The edges, vertices, or both of a graph may be assigned specific values, labels, or colors, in which case the graph is called a labeled graph. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.6

Graphs come in a wide variety of different sorts: colourings A vertex coloring is an assignment of labels or colors to each vertex of a graph such that no edge connects two identically colored vertices. An edge coloring is an assignment of labels or colors to each edge of a graph such that adjacent edges (or the edges bounding different regions) must receive different colors. The assignment of labels or colors to the edges or vertices of a graph based on a set of specified criteria is known as graph coloring. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.7

Graphs come in a wide variety of different sorts - directedness If arrows may be placed on one or both endpoints of the edges of a graph to indicate directedness, the graph is said to be directed ( or a digraph); otherwise it is undirected. A directed graph in which each edge is given a unique is called an oriented graph. A graph or directed graph together with a function which assigns a positive real number to each edge (i.e., an oriented edge-labeled graph) is known as a network. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.8

Graphs as adjacency matrices We can use a matrix to represent a graph s structure. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.9

Graphs as adjacency lists We can also use lists to represent a graph s structure. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.10

Graphs: more terminology and definitions The degree (or valence) of a vertex is the number of edge ends at that vertex. The out-degree of a node in a digraph is: the number of edges emanating from that node The in-degree of a node in a digraph is: the number of edges incident on that node A source has in-degree=0, A sink has outdegree=0 QUESTION: What is out-degree of source? What is in-degree of sink? 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.11

Graphs: more terminology and definitions A path is a sequence of consecutive edges in a graph and the length of the path is the number of edges traversed. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.12

Graphs: more terminology and definitions The diameter of a connected graph (component) is the length of the longest shortest path between 2 nodes of the graph (component) 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.13

Graphs: more terminology and definitions QUESTION: find a path, cycle, loop and simple cycle in graph G1 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.14

Graphs: more terminology and definitions Two vertices are adjacent if they are connected by an edge. A complete graph with n vertices (denoted Kn) is a graph with n vertices in which each vertex is connected to each of the others (with one edge between each pair of vertices A graph is connected if there is a path connecting every pair of vertices. A graph that is not connected can be divided into connected components (disjoint connected subgraphs). A vertex of degree zero (with no edges connected) is isolated A vertex of degree one (with only one edge connected) is a pendant edge. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.15

Directed Acyclic Graphs (DAGs) For certain applications it is convenient to deal with graphs that contain no cycles. For example, a tree is a special kind of graph that contains no cycles. DEFINITION: A directed, acyclic graph is a directed graph that contains no cycles. NOTE: G2 is a particular type of DAG a tree 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.16

Graph Traversals There are many different applications of graphs. As a result, there are many different algorithms for manipulating them. Many of the different graph algorithms systematically visit all the vertices in the graph. That is, the algorithm walks through the graph data structure and performs some computation at each vertex in the graph. This process of walking through the graph is called a graph traversal. While there are many different possible ways in which to systematically visit all the vertices of a graph, the most common are: depth-first traversal, breadth-first traversal and topological sort. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.17

Graph Traversals: depth-first Depth-first traversal of a graph visits a start-vertex and then recursively visits all the vertices adjacent to that node. The graph may contain cycles, but the traversal must visit every vertex at most once. The solution to the problem is to keep track of the nodes that have been visited, so that the traversal does not suffer the fate of infinite recursion. For example: 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.18

Graph Traversals: breadth first Since a graph has no root, when we do a breadth-first traversal, we must specify the vertex at which to start the traversal. Furthermore, we can define the depth of a given vertex to be the length of the shortest path from the starting vertex to the given vertex. Thus, breadth-first traversal first visits the starting vertex, then all the vertices adjacent to the starting vertex, and the all the vertices adjacent to those, and so on. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.19

Graph Traversals: topological sort A topological sort or topological ordering of a directed acyclic graph (DAG) is a linear ordering of its nodes in which each node comes before all nodes to which it has outbound edges. Every DAG has one or more topological sorts. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.20

Graph Algorithms There are many interesting graph problems and algorithmic solutions, e.g: Traversal Searching Shortest/Longest Paths Eulerian Hamiltonian Circuits Max/Min flow Flooding Isomorphisms Reduction Re-writing Color coding Spanning Trees TO DO: You need to have a broad understanding of all of these problems They arise in many different problem domains and you should be aware of classical solutions that can be re-use/adapted We return to some of these in later lectures when we look at computational complexity 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.21

Graph Algorithms: transitive closure The diameter of the transitive closure is 1 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.22

QUESTION: What is the transitive closure of the following graph 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.23

Answer: Two connected subpgraphs 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.24

Trees A tree is a graph in which any two vertices are connected by exactly one simple path. In other words, any connected graph without cycles is a tree. A forest is a disjoint union of trees. A tree is called a rooted tree if one vertex has been designated the root, in which case the edges have a natural orientation, towards or away from the root. The tree-order is the partial ordering on the vertices of a tree with u v if and only if the unique path from the root to v passes through u. In a rooted tree, the parent of a vertex is the vertex connected to it on the path to the root; every vertex except the root has a unique parent. A child of a vertex v is a vertex of which v is the parent. A leaf is a vertex without children. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.25

Trees: some specialisations An n-ary tree is a rooted tree for which each vertex which is not a leaf has at most n children. 2-ary trees (resp. 3-ary trees) are sometimes called binary trees (resp. ternary trees) A binary search tree (BST) is a node based binary tree data structure (where each node has a data value or key that are ordered) which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees. 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.26

Trees: balanced binary search tree Definition: A balanced binary search tree requires that: The tree is a binary search tree, and it is balanced: The height of the two subtrees (children) of a node differs by at most one. (Where, the height is the maximum distance of any leaf from the root of a tree) Each subtree is balanced For example: 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.27

Trees: AVL tree The AVL tree is named after its two inventors, G.M. Adelson- Velskii and E.M. Landis, who published it in their 1962 paper An algorithm for the organization of information. An AVL tree is a self-balancing binary search tree, and it is the first such data structure to be invented TO DO: Check that you know how insertions and deletions work for such AVL trees 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.28

Trees: some specialisations A heap is a specialized binary tree where if B is a child node of A, then key(a) key(b). For example: 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.29

Trees from graphs minimum spanning tree Informally, a spanning tree of a graph G is a selection of edges of G that form a tree spanning every vertex. That is, every vertex lies in the tree, but no cycles (or loops) are formed. It is often useful to find a minimum spanning tree of a weighted graph, ie a spanning tree with weight less than or equal to the weight of every other spanning tree. NOTE: The weight is defined as the sum of the weights of the edges in that spanning tree. EXAMPLE: 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.30

Representing Graphs As Text Strings There are lots of ways of representing graphs textually. For example, consider graph G and an alphabet restricted to: Integers as node labels Letters as arc labels Standard punctuation for representing structure I could choose a string representation such as: 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.31

Representing Graphs As Text Strings QUESTION: What other string representations can you find (using the same alphabet of punctuation): i. [ ii. ] iii., iv. ( v. ) QUESTION: Can we reduce the amont of punctuation required? 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.32

Representing Graphs As Text Strings TYPICAL ANSWERS: QUESTION: Compare and contrast the different representations are they equivalent? 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.33

Programming Exercise: check for cycles? For any graph, such as G, node and arc labelled, with directed arcs, chose a textual (string) representation. Write a function/method/procedure (in the programming language of your choice) that reads the string representation and returns true if the given graph contains a cycle (loop) NOTE: Checking for cycles is very important because many graph algorithms work only if there are no cycles in the graph (otherwise they may get into an infinite loop) 2012: J Paul Gibson T&MSP: Mathematical Foundations MAT7003/L2-GraphsAndTrees.34