CS 4407 Algorithms Lecture 5: Graphs an Introduction

Similar documents
COT 6405 Introduction to Theory of Algorithms

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

Graphs Definitions. Gunnar Gotshalks. GraphDefinitions 1

Graph Algorithms. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Lecture 5: Graphs & their Representation

Graph Theory. ICT Theory Excerpt from various sources by Robert Pergl

Algorithm Design and Analysis

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

Chapter 9 Graph Algorithms

Introduction to Graph Theory

Chapter 9 Graph Algorithms

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

Chapter 9 Graph Algorithms

IS 709/809: Computational Methods in IS Research. Graph Algorithms: Introduction

Introduction to Algorithms

Introduction to Algorithms

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

Graph Algorithms: Chapters Part 1: Introductory graph concepts

Review: Graph Theory and Representation

Introduction to Algorithms

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

Outline. Graphs. Divide and Conquer.

Graph and Digraph Glossary

UNDIRECTED GRAPHS BBM 201 DATA STRUCTURES DEPT. OF COMPUTER ENGINEERING

Graph Algorithms Using Depth First Search

Design and Analysis of Algorithms

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

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

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

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

Algorithm Design and Analysis

Konigsberg Bridge Problem

Introduction III. Graphs. Motivations I. Introduction IV

Jana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides

Graphs and Genetics. Outline. Computational Biology IST. Ana Teresa Freitas 2015/2016. Slides source: AED (MEEC/IST); Jones and Pevzner (book)

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

Varying Applications (examples)

Reference Sheet for CO142.2 Discrete Mathematics II

CSI 2101 / Winter 2008: Discrete Structures.

CMSC 380. Graph Terminology and Representation

Elementary Graph Algorithms

CS 310 Advanced Data Structures and Algorithms

Lecture 3: Recap. Administrivia. Graph theory: Historical Motivation. COMP9020 Lecture 4 Session 2, 2017 Graphs and Trees

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.

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search


CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

Lecture 10. Graphs Vertices, edges, paths, cycles Sparse and dense graphs Representations: adjacency matrices and adjacency lists Implementation notes

CS 4407 Algorithms. Lecture 8: Circumventing Intractability, using Approximation and other Techniques

Algorithm Design and Analysis

Chapter 22. Elementary Graph Algorithms

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

Basic Graph Algorithms (CLRS B.4-B.5, )

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

CSI 604 Elementary Graph Algorithms

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

! Interesting and broadly useful abstraction. ! Challenging branch of computer science and discrete math. ! Hundreds of graph algorithms known.

Elements of Graph Theory

Graph: representation and traversal

Graph Algorithms. Definition

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

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

DFS & STRONGLY CONNECTED COMPONENTS

Basics of Graph Theory

Graph Representation

Lecture 1: Examples, connectedness, paths and cycles

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

Graphs. Pseudograph: multiple edges and loops allowed

Lecture 26: Graphs: Traversal (Part 1)

of optimization problems. In this chapter, it is explained that what network design

1 Digraphs. Definition 1

Math 776 Graph Theory Lecture Note 1 Basic concepts

Graph definitions. There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs. An undirected graph

Algorithm Design and Analysis

Unit 2: Algorithmic Graph Theory

Basic Graph Definitions

Topic 12: Elementary Graph Algorithms

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

3.1 Basic Definitions and Applications

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

Lecture 22 Tuesday, April 10

Graphs: basic concepts and algorithms

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

CS 206 Introduction to Computer Science II

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

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

Preface MOTIVATION ORGANIZATION OF THE BOOK. Section 1: Basic Concepts of Graph Theory

UNDIRECTED GRAPHS BBM ALGORITHMS DEPT. OF COMPUTER ENGINEERING

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

Representations of Graphs

Graph Theory CS/Math231 Discrete Mathematics Spring2015

BIL694-Lecture 1: Introduction to Graphs

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

An Introduction to Graph Theory

Algorithms: Graphs. Amotz Bar-Noy. Spring 2012 CUNY. Amotz Bar-Noy (CUNY) Graphs Spring / 95

Definition of Graphs and Trees. Representation of Trees.

Combinatorics Summary Sheet for Exam 1 Material 2019

0.0.1 Network Analysis

Transcription:

CS 4407 Algorithms Lecture 5: Graphs an Introduction Prof. Gregory Provan Department of Computer Science University College Cork 1

Outline Motivation Importance of graphs for algorithm design applications Overview of algorithms to study Review of basic graph theory

Today s Learning Objectives Why graphs are useful throughout Computer Science Range of applications is large We use some basic properties of graphs CS 4407, Algorithms

For theoreticians: Motivation Graph problems are neat, often difficult, hence interesting For practitioners: Massive graphs arise in networking, web modelling,... Problems in computational geometry can be expressed as graph problems Many abstract problems best viewed as graph problems Extreme: Pointer-based data structures = graphs with extra information at their nodes CS 4407, Algorithms

Examples of Networks Network Nodes Arcs Flow communication telephone exchanges, computers, satellites cables, fiber optics, microwave relays voice, video, packets circuits gates, registers, processors wires current mechanical joints rods, beams, springs heat, energy hydraulic reservoirs, pumping stations, lakes pipelines fluid, oil financial stocks, currency transactions money transportation airports, rail yards, street intersections highways, railbeds, airway routes freight, vehicles, passengers chemical sites bonds energy

Graph Algorithms Overview Standard graph algorithms Breadth-first search (BFS), Depth-first search (DFS), heuristic algorithms Minimum Spanning Tree Shortest Path Max-Flow Tree-Decomposition Algorithms Convert arbitrary graphs to trees of cliques CS 4407, Algorithms

Applications Networking Internet, communication, transportation VLSI & logic circuit design Graphics surface meshes in CAD/CAM AI and Robotics applications path planning for autonomous agents precedence constraints in scheduling

Motivations for Definition Algorithm/Concept BFS, DFS MST Network Flows Greedy algorithms MapReduce NP-complete: Hamilton cycle TSP graph isomorphism Definition Graph, adjacency structure, directionality Trees, directionality, Weighted graph Weighted graph Graph, adjacency structure, directionality Graph, adjacency structure, directionality Hamilton cycle, paths, cycles Paths, cycles Graph isomorphism

Graphs A collection of vertices or nodes, connected by a collection of edges. Useful in many applications where there is some connection or relationship or interaction between pairs of objects. network communication & transportation VLSI design & logic circuit design surface meshes in CAD/CAM path planning for autonomous agents precedence constraints in scheduling

Basic Definitions A directed graph (or digraph) G = (V, E) consists of a finite set V, called vertices or nodes, and E, a finite set of ordered pairs, called edges of G. E is a binary relation on V. Cycles, including self-loops are allowed. Multiple edges are not allowed though; (v, w) and (w, v) are distinct edges. An undirected graph (or simply a graph) G = (V, E) consists of a finite set V of vertices, and a finite set E of unordered pairs of distinct vertices, called edges of G. Cycles are allowed, but not self-loops. Multiple edges are not allowed.

Examples of Digraphs & Graphs Figure B.2

Definitions Vertex v is adjacent to vertex u if there is an edge (u, v). Given an edge e = (u, v) in an undirected graph, u and v are the endpoints of e, and e is incident on u and on v. In a digraph with edge e = (u, v), u and v are the origin and destination. We say that e leaves u and enters v. A digraph or graph is weighted if its edges are labeled with numeric values. In a digraph, the Out-degree of v is the number of edges coming from v. the In-degree of v is the number of edges coming into v. In a graph, the degree of v is the number of edges incident to v. (The in-degree equals the out-degree).

Combinatorial Facts In a graph 0 E C( V, 2) = V ( V 1) / 2 O( V 2 ) v V degree(v) = 2 E In a digraph 0 E V 2 v V in-degree(v) = v V out-degree(v) = E A graph is said to be sparse if E O( V ), and dense otherwise. CS 4407, Algorithms

Definitions (Path vs. Cycle) Path: a sequence of vertices <v 0,, v k > such that (v i- 1, v i ) is an edge for i = 1 to k, in a digraph. The length of the path is the number of edges, k. w is reachable from u if there is a path from u to w. A path is simple if all vertices are distinct. Cycle: a path in a digraph containing at least one edge and for which v 0 = v k. A cycle is simple if, in addition, all vertices are distinct. For graphs, the definitions are the same, but a simple cycle must visit 3 distinct vertices.

Historical Terms For Cycles and Paths An Eulerian cycle is a cycle, not necessarily simple, that visits every edge of a graph exactly once. A Hamiltonian cycle (or path) is a cycle (path in a directed graph) that visits every vertex exactly once.

Definitions (Connectivity) A graph is acyclic, if it contains no simple cycles. A graph is connected, if every one of its vertices can reach every other vertex. I.e., every pair of vertices is connected by a path. The connected components of a graph are equivalence classes of vertices under the is reachable from relation. A digraph is strongly connected, if every two vertices are reachable from each other. Graphs G = (V, E) and G = (V, E ) are isomorphic, if a bijection f : V V such that u, v E iff ( f(u), f(v)) E.

Examples of Isomorphic Graphs Figure B.3

Graphs, Trees, Forests Free Tree Forest DAG Trees

DAGs versus Trees A tree is a digraph with a non-empty set of nodes such that: There is exactly one node, the root, with in-degree of 0. Every node other than the root has in-degree 1. For every node a of the tree, there is a directed path from the root to a. Textbook (CLRS) suggests that a tree is an undirected graph, by association with free trees. This is a valid approach, if you accept that the existence of the distinguished vertex (root) induces a direction on all the edges of the graph. However, we usually think of trees as being DAGs. Notice that a DAG may not be a tree, even if a root is designated.

Representing Graphs Assume V = {1, 2,, n} An adjacency matrix represents the graph as a n x n matrix A: A[i, j] = 1 if edge (i, j) E (or weight of edge) = 0 if edge (i, j) E CS 4407, Algorithms

Example: Graphs: Adjacency Matrix a 1 2 4 b 3 d c A 1 2 3 4 1 2 3?? 4

Example: Graphs: Adjacency Matrix a 1 2 4 b 3 d c A 1 2 3 4 1 0 1 1 0 2 0 0 1 0 3 0 0 0 0 4 0 0 1 0

Graphs: Adjacency Matrix How much storage does the adjacency matrix require? A: O(V 2 ) What is the minimum amount of storage needed by an adjacency matrix representation of an undirected graph with 4 vertices? A: 6 bits Undirected graph matrix is symmetric No self-loops don t need diagonal CS 4407, Algorithms

Graphs: Adjacency Matrix The adjacency matrix is a dense representation Usually too much storage for large graphs But can be very efficient for small graphs Most large interesting graphs are sparse E.g., planar graphs, in which no edges cross, have E = O( V ) by Euler s formula For this reason the adjacency list is often a more appropriate representation CS 4407, Algorithms

Graphs: Adjacency List Adjacency list: for each vertex v V, store a list of vertices adjacent to v Example: Adj[1] = {2,3} Adj[2] = {3} Adj[3] = {} Adj[4] = {3} Variation: can also keep a list of edges coming into vertex 1 2 4 3 CS 4407, Algorithms

Graphs: Adjacency List How much storage is required? The degree of a vertex v = # incident edges Directed graphs have in-degree, out-degree For directed graphs, # of items in adjacency lists is out-degree(v) = E takes (V + E) storage (Why?) For undirected graphs, # items in adj lists is degree(v) = 2 E (handshaking lemma) also (V + E) storage So: Adjacency lists take O(V+E) storage

Graph Representations Let G = (V, E) be a digraph. Adjacency Matrix: a V V matrix for 1 v,w V A[v, w] = 1, if (v, w) E and 0 otherwise If digraph has weights, store them in the matrix. Adjacency List: an array Adj[1 V ] of pointers where for 1 v V, Adj[v] points to a linked list containing the vertices adjacent to v. If the edges have weights then they may also be stored in the linked list elements. Incidence Matrix: a V E matrix, B[i, j], of elements b ij = { -1, if edge j leaves vertex i } b ij = { 1, if edge j enters vertex i } b ij = { 0, otherwise } Note: must have no self-loops.

Example for Graphs Figure 22.1 NOTE: it is common to include cross links between corresponding edges, when needed to mark the edges previously visited. E.g. (v,w) = (w,v). CS 4407, Algorithms

Example for Digraphs Figure 22.2

Lecture Summary Motivation for studying graphs Importance of graphs for algorithm design applications Overview of algorithms Basic algorithms: DFS, BFS More advanced algorithms: flows, treedecompositions Review of basic graph theory