mirror of
https://github.com/dholerobin/Lecture_Notes.git
synced 2025-07-01 13:06:29 +00:00
Update Topological-Sort.md
This commit is contained in:
parent
993d8529b0
commit
c35132ae80
@ -20,7 +20,7 @@ Topological Sort is the sorting of the vertices in such a way that, for any two
|
|||||||
|
|
||||||
$a,b,c,d,e$ is the topologically ordering for the graph below.
|
$a,b,c,d,e$ is the topologically ordering for the graph below.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Quiz Time
|
## Quiz Time
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ $Q.1$ Is it always possible to find out the topological sort?
|
|||||||
|
|
||||||
No. Whenever there is a cycle in a graph we can not find it. See the image below:
|
No. Whenever there is a cycle in a graph we can not find it. See the image below:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
We can not find proper dependency between any two vertices, becuase each of them are interdependent.
|
We can not find proper dependency between any two vertices, becuase each of them are interdependent.
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ So the condition for the topological sort is, the graph must be a DAG - Directed
|
|||||||
$Q.2$ Does topological sort give a unique ordering of the vertices?
|
$Q.2$ Does topological sort give a unique ordering of the vertices?
|
||||||
|
|
||||||
No, it is not unique in every case, because we can find many orderings which satisfies the condition of the topological sort.
|
No, it is not unique in every case, because we can find many orderings which satisfies the condition of the topological sort.
|
||||||

|

|
||||||
|
|
||||||
In the graph shown in the image above, $b,a,c,d,e$ and $a,b,c,d,e$ both are valid topological sorts.
|
In the graph shown in the image above, $b,a,c,d,e$ and $a,b,c,d,e$ both are valid topological sorts.
|
||||||
|
|
||||||
@ -57,13 +57,13 @@ We will use the indegree of vertices to find the topological ordering. How? Let'
|
|||||||
|
|
||||||
In the image below, the number in the square bracket represents indegree for a vertex near to it.
|
In the image below, the number in the square bracket represents indegree for a vertex near to it.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
As we have seen the topological ordering for the above graph is $a,b,c,d,e$. Now, what is your observation?
|
As we have seen the topological ordering for the above graph is $a,b,c,d,e$. Now, what is your observation?
|
||||||
|
|
||||||
See that the vertices having indegree $0$ are appearing first in the ordering. But what next? What if we remove both the vertices and all the edges coming out from it?
|
See that the vertices having indegree $0$ are appearing first in the ordering. But what next? What if we remove both the vertices and all the edges coming out from it?
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
See now, $c$ is the vertex having $0$ indegree, which is appearning next in the ordering.
|
See now, $c$ is the vertex having $0$ indegree, which is appearning next in the ordering.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user