Graph Definitions and Applications. Graphs: Very Useful Abstractions Graphs apply to many diverse areas: social sciences, linguistics, physical sciences,

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Great Theoretical Ideas in Computer Science
Chapter Matrices Matrix Arithmetic
February 26, 2015Applied Discrete Mathematics Week 5: Mathematical Reasoning 1 Addition of Integers Example: Add a = (1110) 2 and b = (1011) 2. a 0 + b.
Lecture 5 Graph Theory. Graphs Graphs are the most useful model with computer science such as logical design, formal languages, communication network,
8.3 Representing Relations Connection Matrices Let R be a relation from A = {a 1, a 2,..., a m } to B = {b 1, b 2,..., b n }. Definition: A n m  n connection.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Great Theoretical Ideas in Computer Science for Some.
Discussion #33 Adjacency Matrices. Topics Adjacency matrix for a directed graph Reachability Algorithmic Complexity and Correctness –Big Oh –Proofs of.
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Discussion #34 1/17 Discussion #34 Warshall’s and Floyd’s Algorithms.
Representing Relations Using Matrices
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Applied Discrete Mathematics Week 12: Trees
Graph & BFS.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
Introduction to Graphs
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Fall 2014 Doug James Lecture 17: Graphs.
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
Discussion #30 1/23 Discussion #30 Graph Definitions and Applications.
MATRICES. Matrices A matrix is a rectangular array of objects (usually numbers) arranged in m horizontal rows and n vertical columns. A matrix with m.
Applied Discrete Mathematics Week 10: Equivalence Relations
GRAPHS Education is what remains after one has forgotten what one has learned in school. Albert Einstein Albert Einstein Smitha N Pai.
GRAPH Learning Outcomes Students should be able to:
February 25, 2002Applied Discrete Mathematics Week 5: Mathematical Reasoning 1 Addition of Integers How do we (humans) add two integers? Example: 7583.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
Chapter 2 Graph Algorithms.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 2): Graphs  Graph Terminology (9.2)
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Based on slides by Y. Peng University of Maryland
1 Closures of Relations: Transitive Closure and Partitions Sections 8.4 and 8.5.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every.
Data Structures & Algorithms Graphs
Matrices Section 2.6. Section Summary Definition of a Matrix Matrix Arithmetic Transposes and Powers of Arithmetic Zero-One matrices.
Relation. Combining Relations Because relations from A to B are subsets of A x B, two relations from A to B can be combined in any way two sets can be.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
8.4 Closures of Relations Definition: The closure of a relation R with respect to property P is the relation obtained by adding the minimum number of.
Chapter 9: Graphs.
Great Theoretical Ideas in Computer Science for Some.
Graphs. Graph Definitions A graph G is denoted by G = (V, E) where  V is the set of vertices or nodes of the graph  E is the set of edges or arcs connecting.
COMPSCI 102 Introduction to Discrete Mathematics.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
Section 2.4. Section Summary  Sequences. o Examples: Geometric Progression, Arithmetic Progression  Recurrence Relations o Example: Fibonacci Sequence.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Programming Abstractions Cynthia Lee CS106B. Upcoming Topics Graphs! 1.Basics  What are they? How do we represent them? 2.Theorems  What are some things.
CS 285- Discrete Mathematics Lecture 11. Section 3.8 Matrices Introduction Matrix Arithmetic Transposes and Power of Matrices Zero – One Matrices Boolean.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Discrete Structures Li Tak Sing( 李德成 ) Lectures
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
Inductive Proof (the process of deriving generalities from particulars) Mathematical Induction (reasoning over the natural numbers)
Graphs: Definitions and Basic Properties
Mathematical Structures for Computer Science Chapter 6
Graph Definitions and Applications
ICS 353: Design and Analysis of Algorithms
Graphs Chapter 13.
Closures of Relations: Transitive Closure and Partitions
Basic Graph Algorithms
Graph Operations And Representation
CS 583 Analysis of Algorithms
Data Structures & Algorithms Digraphs and DAGs
Discrete Mathematics for Computer Science
Representing Relations Using Matrices
Presentation transcript:

Graph Definitions and Applications

Graphs: Very Useful Abstractions Graphs apply to many diverse areas: social sciences, linguistics, physical sciences, communication engineering, and many more. Why? Because they are a useful abstraction. –Abstractions capture the essence of a real-world problem. –Abstractions discard irrelevant details and let us focus on the essence of the problem to be solved. –Abstractions lend themselves to precise (mathematical) specification. –Mathematically defined abstractions lead to correct computer implementations.

Graphs in Programming Testing: paths in programs: Call graphs in programs Software products consist of modules that invoke each other Deadlock in operating systems … T F T F T F SequenceIf-then-else While Repeat-until Case

Graphs in Transportation & Product Delivery Airline connections: getting from here to there Highways with mileage between cities Traveling salesman problem: visit all cities with minimal distance Traffic networks studied by transportation and city planners Pipelines for delivering water or gas

Graphs in Networks Social networks –Friend of a friend –Co-collaborators Computer networks –Connect all, minimal number of connections –(Minimal) spanning trees, LANs, WANs Scheduling networks –Workflow from source to sink –Critical path, slack time –Earliest starting time, latest completion time

Problems that Don’t Initially Look Like Graph Problems Have you ever had to work your way through a maze of interpreters at an international conference? Swedish and Indonesian delegates wish to talk to each other, but among the sixteen interpreters, not one speaks both Swedish and Indonesian. A way to solve this problem is to form a chain of interpreters. There are, however, only four booths; interpreters must be in booths, and each booth can contain only one interpreter. Problem: Does a solution exist? If so, which four interpreters will you place in the booths?

Interpreters at the Great World Conference Swedish—( Booth #1Booth #2Booth #3Booth #4 )—Indonesian (1) Portuguese Indonesian (2) Polish English German (3) Italian Norwegian English (4) Korean Turkish (5) English Polish (6) Swedish Turkish (7) Spanish Chinese Japanese (8) French Portuguese (9) Dutch German (10) Swedish Norwegian (11) Japanese Indonesian Russian (12) Dutch French Chinese Russian Portuguese (13) Polish Italian Swedish (14) German Chinese Korean (15) Dutch Spanish Indonesian (16) French English

Table of Spoken Languages A B Chinese 111 Dutch 1111 English 1111 French 111 German 111 Indonesian 1111 Italian 11 Japanese 11 Korean 11 Norwegian 11 Polish 111 Portuguese 111 Russian 11 Spanish 11 Swedish 1111 Turkish 11

A B A B “Can Speak to” Matrix

Graph of “Can Speak to” Matrix 103 Norwegian English 2 13 Polish Swedish 6 5 Polish English 14 German 9 4 Turkish Korean 7 Dutch Chinese French Chinese Spanish Portuguese French Japanese Indonesian Russian Indonesian Italian Swedish Indonesian A B Indonesian Swedish 16 French

Graph Definition Hyp: edges either all ordered or all unordered G = (V, E), where V is a set of vertices/nodes, and E is a relation on VxV (E is a set of all-ordered or all-unordered pairs) Example V = {1, 2, 3} E = {(1, 2), (2, 3), (3, 3)}

A Few Special Graphs H is a subgraph of G if V H is a subset of V G and E H is a subset of E G A graph G is complete if all nodes in G are connected to all other nodes in G (often denoted K 1, …, K n ) A graph G is planar if it can be drawn (in 2D) with no crossing lines  K5K5  B3B3   A graph is planar if and only if it does not contain either K 5 or B 3 as a subgraph.

Adjacency Matrix Definition: Let G = (V, E) be a simple digraph. Let V = {v 1, v 2,…v n } be the vertices (nodes). Order the vertices from v 1 to v n. The n  n matrix A whose elements are given by a ij = 1, if (v i, v j )  E 0, otherwise is the adjacency matrix of the graph G. Example: { v4v v3v v2v v1v1 v4v4 v3v3 v2v2 v1v1 A =

Powers of Adjacency Matrices Powers of adjacency matrices: A 2, A 3, … Can compute powers –Using ordinary arithmetic: –Using Boolean arithmetic: a ij =  k=1 n a ik  a kj a ij =  k=1 n a ik  a kj

Powers Using Ordinary Arithmetic A = A 2 = A 3 =

Powers Using Ordinary Arithmetic (continued…) The element in the ith row and the jth column of A n is equal to the number of paths of length n from the ith node to the jth node A 4 =

Powers Using Ordinary Arithmetic (continued…) A = A 2 = A 3 = A 1 + A 2 = # of ways in 2 or fewer A 1 + A 2 + A 3 = # of ways in 3 or fewer A 1 + A 2 + A 3 + A 4 = # of ways in 4 or fewer = =

Powers Using Boolean Arithmetic Using Boolean arithmetic, we compute reachability. We can compute the paths of length 2 by A 2, 3 by A 3 … and of length n by A n. Since the longest possible path we care about for reachability is n, we obtain all paths by A  A 2  A 3  …  A n. The reachability matrix is the transitive closure of A. Algorithm: R = A; for (i = 2 to n) { compute A i ; R = R  A i ; } O(n 4 ) (n-1)  n  n  n for (j = 1 to n) { for (k = 1 to n) { a i jk = 0; for (m = 1 to n) { a i jk = a i jk  (a i-1 jm  a 1 mk ); }

Reachability A = A  A 2 = A  A 2  A 3 = A  A 2  A 3  A 4 = 1 st iteration 2 nd iteration 3 rd iteration

Algorithms: Proof of Correctness The algorithm terminates –No loops: obvious –Loops: descending sequence on well-founded poset (intuitively, fixed start and end place) The algorithm produces the correct result –No loops: Reason that steps lead to the desired conclusion –Loops: Find an appropriate loop invariant  a T/F condition that stays the same as the loop executes, is based on the number of iterations, and leads to the conclusion we need. Prove by induction that the loop invariant holds as the loop executes.

Loop Invariant Example:  A[i] i=1 n sum = 0 for i = 1 to n sum = sum + A[i] Loop invariant: After k iterations, sum = A[1] + A[2] + … + A[k]. Induction proof: Basis: k = 0 (initialization, before the loop begins), sum = 0, which is the sum after 0 iterations. (Or, we could start with k=1: After 1 iteration, sum = A[1].) Induction: By the induction hypothesis, after k iterations, sum = A[1] + A[2] + … + A[k]. In the next iteration we add A[k+1]. Thus, after k+1 iterations, sum = A[1] + A[2] + … + A[k+1].

Loop Invariant Example: Selection Sort -- A is an array of n distinct integers for i = 1 to n find location j of the smallest integer in A[i] … A[n] swap A[i] and A[j] Loop invariant: After k iterations, A[1], …, A[k] are sorted  A[k] < all of A[k+1], …, A[n]. Induction proof: Basis: k = 0 (initialization, before the loop begins), A is an array of n distinct integers which may or may not be sorted. (Or, we could start with k=1: After 1 iteration A[1] is sorted  A[1] < all of A[1+1], …, A[n].) Induction: By the induction hypothesis, after k iterations, A[1], …, A[k] are sorted  A[k] < all of A[k+1], …, A[n]. Then since A[k] < all of A[k+1], …, A[n], and we find the smallest integer in A[k+1], …, A[n] to swap with A[k+1], A[1], …, A[k+1] are sorted  A[k+1] < all of A[(k+1)+1], …, A[n]

Proof of Correctness for Reachability Loop invariant: After z outer loops, a xy = 1 iff y is reachable from x along a path of length z+1 or less from x to y. Note: the loop terminates after n  1 outer loops since i runs from 2 to n. Thus, when the algorithm terminates, if the loop invariant holds, a xy = 1 iff y is reachable from x along a path of length (n  1)+1 = n or less from x to y, and thus is reachable since n is the longest a path can be (that starts at a node N, visits all other nodes once, and comes back to N). Inductive proof –Basis: z=0 (i.e., before entering the outer loop), R = A and a xy is 1 iff there is a path from x to y; thus a xy = 1 iff y is reachable from x along a path of length 0+1 = 1 or less from x to y. –Induction: By the induction hypothesis we have that after z outer loops, a xy = 1 iff y is reachable from x along a path of length z+1 or less from x to y. In the z+1 st iteration we compute A (z+2), in which a xy = 1 iff there is a path of length z+1 from x to some node q and an edge from q to y, i.e. a path of length z+2 from x to y, and we add these reachable possibilities for paths of length z+2 to the result R. Hence, after z+1 outer loops, a xy = 1 iff y is reachable from x along a path of length (z+1)+1 = z+2 or less from x to y. R = A; for (i = 2 to n) { compute A i ; R = R  A i ; } for (j = 1 to n) { for (k = 1 to n) { a i jk = 0; for (m = 1 to n) { a i jk = a i jk  (a i-1 jm  a 1 mk ); }