GRAPH THEORY Discrete Math Team KS091201 MATEMATIKA DISKRIT (DISCRETE MATHEMATICS )

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Lecture 5 Graph Theory. Graphs Graphs are the most useful model with computer science such as logical design, formal languages, communication network,
Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
1 Slides based on those of Kenneth H. Rosen Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Graphs.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CS138A Single Source Shortest Paths Peter Schröder.
Data Structures and Algorithms Graphs Single-Source Shortest Paths (Dijkstra’s Algorithm) PLSD210(ii)
chapter Single-Source Shortest Paths Problem Definition Shortest paths and Relaxation Dijkstra’s algorithm (can be viewed as a greedy algorithm)
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Applied Discrete Mathematics Week 12: Trees
Graph & BFS.
1 Section 8.2 Graph Terminology. 2 Terms related to undirected graphs Adjacent: 2 vertices u & v in an undirected graph G are adjacent (neighbors) in.
Lecture 19: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Applied Discrete Mathematics Week 12: Trees
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE Discrete.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Let us switch to a new topic:
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
9.2 Graph Terminology and Special Types Graphs
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
GRAPH Learning Outcomes Students should be able to:
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Graphs Chapter 10.
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
Chapter 2 Graph Algorithms.
1 Graphs Chapters 9.1 and 9.2 University of Maryland Chapters 9.1 and 9.2 Based on slides by Y. Peng University of Maryland.
Graph Theory 4/23/2017.
16.1 CompSci 102© Michael Frank Today’s topics GraphsGraphs –Basics & types –Properties –Connectivity –Hamilton & Euler Paths Reading: Sections Reading:
Module #19: Graph Theory: part I Rosen 5 th ed., chs. 8-9 내년 3 월 ? 교환 학생 프로그램 영어 점수 미리미리 준비하세요.
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements.
Graphs What are Graphs? General meaning in everyday math: A plot or chart of numerical data using a coordinate system. Technical meaning in discrete.
Introduction to Algorithms Jiafen Liu Sept
Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore.
1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian.
Graphs 9.1 Graphs and Graph Models أ. زينب آل كاظم 1.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.
LOGO.  Relations:  In these slides: Introductions to graphs Graph terminology Representing graphs and graph isomorphism Connectivity Euler and Hamilton.
Chapter 9: Graphs.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Chap 7 Graph Def 1: Simple graph G=(V,E) V : nonempty set of vertices E : set of unordered pairs of distinct elements of V called edges Def 2: Multigraph.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
Chapter Chapter Summary Graphs and Graph Models Graph Terminology and Special Types of Graphs Representing Graphs and Graph Isomorphism Connectivity.
BCA-II Data Structure Using C Submitted By: Veenu Saini
Data Structures and Algorithms
COT 3100, Spring 2001 Applications of Discrete Structures
Algorithms and Data Structures Lecture XIII
Rosen 5th ed., chs. 8-9 ~44 slides (more later), ~3 lectures
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Basic Graph Algorithms
CS 583 Analysis of Algorithms
Algorithms and Data Structures Lecture XIII
Minimum Spanning Tree Algorithms
Text Book: Introduction to algorithms By C L R S
Concepts of Computation
Presentation transcript:

GRAPH THEORY Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS )

Outline 2 -- KS  Simple Graph  Directed Graph  Djikstra Algorithm

What are Graphs?  General meaning in everyday math: A plot or chart of numerical data using a coordinate system.  Technical meaning in discrete mathematics: A particular class of discrete structures (to be defined) that is useful for representing relations and has a convenient graphical representation.

Applications of Graphs  Potentially anything (graphs can represent relations; relations can describe the extension of any predicate).  Apps in networking, scheduling, flow optimization, circuit design, path planning.  Genealogy analysis, computer game-playing, program compilation, object-oriented design, …

Simple Graphs  Correspond to symmetric binary relations R.  A simple graph G=(V, E) consists of:  a set V of vertices or nodes (V corresponds to the universe of the relation R),  a set E of edges / arcs / links: unordered pairs of elements u,v  V, such that uRv.

Example of a Simple Graph  Let V be the set of states in the far-southeastern U.S.:  V={FL, GA, AL, MS, LA, SC, TN, NC}  Let E={{u,v}|u adjoins v} ={{FL,GA},{FL,AL},{FL,MS},{FL,LA},{GA,AL},{AL,MS},{ MS,LA},{GA,SC},{GA,TN}, {SC,NC},{NC,TN},{MS,TN},{MS,AL}} TN AL MS LA SC GA FL NC

Directed Graphs  Correspond to arbitrary binary relations R, which need not be symmetric.  A directed graph (V,E) consists of a set of vertices V and a binary relation E on V.  E.g.: V = people, E={(x,y) | x loves y}

Graph Terminology  Adjacent  connects  endpoints  degree  initial  terminal  in-degree, out-degree  subgraph, union.

Adjacency  Let G be an undirected graph with edge set E. Let e  E be (or map to) the pair {u,v}. Then we say:  u, v are adjacent / neighbors / connected.  Edge e is incident with vertices u and v.  Edge e connects u and v.  Vertices u and v are endpoints of edge e.

Degree of a Vertex  Let G be an undirected graph, v  V a vertex.  The degree of v, deg(v), is its number of incident edges. (Except that any self-loops are counted twice.)  A vertex with degree 0 is isolated.  A vertex of degree 1 is pendant.

Handshaking Theorem  Let G be an undirected graph with vertex set V and edge set E. Then  Corollary: Any undirected graph has an even number of vertices of odd degree.

Directed Adjacency  Let G be a directed graph, and let e be an edge of G that is (or maps to) (u,v). Then we say:  u is adjacent to v, v is adjacent from u  e comes from u, e goes to v.  e connects u to v, e goes from u to v  the initial vertex of e is u  the terminal vertex of e is v

Directed Degree  Let G be a directed graph, v a vertex of G.  The in-degree of v, deg  (v), is the number of edges going to v.  The out-degree of v, deg  (v), is the number of edges coming from v.  The degree of v, deg(v)  deg  (v)+deg  (v), is the sum of v’s in-degree and out-degree.

Directed Handshaking Theorem  Let G be a directed graph with vertex set V and edge set E. Then:  Note that the degree of a node is unchanged by whether we consider its edges to be directed or undirected.

Subgraphs  A subgraph of a graph G=(V,E) is a graph H=(W,F) where W  V and F  E. G H

Graph Unions  The union G 1  G 2 of two simple graphs G 1 =(V 1, E 1 ) and G 2 =(V 2,E 2 ) is the simple graph (V 1  V 2, E 1  E 2 ).

Graph Representations  Adjacency lists.  Adjacency matrices.  Incidence matrices.

Adjacency Lists  A table with 1 row per vertex, listing its adjacent vertices. a b d c f e

Directed Adjacency Lists  1 row per node, listing the terminal nodes of each edge incident from that node.

Adjacency Matrices  Matrix A=[a ij ], where a ij is 1 if {v i, v j } is an edge of G, 0 otherwise.

Connectivity  In an undirected graph, a path of length n from u to v is a sequence of adjacent edges going from vertex u to vertex v.  A path is a circuit if u=v.  A path traverses the vertices along it.  A path is simple if it contains no edge more than once.

Paths in Directed Graphs  Same as in undirected graphs, but the path must go in the direction of the arrows.

Connectedness  An undirected graph is connected iff there is a path between every pair of distinct vertices in the graph.  Theorem: There is a simple path between any pair of vertices in a connected undirected graph.

Review: Graph Theory  Types of graphs  Graph terminology  Graph representation  Connectivity

Graphs - Shortest Paths  Application  In a graph in which edges have costs..  Find the shortest path from a source to a destination  Surprisingly..  While finding the shortest path from a source to one destination,  we can find the shortest paths to all over destinations as well!  Common algorithm for single-source shortest paths is due to Edsger Dijkstra

Dijkstra’s Algorithm - Data Structures  For a graph, G = ( V, E )  Dijkstra’s algorithm keeps two sets of vertices: S Vertices whose shortest paths have already been determined V-S Remainder  Also d Best estimates of shortest path to each vertex  Predecessors for each vertex

Predecessor Sub-graph  Array of vertex indices,  [j], j = 1.. |V|   [j] contains the pre-decessor for node j  j’s predecessor is in  [  [j]], and so on....  The edges in the pre-decessor sub-graph are (  [j], j )

Dijkstra’s Algorithm - Operation  Initialise d and   For each vertex, j, in V  d j =    j = nil  Source distance, d s = 0  Set S to empty  While V-S is not empty  Sort V-S based on d  Add u, the closest vertex in V-S, to S  Relax all the vertices still in V-S connected to u Initial estimates are all  No connections Add s first!

Dijkstra’s Algorithm - Operation  Initialise d and   For each vertex, j, in V  d j =    j = nil  Source distance, d s = 0  Set S to empty  While V-S is not empty  Sort V-S based on d  Add u, the closest vertex in V-S, to S  Relax all the vertices still in V-S connected to u Initial estimates are all  No connections Add s first!

Dijkstra’s Algorithm - Operation  The Relaxation process Relax the node v attached to node u relax( Node u, Node v, double w[][] ) if d[v] > d[u] + w[u,v] then d[v] := d[u] + w[u,v] pi[v] := u If the current best estimate to v is greater than the path through u.. Edge cost matrix Update the estimate to v Make v’s predecessor point to u

Dijkstra’s Algorithm - Full  The Shortest Paths algorithm Given a graph, g, and a source, s shortest_paths( Graph g, Node s ) initialise_single_source( g, s ) S := { 0 } /* Make S empty */ Q := Vertices( g ) /* Put the vertices in a PQ */ while not Empty(Q) u := ExtractCheapest( Q ); AddNode( S, u ); /* Add u to S */ for each vertex v in Adjacent( u ) relax( u, v, w )

Dijkstra’s Algorithm - Initialise  The Shortest Paths algorithm Given a graph, g, and a source, s shortest_paths( Graph g, Node s ) initialise_single_source( g, s ) S := { 0 } /* Make S empty */ Q := Vertices( g ) /* Put the vertices in a PQ */ while not Empty(Q) u := ExtractCheapest( Q ); AddNode( S, u ); /* Add u to S */ for each vertex v in Adjacent( u ) relax( u, v, w ) Initialise d, , S, vertex Q

Dijkstra’s Algorithm - Loop  The Shortest Paths algorithm Given a graph, g, and a source, s shortest_paths( Graph g, Node s ) initialise_single_source( g, s ) S := { 0 } /* Make S empty */ Q := Vertices( g ) /* Put the vertices in a PQ */ while not Empty(Q) u := ExtractCheapest( Q ); AddNode( S, u ); /* Add u to S */ for each vertex v in Adjacent( u ) relax( u, v, w ) Greedy! While there are still nodes in Q

Dijkstra’s Algorithm - Relax neighbours  The Shortest Paths algorithm Given a graph, g, and a source, s shortest_paths( Graph g, Node s ) initialise_single_source( g, s ) S := { 0 } /* Make S empty */ Q := Vertices( g ) /* Put the vertices in a PQ */ while not Empty(Q) u := ExtractCheapest( Q ); AddNode( S, u ); /* Add u to S */ for each vertex v in Adjacent( u ) relax( u, v, w ) Greedy! Update the estimate of the shortest paths to all nodes attached to u

Dijkstra’s Algorithm - Operation  Initial Graph Distance to all nodes marked  Source Mark 0

Dijkstra’s Algorithm - Operation  Initial Graph Source Relax vertices adjacent to source

Dijkstra’s Algorithm - Operation  Initial Graph Source Red arrows show pre-decessors

Dijkstra’s Algorithm - Operation Source is now in S Sort vertices and choose closest

Dijkstra’s Algorithm - Operation Source is now in S Relax u because a shorter path via x exists Relax y because a shorter path via x exists

Dijkstra’s Algorithm - Operation Source is now in S Change u’s pre-decessor also Relax y because a shorter path via x exists

Dijkstra’s Algorithm - Operation S is now { s, x } Sort vertices and choose closest

Dijkstra’s Algorithm - Operation S is now { s, x } Sort vertices and choose closest Relax v because a shorter path via y exists

Dijkstra’s Algorithm - Operation S is now { s, x, y } Sort vertices and choose closest, u

Dijkstra’s Algorithm - Operation S is now { s, x, y, u } Finally add v

Dijkstra’s Algorithm - Operation S is now { s, x, y, u } Pre-decessors show shortest paths sub-graph

Dijkstra’s Algorithm - Proof  Greedy Algorithm  Proof by contradiction best  Lemma 1  Shortest paths are composed of shortest paths  Proof  If there was a shorter path than any sub-path, then substitution of that path would make the whole path shorter

Dijkstra’s Algorithm - Proof  Denote   (s,v) - the cost of the shortest path from s to v  Lemma 2  If s ...  u  v is a shortest path from s to v, then after u has been added to S and relax(u,v,w) called, d[v] =  (s,v) and d[v] is not changed thereafter.  Proof  Follows from the fact that at all times d[v]   (s,v)  See Cormen (or any other text) for the details

Dijkstra’s Algorithm - Proof  Using Lemma 2  After running Dijkstra’s algorithm, we assert d[v] =  (s,v) for all v  Proof (by contradiction)  Suppose that u is the first vertex added to S for which d[u]    (s,u)  Note  v is not s because d[s] = 0  There must be a path s ...  u, otherwise d[u] would be   Since there’s a path, there must be a shortest path

Dijkstra’s Algorithm - Proof  Proof (by contradiction)  Suppose that u is the first vertex added to S for which d[u]   (s,u)  Let s  x  y  u be the shortest path s  u, where x is in S and y is the first outside S  When x was added to S, d[x]    (s,x)  Edge x  y was relaxed at that time, so d[y]    (s,y)

Dijkstra’s Algorithm - Proof  Proof (by contradiction)  Edge x  y was relaxed at that time, so d[y]    (s,y)   (s,u)  d[u]  But, when we chose u, both u and y where in V-S, so d[u]  d[y] (otherwise we would have chosen y)  Thus the inequalities must be equalities  d[y]    (s,y)   (s,u)  d[u]  And our hypothesis (d[u]    (s,u)) is contradicted!

Dijkstra’s Algorithm - Time Complexity  Dijkstra’s Algorithm  Similar to MST algorithms  Key step is sort on the edges  Complexity is  O( (|E|+|V|)log|V| ) or  O( n 2 log n ) for a dense graph with n = |V|