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

Similar documents
CSI 604 Elementary Graph Algorithms

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms

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

Chapter 9 Graph Algorithms

Algorithm Design and Analysis

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

Graph Theory. Many problems are mapped to graphs. Problems. traffic VLSI circuits social network communication networks web pages relationship

Basic Graph Definitions

Lecture 5: Graphs & their Representation

Graphs - I CS 2110, Spring 2016

CS 310 Advanced Data Structures and Algorithms

Computational Methods in IS Research Fall Graph Algorithms Network Flow Problems

CS 4407 Algorithms Lecture 5: Graphs an Introduction

GRAPHS Lecture 19 CS2110 Spring 2013

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

Lecture 9 Graph Traversal

CMSC 380. Graph Terminology and Representation

GRAPHS Lecture 17 CS2110 Spring 2014

Lecture 22 Tuesday, April 10

EECS 1028 M: Discrete Mathematics for Engineers

Konigsberg Bridge Problem

Directed acyclic graphs

Lecture 26: Graphs: Traversal (Part 1)

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

(Re)Introduction to Graphs and Some Algorithms

DESIGN AND ANALYSIS OF ALGORITHMS

Introduction to Graphs. CS2110, Spring 2011 Cornell University

Graphs Definitions. Gunnar Gotshalks. GraphDefinitions 1

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

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

Graphs. Carlos Moreno uwaterloo.ca EIT

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

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

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

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

Copyright 2000, Kevin Wayne 1

(Dijkstra s Algorithm) Consider the following positively weighted undirected graph for the problems below: 8 7 b c d h g f

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

Introduction to Graphs. common/notes/ppt/

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

Topic 12: Elementary Graph Algorithms

Graph Algorithms. 1 Preliminary Denitions. CSci 335 Software Design and Analysis III Chapter 9 Graph Algorithms. Prof.

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College

Algorithm Design and Analysis

CS4800: Algorithms & Data Jonathan Ullman

3.1 Basic Definitions and Applications

Graph. Vertex. edge. Directed Graph. Undirected Graph

Introduction to Graphs

CSE 373 NOVEMBER 20 TH TOPOLOGICAL SORT

Dynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs).

Graph Algorithms (part 3 of CSC 282),

Graphs and their representations. EECS 214, Fall 2018

Algorithm Design (8) Graph Algorithms 1/2

Graph Algorithms. Definition

Algorithm Design and Analysis

1 Digraphs. Definition 1

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Breadth First Search. Graph Traversal. CSE 2011 Winter Application examples. Two common graph traversal algorithms

Graphs & Digraphs Tuesday, November 06, 2007

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

Outline. Graphs. Divide and Conquer.

Today s Outline. CSE 326: Data Structures. Topic #15: Cool Graphs n Pretty Pictures. A Great Mathematician. The Bridges of Königsberg

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other.

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

W4231: Analysis of Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Inf 2B: Graphs, BFS, DFS

CSE 373: Data Structures and Algorithms

Graph Algorithms: Chapters Part 1: Introductory graph concepts

Graphs. Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS

Foundations of Discrete Mathematics

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

Week 11: Minimum Spanning trees

I A graph is a mathematical structure consisting of a set of. I Formally: G =(V, E), where V is a set and E V V.

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131

Graph Algorithms (part 3 of CSC 282),

CS 491 CAP Introduction to Graphs and Search

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

Exam 3 Practice Problems

Algorithm Design and Analysis

Advanced Data Structures and Algorithms

Graphs Introduction and Depth first algorithm

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

DIRECTED GRAPHS BBM 201 DATA STRUCTURES DEPT. OF COMPUTER ENGINEERING

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

COT 6405 Introduction to Theory of Algorithms

Introduction to Graph Theory

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

Graphs. Motivations: o Networks o Social networks o Program testing o Job Assignment Examples: o Code graph:

Graphs. The ultimate data structure. graphs 1

Homework Assignment #3 Graph

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

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

Topological Sort. Version of October 11, Version of October 11, 2014 Topological Sort 1 / 14

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

COL 702 : Assignment 1 solutions

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

Graphs ADTs and Implementations

Transcription:

IS 709/809: Computational Methods in IS Research Graph Algorithms: Introduction Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu

Motivation Several real-life problems can be converted to problems on graphs Graphs are one of the pervasive data structures used in computer science Graphs are a useful tool for modeling real-world problems Graphs allow us to abstract details and focus on the problem We can represent our domain as graphs and apply graph algorithms to solve our problem

Examples Given a map of UMBC and the surrounding area, how to get from one place to another? A B D E F C J G I H

Examples (cont d) What data structure to use to represent the problem? How do you even think about the problem? A B D E F C J G H I

Examples (cont d) Let us strip away irrelevant details We have a set of vertices {A, B, C, D, E, F, G, H, I, J} A B D E F C J G H I

Examples (cont d) Let us strip away irrelevant details We have a set of edges connecting the vertices A B D E F C J G H I

Examples (cont d) Let us strip away irrelevant details Edges can be assigned weights A 5 6 B D 7 3 C 6 E 4 F 6 9 8 G H J I 2

Examples (cont d) Let us strip away irrelevant details A 5 6 B D 7 6 E 3 4 F 6 9 C 8 J G I 2 H

Other Examples Protein-protein interaction Social network Internet Power grid WWW

Simple Graphs G = (V, E) u V is a set of vertices. E is a set of edges. u V, v V (u, v) E v

Directed Graphs G = (V, E) u v V is a set of vertices. E is a set of edges. u V, v V (u, v) E (v, u) E

Weighted Graphs G = (V, E) 5 6 7 V is a set of vertices E is a set of edges 3 6 4 6 9 8 2

Cardinality of a Set The number of elements in a set Let A be a finite set If A = (the empty set), then the cardinality of A is 0 If A has exactly n elements, n a natural number, then the cardinality of A is n The cardinality of a set A is denoted by A

Definition of a Graph A graph G = (V, E) consists of a set of vertices V and a set of edges E E = {(u, v} u, v V} Vertex v is adjacent to vertex u Edges are sometimes called arcs Example V = {A, B, C, D, E, F, G} E = {(A, B), (A, D), (B, C), (C, D), (C, G), (D, E), (D, F), (E, F)} Cardinality of Vertex Set denoted by V V = 7 = number of vertices in set V Cardinality of Edge Set denoted by E E = 8 = number of edges in set E

Definitions Undirected graphs Edges are unordered (i.e. (u, v) is the same as (v, u)) Directed graphs (digraphs) Edges are ordered (i.e. <u, v> <v, u>) Weighted graphs Edges have a weight w(u, v) or cost (u, v)

Definitions (cont d) Degree of a vertex Number of edges incident on a vertex Indegree Number of directed edges to vertex Outdegree Number of directed edges from vertex degree(v4) = 6 indegree(v4) = 3 outdegree(v4) = 3 indegree(v1) = 0 outdegree(v1) = 3 indegree(v6) = 3 outdegree(v6) = 0

Definitions (cont d) Path Sequence of vertices v 1, v 2,, v N such that (v i, v i + 1 ) E for 1 i N Path length is the number of edges on the path (i.e., N 1) Simple path has unique intermediate vertices Cycle Path where v 1 = v N Usually simple and directed Acyclic graphs have no cycles

Definitions (cont d) Undirected graph is connected if there is a path between every pair of vertices Connected, directed graph is called strongly connected Complete graph has an edge between every two vertices v 6 to v 1, v 7 to v 1

Representations Adjacency matrix is a two dimensional array For each edge (u,v), A[u][v] is true otherwise it is false

Representations (cont d) It is good to use adjacency lists for sparse graphs Sparse means not dense Graph is dense means E = ( V 2 )

Practical Problem Representations Graph represents a street map with Manhattan-like orientation Streets run mainly on north-south or east-west Any intersection is attached with four streets Graph is directed and all streets are two way, then E = 4 V Example: Assume 3000 intersections = 3000-vertex graph and 12000 edges Array size for Adjacency Matrix = 9,000,000 Most of these entries would contain 0 If the graph is sparse a better solution is adjacency list For each vertex we keep a list of all adjacent vertices Space requirement is O( E + V ), linear in the size of the graph

Graph Algorithms: Topological Sort

Topological Sort Order the vertices in a directed acyclic graph (DAG), such that if (u, v) E, then u appears before v in the ordering Example Course Prerequisite Structure at a University

Topological Sort (cont d) Topological ordering is not possible if the graph has a cycle, since for two vertices u and v on the cycle, u precedes v and v precedes u The ordering is not necessarily unique; any legal ordering will do Possible topological orderings: v 1, v 2, v 5, v 4, v 3, v 7, v 6 and v 1, v 2, v 5, v 4, v 7, v 3, v 6.

Topological Sort (cont d) Solution #1 While there are vertices left in the graph Find vertex v with indegree equals to 0 Output v Remove v from the graph together with all edges to and from v Running of Solution #1 is O( V 2 ) Possible topological ordering: v 1, v 2, v 5, v 4, v 3, v 7, v 6.

Topological Sort Pseudocode //Not been assigned a topological number Takes O( V ) times, V such calls CycleFoundException()

Topological Sort (cont d) Solution #2 Don t need to search over all vertices for indegree = 0 Only vertices that lost an edge from the previous vertex s removal need to be searched Algorithm Compute the indegree for every vertex Place all vertices of indegree 0 to an initially empty queue (note: we can also use a stack) While the queue is not empty Remove a vertex v from the queue Output v Decrement indegrees of all vertices adjacent to v Put a vertex on the queue as soon as its indegree falls to 0

Topological Sort (cont d)

Topological Sort Pseudocode

Topological Sort (cont d) Solution #2 Assume that the graph is already read into an adjacency list Assume the indegrees are computed and stored with the vertices Running time of Solution #2 is O( V + E ) Possible topological ordering: v 1, v 2, v 5, v 4, v 3, v 7, v 6.

Graph Algorithms Topological sort Shortest paths Network flow Minimum spanning tree Applications