CS1022 Computer Programming & Principles Lecture 8.1 Digraphs (1)

Slides:



Advertisements
Similar presentations
Mathematical Preliminaries
Advertisements

1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 10 Arrays and Tile Mapping Starting Out with Games & Graphics.
Lecture 15. Graph Algorithms
ABC Technology Project
CHAPTER 6 Introduction to Graphing and Statistics Slide 2Copyright 2012, 2008, 2004, 2000 Pearson Education, Inc. 6.1Tables and Pictographs 6.2Bar Graphs.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE Transportation.
Comp 122, Spring 2004 Graph Algorithms – 2. graphs Lin / Devi Comp 122, Fall 2004 Identification of Edges Edge type for edge (u, v) can be identified.
Squares and Square Root WALK. Solve each problem REVIEW:
CS1022 Computer Programming & Principles
© 2010 Goodrich, Tamassia Graphs1 Graph Data Structures ORD DFW SFO LAX
Graphs, representation, isomorphism, connectivity
CS1022 Computer Programming & Principles Lecture 9.2 Boolean Algebra (2)
CS1022 Computer Programming & Principles
CS1022 Computer Programming & Principles Lecture 7.1 Graphs (1)
Discrete Mathematics 3. MATRICES, RELATIONS, AND FUNCTIONS Lecture 5 Dr.-Ing. Erwin Sitompul
Discrete Mathematics Dr.-Ing. Erwin Sitompul
CS1022 Computer Programming & Principles
CS1022 Computer Programming & Principles
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Week 1.
We will resume in: 25 Minutes.
CS203 Lecture 15.
How Cells Obtain Energy from Food
Epp, section 10.? CS 202 Aaron Bloomfield
Analysis of Algorithms CS 477/677
Chapter 8 Topics in Graph Theory
Bioinformatics Programming 1 EE, NCKU Tien-Hao Chang (Darby Chang)
13-Optimization Assoc.Prof.Dr. Ahmet Zafer Şenalp Mechanical Engineering Department Gebze Technical.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
Applied Discrete Mathematics Week 12: Trees
Introduction to Graphs
Lecture 16 CSE 331 Oct 9, Announcements Hand in your HW4 Solutions to HW4 next week Remember next week I will not be here so.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Discrete Math for CS Chapter 8: Directed Graphs. Discrete Math for CS digraph: A digraph is a graph G = (V,E) where V is a finite set of vertices and.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Chapter 2 Graph Algorithms.
Foundations of Discrete Mathematics
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CSCI 115 Chapter 8 Topics in Graph Theory. CSCI 115 §8.1 Graphs.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs Upon completion you will be able to:
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
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.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Leda Demos By: Kelley Louie Credits: definitions from Algorithms Lectures and Discrete Mathematics with Algorithms by Albertson and Hutchinson graphics.
MAT 2720 Discrete Mathematics Section 8.1 Introduction
Graphs and Graph Models
Introduction (with applications) ADT & terminology
Graphs Chapter 13.
CS100: Discrete structures
Chapter 9: Graphs Basic Concepts
Walks, Paths, and Circuits
Graphs Chapter 7 Visit for more Learning Resources.
Graphs G = (V, E) V are the vertices; E are the edges.
Chapter 9: Graphs Basic Concepts
Presentation transcript:

CS1022 Computer Programming & Principles Lecture 8.1 Digraphs (1)

Plan of lecture Digraphs (definition and terminology) Simple digraphs Paths and cycles PERT charts Topological sort algorithm 2 CS1022

Digraphs, again Directed graphs = digraphs We have used digraphs to represent relations – We did not define them formally Model partial ordering – A before B, A before C, – B before C? C before B? Networks of dependences useful for – Data flow analysis – Task scheduling Edges are directed – Finding paths require following a direction 3 CS

A digraph is a pair G  (V, E) where – V is a finite set of vertices – E is a relation on V Visually, a digraph is – A set of labelled vertices with – Directed edges linking pairs of vertices Directed edges are elements of E – Pairs of vertices, where the order is important – Also called arcs If u, v  V are vertices and (u, v)  E is an arc – We write simply uv Directed graphs 4 CS1022 ab

Simple digraphs (1) A simple digraph has no loops or multiple arcs There is at most one arc uv from u to v and There is at most one arc vu from v to u If uv is an arc then we say u is an antecedent of v 5 CS1022

Simple digraphs (2) Example: digraph G  (V, E) where Vertex set V   a, b, c, d  Arc set E   ab, bd, cb, db, dc  Graphically: 6 CS1022 a c b d

abcd a b c d Simple digraphs (3) Adjacency matrix (set E   ab, bd, cb, db, dc  ): 7 CS1022 abcd aF b c d abcd aFTFF b c d abcd aFTFF bFFFT c d abcd aFTFF bFFFT cFTFF d abcd aFTFF bFFFT cFTFF dFTTF

Paths and cycles in digraphs A path of length k is a – Sequence of vertices v 0, v 1, , v k – Such that v i – 1 v i is an arc, 1  i  k – Example: a, b, d, c is a path A cycle is a – Sequence of vertices v 0, v 1, , v k – Such that v i – 1 v i is an arc, 1  i  k – v 0  v k (first and last vertices are the same) – v i  v j, 0  i, j  k, i  0 or j  k (no other repetition) – Example: b, d, c, b is a cycle; a, b, d, c, b, a is not a cycle A graph with no cycles in it is an acyclic graph 8 CS1022 a c b d

PERT chart (1) Acyclic graphs useful to model situations in which tasks have to be carried out in a certain order – A cycle means that a task had to precede itself! In task-scheduling problems the corresponding acyclic digraph is known as PERT chart – Project Evaluation and Review Technique (PERT) 9 CS1022

PERT chart (2) Suppose (partial) degree programme below – Pre-requisites, so order is important 10 CS1022 ModulePre-requisites Advanced biotechnologyB BiotechnologyC Cell biologyH DNA structuresC Enzyme activitiesD, G Food scienceE Genetic engineeringC Human biologyNone

PERT chart (3) PERT chart shows interdependence of modules 11 CS1022 ModulePre-requisites Advanced biotechnologyB BiotechnologyC Cell biologyH DNA structuresC Enzyme activitiesD, G Food scienceE Genetic engineeringC Human biologyNone A B C DE H G F

Topological sort algorithm (1) We want to help students find an order of modules – Consistent with pre-requisites Classic solution: topological sort algorithm – Consistent labelling for vertices of acyclic digraphs Labelling 1, 2, 3, , n of vertices such that – If uv is an arc and – Vertex u has label i, and – Vertex v has label j, then – i  j 12 CS1022

Topological sort algorithm (2) Gives consistent labelling of acyclic digraph G  (V, E) – Antecedents of each vertex stored in A(v) 13 CS1022 begin for v  V do calculate A(v); label := 0; while unlabelled vertices v remain for which A(v)   do begin label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u}; % delete u from remaining vs end

Find consistent labelling for digraph of modules Step 0 – Antecedent sets are: – A(A)  {B} – A(B)  {C} – A(C)  {H} – A(D)  {C} – A(E)  {D, G} – A(F)  {E} – A(G)  {C} – A(H)   begin for v  V do calculate A(v); label := 0; while unlabelled vertices v remain for which A(v)   do begin label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u}; end Topological sort algorithm (3) 14 CS1022 for v  V do calculate A(v); A B C DE H G F

Topological sort algorithm (4) Step 1 – Enter while loop: – Assign label 1 to H – Delete H from remaining A(v) – A(A)  {B} – A(B)  {C} – A(C)   – A(D)  {C} – A(E)  {D, G} – A(F)  {E} – A(G)  {C} 15 CS label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u};...

Topological sort algorithm (5) Step 2 – second pass through while loop: – Assign label 2 to C – Delete C from remaining A(v) – A(A)  {B} – A(B)   – A(D)   – A(E)  {D, G} – A(F)  {E} – A(G)   16 CS label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u};...

Topological sort algorithm (6) Step 3 – third pass through while loop: – There is a choice of labels to choose from – Each choice leads to distinct consistent labelling – Assign label 3 to B and delete B from remaining A(v) – A(A)   – A(D)   – A(E)  {D, G} – A(F)  {E} – A(G)   17 CS label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u};...

Topological sort algorithm (7) Step 4 – fourth pass through while loop: – There is again a choice of labels to choose from – Assign label 4 to A and delete A from remaining A(v) – A(D)   – A(E)  {D, G} – A(F)  {E} – A(G)   18 CS label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u};...

Topological sort algorithm (8) Step 5 – fifth pass through while loop: – Assign label 5 to D and delete D from remaining A(v) – A(E)  {G} – A(F)  {E} – A(G)   19 CS label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u};...

Topological sort algorithm (9) Step 6 – sixth pass through while loop: – Assign label 6 to G and delete G from remaining A(v) – A(E)   – A(F)  {E} 20 CS label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u};...

Topological sort algorithm (10) Step 7 – seventh pass through while loop: – Assign label 7 to E and delete E from remaining A(v) – A(F)   21 CS label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u};...

Topological sort algorithm (11) Step 7 – final pass through while loop: – Assign label 8 to F a – There are no remaining vs to delete E from 22 CS label := label + 1; u := a vertex with A(u)   ; assign label to u; for each unlabelled vertex v  V do A(v) := A(v)  {u};...

Topological sort algorithm (12) Algorithm found one possible consistent labelling: H, C, B, A, D, G, E, F This gives an order in which modules can be taken – Consistent with pre-requisites 23 CS1022 A B C DE H G F

Some remarks Algorithm analysed a graph and ordered vertices – “Sort” vertices based on incidence of arcs Approach was exhaustive... – However, it did not try all traversals of the digraph – It relied on visiting vertices (labelling them) in some order Why should you care? – If you ever need to perform similar process you can (you should!) re-use the algorithm – Algorithm can be implemented in different languages 24 CS1022

Further reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd (Chapter 8) Wikipedia’s entry on directed graphs Wikibooks entry on graph theory 25 CS1022