SlideShare a Scribd company logo
Design and Analysis of Algorithms
Lecture 12
• Algorithms
1
CS345A
for Directed Acyclic Graphs
Recap of last lecture
2
Problem Definition
Input: A directed graph with and a source vertex
Aim:
• Compute the shortest path to for all
Theorem:
There exists an time algorithm to build size data structure
that compactly stores shortest path to for all
3
Longest path to each vertex ?
No polynomial time algorithm
till date !
Imagine there were no research in Algorithms. And you are asked to write a program
to compute shortest paths from source s to every vertex. Your first attempt would
have been to enumerate all paths from source and then report the path which is
shortest. But the number of paths from source to any vertex can be exponential. So
you would have felt the hardness of the shortest paths problem. May be (if you were
like Dijkstra) you would have worked hard and with perseverance and designed the
algorithm which we call Dijkstra’s algorithm today.
But consider the situation now when the area of algorithm is quite developed ( very
active for more than 50 years). But the best algorithm the researchers have designed
till date for the longest paths problem takes exponential time ! What would be your
reaction to this reality ?
• Frustration, feeling down ? (not good for a person with true scientific spirit)
• Curiosity (natural)
There are hundreds of such algorithmic problems in computer science for which the
fastest algorithm takes only exponential time.
Towards the end of this course, we shall discuss a theory of such a family of problems.
“Theory of NP complete problems”
With this note, we begin today’s lecture.
4
Directed Acyclic Graphs
5
Directed Acyclic Graphs
Question: what is a cycle in ?
Answer: A sequence , ,…, such that (,) for all
and (,) .
6
𝒗 𝟏 𝒗 𝟐 𝒗 𝟑 𝒗𝒌 −𝟏 𝒗 𝒌
…
Directed Acyclic Graphs
Definition:
A directed graph is said to be acyclic if there is no cycle present in it.
Example:
7
z
u
b v
x w a
y
DAG
Topological ordering
Definition: a mapping : []
such that for each edge
() < ()
Theorem: There exists a topological ordering for every DAG.
1 2 3 4 5 6 7 8 9 10 11
Does there exist a
topological ordering for
every directed graph ?
Certainly No if there is any cycle
< < <
< < <
>
Is it possible to arrange vertices in a line so that each edge goes from left to right ?
How to formalize it ?
Topological ordering
Example:
This is indeed a valid topological ordering.
9
z
u
b v
x w a
y
u v a b w
x z y
1 2 3 4 5 6 7 8
How efficiently can we
determine if a given mapping
is indeed a topological
ordering ?
O() time
Topological ordering
Three questions
Question 1: Why does a topological ordering exist for every DAG ?
Question 2: How efficiently can we compute a topological ordering ?
Question 3: What is the use of topological ordering ?
10
APPLICATIONS OF
TOPOLOGICAL ORDERING
Question 3
11
Applications of Topological ordering
Almost every algorithmic problem on DAG exploits Topological ordering.
Examples:
• Single source shortest paths
(No need of Dijkstra’s algorithm)
• Single source longest paths
• Count no. of paths from a source to a destination
(If the no. is a polynomial of )
All these problems have a simple time algorithm for DAG
12
WHY DOES
TOPOLOGICAL ORDERING EXIST FOR EVERY DAG?
Question 1
13
Why does Topological ordering exist ?
Example:
14
z
u
b v
x w a
y
Is there any vertex for
which you can be sure of
its place in the ordering?
Any vertex of indegree=0 can
be given number 1 in a
topological ordering.
What is the guarantee
that such a vertex always
exists in a DAG ?
Why does Topological ordering exist ?
Lemma 1: Every DAG has at least one vertex with in-degree = 0.
Proof:
(an algorithmic proof)
Pick any vertex .
While in-degree 0 do
{ Let be an edge
 ;
}
return ;
Observation: This algorithm, if terminates will output a vertex of indegree =0.
15
a
c
x
c …
b y
cycle
But what is the guarantee that it
will terminate.?
The algorithm does indeed terminate.
In fact, no vertex will be processed twice in
while loop.
Why does Topological ordering exist ?
Lemma 1: Every DAG has at least one vertex with in-degree = 0.
16
z
u
b v
x w a
y
How to use
Lemma 1 to show
existence of a valid
?
Why does Topological ordering exist ?
17
z
w
y
u
a
x
v
u v a
b
b w
x z y
1 2 3 4 5 6 7 8
Why does Topological ordering exist ?
Time complexity of the algorithm: ?
18
Is empty ?
 a vertex with
in-degree = 0
 num;
num  num + 1;
Remove and all its
outgoing edges;
NO
Yes
Input ;
num 1;
A valid
time
HOW EFFICIENTLY CAN WE COMPUTE
TOPOLOGICAL ORDERING ?
19
Important Questions
Aim:
To design a more efficient implementation of the algorithm.
Question:
What is the most time consuming step of the algorithm ?
Answer: Searching a vertex of in-degree = 0 ?
Question:
Do we need to compute from scratch the next vertex of in-degree 0 every time ?
Answer: Perhaps not !
20
Let us explore closely the algorithm to see
“how and when the vertices with in-degree=0 get created” ?
Revisiting the example
The new vertices with indegree=0 are created during ?
21
z
w
y
u
a
x
v
u v a
b
b w
x z y
1 2 3 4 5 6 7 8
..but slowly this time…
the processing of the current vertex of indegree=0
Algorithm for Topological ordering ?
Question:
How to design a more efficient implementation of the algorithm ?
Main step of the current algorithm:
• Searching a vertex of in-degree = 0
Hints:
1. Maintain a set of vertices of In-degree=0
2. Keep an array In-degree[] that stores for each vertex the number of edges
entering it at any stage during the algorithm.
22
time.
Attempt as a Homework.
APPLICATIONS OF
TOPOLOGICAL ORDERING ?
23
Example: Single source shortest paths
: the distance from source .
=0;
=
A correct formulation for distances from in a directed graph.
But difficult to translate to algorithms for general graphs.
Ponder over it.
24
But, this formulation leads to a very simple and
efficient algorithm for distance in DAGs.
Now ponder over it.
Topological ordering
A mapping : [] such that
For each edge , () < ()
1 2 3 4 5 6 7 8 9 10 11
Applications of Topological ordering
I
A mapping : [] such that
For each edge , () < ()
Let be a function on that we wish to compute
If can be expressed in terms of ONLY
We can compute by processing vertices in increasing order of .
1 2 3 4 5 6 7 8 9 10 11
𝒚
It is useful to compute in this order
Applications of Topological ordering
I
A mapping : [] such that
For each edge , () < ()
Example: Single source shortest paths
: the distance from source .
=0;
=
1 2 3 4 5 6 7 8 9 10 11
𝒚
It is useful to compute in this order
time algo
Applications of Topological ordering
II
A mapping : [] such that
For each edge , () < ()
Let be a function on that we wish to compute
If can be expressed in terms of ONLY
We can compute by processing vertices in decreasing order of .
1 2 3 4 5 6 7 8 9 10 11
𝒚
It is useful to compute in this order
Applications of Topological ordering
II
A mapping : [] such that
For each edge , () < ()
Example: Number of paths to a vertex
: the number of paths to .
=1;
=
1 2 3 4 5 6 7 8 9 10 11
𝒚
time algo
It is useful to compute in this order
Homework
Design an time algorithm for the following problem:
Given a directed acyclic graph , and a sequence of vertices ,
does there exist a path in which looks like :
30
Moral of the story
Think of a problem on DAG
 Think of topological ordering

31
Ad

Recommended

PPTX
Design and Analysis of Algorithms Lecture Notes
Sreedhar Chowdam
 
PDF
DAA Notes.pdf
SauravPawar14
 
PPT
Mit15 082 jf10_lec01
Saad Liaqat
 
PDF
Lecture 16 - Dijkstra's Algorithm.pdf
iftakhar8
 
PPTX
Linear Programming- Leacture-16-lp1.pptx
SarahKoech1
 
PPT
Lecture 1 and 2 of Data Structures & Algorithms
haseebanjum2611
 
PPTX
Bidirectional graph search techniques for finding shortest path in image base...
Navin Kumar
 
PPTX
Asymptotic Notations
Rishabh Soni
 
PDF
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
 
PPT
36 greedy
Ikram Khan
 
DOCX
IntroductionTopological sorting is a common operation performed .docx
mariuse18nolet
 
PPTX
Asymptotics 140510003721-phpapp02
mansab MIRZA
 
PPTX
ICPC 2015, Tsukuba : Unofficial Commentary
irrrrr
 
PPTX
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
PPTX
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
PDF
A greedy algorithms
Amit Kumar Rathi
 
PPTX
Searching Algorithms
Afaq Mansoor Khan
 
PPTX
Asymptotic Notations.pptx
SunilWork1
 
PPTX
DS Unit-1.pptx very easy to understand..
KarthikeyaLanka1
 
PDF
Parallelising Dynamic Programming
Raphael Reitzig
 
PPTX
L1_Start_of_Learning_of_Algorithms_Basics.pptx
3cL1Ps3FTMS
 
PDF
Algorithms of graph
getacew
 
PPTX
L1_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
 
PDF
Algorithm Design and Analysis
Sayed Chhattan Shah
 
PDF
Data Structure & Algorithms - Mathematical
babuk110
 
PPTX
Network Design Assignment Help
Computer Network Assignment Help
 
PPTX
Algorithms Exam Help
Programming Exam Help
 
PPTX
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
 
PPTX
DEsign and Analysis of ALgorithms slides of lecture 1, 2 and 3
ssuser9183b6
 
PPTX
Lecture-13-CS345A-2023 of Design and Analysis
ssuser9183b6
 

More Related Content

Similar to Lecture-12-CS345A-2023 of Design and Analysis (20)

PDF
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
 
PPT
36 greedy
Ikram Khan
 
DOCX
IntroductionTopological sorting is a common operation performed .docx
mariuse18nolet
 
PPTX
Asymptotics 140510003721-phpapp02
mansab MIRZA
 
PPTX
ICPC 2015, Tsukuba : Unofficial Commentary
irrrrr
 
PPTX
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
PPTX
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
PDF
A greedy algorithms
Amit Kumar Rathi
 
PPTX
Searching Algorithms
Afaq Mansoor Khan
 
PPTX
Asymptotic Notations.pptx
SunilWork1
 
PPTX
DS Unit-1.pptx very easy to understand..
KarthikeyaLanka1
 
PDF
Parallelising Dynamic Programming
Raphael Reitzig
 
PPTX
L1_Start_of_Learning_of_Algorithms_Basics.pptx
3cL1Ps3FTMS
 
PDF
Algorithms of graph
getacew
 
PPTX
L1_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
 
PDF
Algorithm Design and Analysis
Sayed Chhattan Shah
 
PDF
Data Structure & Algorithms - Mathematical
babuk110
 
PPTX
Network Design Assignment Help
Computer Network Assignment Help
 
PPTX
Algorithms Exam Help
Programming Exam Help
 
PPTX
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
 
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
 
36 greedy
Ikram Khan
 
IntroductionTopological sorting is a common operation performed .docx
mariuse18nolet
 
Asymptotics 140510003721-phpapp02
mansab MIRZA
 
ICPC 2015, Tsukuba : Unofficial Commentary
irrrrr
 
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
A greedy algorithms
Amit Kumar Rathi
 
Searching Algorithms
Afaq Mansoor Khan
 
Asymptotic Notations.pptx
SunilWork1
 
DS Unit-1.pptx very easy to understand..
KarthikeyaLanka1
 
Parallelising Dynamic Programming
Raphael Reitzig
 
L1_Start_of_Learning_of_Algorithms_Basics.pptx
3cL1Ps3FTMS
 
Algorithms of graph
getacew
 
L1_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
 
Algorithm Design and Analysis
Sayed Chhattan Shah
 
Data Structure & Algorithms - Mathematical
babuk110
 
Network Design Assignment Help
Computer Network Assignment Help
 
Algorithms Exam Help
Programming Exam Help
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
 

More from ssuser9183b6 (8)

PPTX
DEsign and Analysis of ALgorithms slides of lecture 1, 2 and 3
ssuser9183b6
 
PPTX
Lecture-13-CS345A-2023 of Design and Analysis
ssuser9183b6
 
PPTX
Lecture-11-CS345A-2023 of Design and Analysis
ssuser9183b6
 
PPTX
Lecture-7-CS345A-2023 of Design and Analysis
ssuser9183b6
 
PPTX
Lecture-8-CS345A-2023 of Design and Analysis
ssuser9183b6
 
PPTX
Lecture-10-CS345A-2023 of Design and Analysis
ssuser9183b6
 
PPTX
Lecture-7-CS345A-2023 of Design and Analysis
ssuser9183b6
 
PPTX
DiscreteMathematicsfor btechAsWeProgress.pptx
ssuser9183b6
 
DEsign and Analysis of ALgorithms slides of lecture 1, 2 and 3
ssuser9183b6
 
Lecture-13-CS345A-2023 of Design and Analysis
ssuser9183b6
 
Lecture-11-CS345A-2023 of Design and Analysis
ssuser9183b6
 
Lecture-7-CS345A-2023 of Design and Analysis
ssuser9183b6
 
Lecture-8-CS345A-2023 of Design and Analysis
ssuser9183b6
 
Lecture-10-CS345A-2023 of Design and Analysis
ssuser9183b6
 
Lecture-7-CS345A-2023 of Design and Analysis
ssuser9183b6
 
DiscreteMathematicsfor btechAsWeProgress.pptx
ssuser9183b6
 
Ad

Recently uploaded (20)

PPTX
Industrial internet of things IOT Week-3.pptx
KNaveenKumarECE
 
PPTX
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
 
PPTX
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
PPTX
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
resming1
 
PDF
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
PPTX
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
 
PPTX
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
PPTX
DESIGN OF REINFORCED CONCRETE ELEMENTS S
prabhusp8
 
PDF
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
PDF
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
PDF
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
PDF
Modern multi-proposer consensus implementations
François Garillot
 
PPTX
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
PPTX
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
PDF
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
PPTX
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
PDF
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
PPTX
Introduction to sensing and Week-1.pptx
KNaveenKumarECE
 
PPTX
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
SAMEER VISHWAKARMA
 
PPTX
Introduction to Python Programming Language
merlinjohnsy
 
Industrial internet of things IOT Week-3.pptx
KNaveenKumarECE
 
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
resming1
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
 
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
DESIGN OF REINFORCED CONCRETE ELEMENTS S
prabhusp8
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
Modern multi-proposer consensus implementations
François Garillot
 
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
Introduction to sensing and Week-1.pptx
KNaveenKumarECE
 
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
SAMEER VISHWAKARMA
 
Introduction to Python Programming Language
merlinjohnsy
 
Ad

Lecture-12-CS345A-2023 of Design and Analysis

  • 1. Design and Analysis of Algorithms Lecture 12 • Algorithms 1 CS345A for Directed Acyclic Graphs
  • 2. Recap of last lecture 2
  • 3. Problem Definition Input: A directed graph with and a source vertex Aim: • Compute the shortest path to for all Theorem: There exists an time algorithm to build size data structure that compactly stores shortest path to for all 3 Longest path to each vertex ? No polynomial time algorithm till date !
  • 4. Imagine there were no research in Algorithms. And you are asked to write a program to compute shortest paths from source s to every vertex. Your first attempt would have been to enumerate all paths from source and then report the path which is shortest. But the number of paths from source to any vertex can be exponential. So you would have felt the hardness of the shortest paths problem. May be (if you were like Dijkstra) you would have worked hard and with perseverance and designed the algorithm which we call Dijkstra’s algorithm today. But consider the situation now when the area of algorithm is quite developed ( very active for more than 50 years). But the best algorithm the researchers have designed till date for the longest paths problem takes exponential time ! What would be your reaction to this reality ? • Frustration, feeling down ? (not good for a person with true scientific spirit) • Curiosity (natural) There are hundreds of such algorithmic problems in computer science for which the fastest algorithm takes only exponential time. Towards the end of this course, we shall discuss a theory of such a family of problems. “Theory of NP complete problems” With this note, we begin today’s lecture. 4
  • 6. Directed Acyclic Graphs Question: what is a cycle in ? Answer: A sequence , ,…, such that (,) for all and (,) . 6 𝒗 𝟏 𝒗 𝟐 𝒗 𝟑 𝒗𝒌 −𝟏 𝒗 𝒌 …
  • 7. Directed Acyclic Graphs Definition: A directed graph is said to be acyclic if there is no cycle present in it. Example: 7 z u b v x w a y DAG
  • 8. Topological ordering Definition: a mapping : [] such that for each edge () < () Theorem: There exists a topological ordering for every DAG. 1 2 3 4 5 6 7 8 9 10 11 Does there exist a topological ordering for every directed graph ? Certainly No if there is any cycle < < < < < < > Is it possible to arrange vertices in a line so that each edge goes from left to right ? How to formalize it ?
  • 9. Topological ordering Example: This is indeed a valid topological ordering. 9 z u b v x w a y u v a b w x z y 1 2 3 4 5 6 7 8 How efficiently can we determine if a given mapping is indeed a topological ordering ? O() time
  • 10. Topological ordering Three questions Question 1: Why does a topological ordering exist for every DAG ? Question 2: How efficiently can we compute a topological ordering ? Question 3: What is the use of topological ordering ? 10
  • 12. Applications of Topological ordering Almost every algorithmic problem on DAG exploits Topological ordering. Examples: • Single source shortest paths (No need of Dijkstra’s algorithm) • Single source longest paths • Count no. of paths from a source to a destination (If the no. is a polynomial of ) All these problems have a simple time algorithm for DAG 12
  • 13. WHY DOES TOPOLOGICAL ORDERING EXIST FOR EVERY DAG? Question 1 13
  • 14. Why does Topological ordering exist ? Example: 14 z u b v x w a y Is there any vertex for which you can be sure of its place in the ordering? Any vertex of indegree=0 can be given number 1 in a topological ordering. What is the guarantee that such a vertex always exists in a DAG ?
  • 15. Why does Topological ordering exist ? Lemma 1: Every DAG has at least one vertex with in-degree = 0. Proof: (an algorithmic proof) Pick any vertex . While in-degree 0 do { Let be an edge  ; } return ; Observation: This algorithm, if terminates will output a vertex of indegree =0. 15 a c x c … b y cycle But what is the guarantee that it will terminate.? The algorithm does indeed terminate. In fact, no vertex will be processed twice in while loop.
  • 16. Why does Topological ordering exist ? Lemma 1: Every DAG has at least one vertex with in-degree = 0. 16 z u b v x w a y How to use Lemma 1 to show existence of a valid ?
  • 17. Why does Topological ordering exist ? 17 z w y u a x v u v a b b w x z y 1 2 3 4 5 6 7 8
  • 18. Why does Topological ordering exist ? Time complexity of the algorithm: ? 18 Is empty ?  a vertex with in-degree = 0  num; num  num + 1; Remove and all its outgoing edges; NO Yes Input ; num 1; A valid time
  • 19. HOW EFFICIENTLY CAN WE COMPUTE TOPOLOGICAL ORDERING ? 19
  • 20. Important Questions Aim: To design a more efficient implementation of the algorithm. Question: What is the most time consuming step of the algorithm ? Answer: Searching a vertex of in-degree = 0 ? Question: Do we need to compute from scratch the next vertex of in-degree 0 every time ? Answer: Perhaps not ! 20 Let us explore closely the algorithm to see “how and when the vertices with in-degree=0 get created” ?
  • 21. Revisiting the example The new vertices with indegree=0 are created during ? 21 z w y u a x v u v a b b w x z y 1 2 3 4 5 6 7 8 ..but slowly this time… the processing of the current vertex of indegree=0
  • 22. Algorithm for Topological ordering ? Question: How to design a more efficient implementation of the algorithm ? Main step of the current algorithm: • Searching a vertex of in-degree = 0 Hints: 1. Maintain a set of vertices of In-degree=0 2. Keep an array In-degree[] that stores for each vertex the number of edges entering it at any stage during the algorithm. 22 time. Attempt as a Homework.
  • 24. Example: Single source shortest paths : the distance from source . =0; = A correct formulation for distances from in a directed graph. But difficult to translate to algorithms for general graphs. Ponder over it. 24 But, this formulation leads to a very simple and efficient algorithm for distance in DAGs. Now ponder over it.
  • 25. Topological ordering A mapping : [] such that For each edge , () < () 1 2 3 4 5 6 7 8 9 10 11
  • 26. Applications of Topological ordering I A mapping : [] such that For each edge , () < () Let be a function on that we wish to compute If can be expressed in terms of ONLY We can compute by processing vertices in increasing order of . 1 2 3 4 5 6 7 8 9 10 11 𝒚 It is useful to compute in this order
  • 27. Applications of Topological ordering I A mapping : [] such that For each edge , () < () Example: Single source shortest paths : the distance from source . =0; = 1 2 3 4 5 6 7 8 9 10 11 𝒚 It is useful to compute in this order time algo
  • 28. Applications of Topological ordering II A mapping : [] such that For each edge , () < () Let be a function on that we wish to compute If can be expressed in terms of ONLY We can compute by processing vertices in decreasing order of . 1 2 3 4 5 6 7 8 9 10 11 𝒚 It is useful to compute in this order
  • 29. Applications of Topological ordering II A mapping : [] such that For each edge , () < () Example: Number of paths to a vertex : the number of paths to . =1; = 1 2 3 4 5 6 7 8 9 10 11 𝒚 time algo It is useful to compute in this order
  • 30. Homework Design an time algorithm for the following problem: Given a directed acyclic graph , and a sequence of vertices , does there exist a path in which looks like : 30
  • 31. Moral of the story Think of a problem on DAG  Think of topological ordering  31