SlideShare a Scribd company logo
1 of 10
TOPOLOICAL SORT
By Sahil Narvekar
Graph
 A graph is an abstract data type that is meant to
implement the undirected graph and directed
graph concepts from mathematics.
 A graph data structure consists of a finite set of
vertices or nodes or points, together with a set
of unordered pairs of these vertices for an
undirected graph or a set of ordered pairs for a
directed graph.
 These pairs are known as edges, arcs, or
lines for an undirected graph and as arrows,
directed edges, directed arcs, or directed
lines for a directed graph.
Directed graph
Undirected graph
Application of Graph
1) Topological Sorting.
2) Neural networks.
Vertices represent neurons and edges the synapses between them. Neural
networks are used to understand how our brain works and how connections
change when we learn. The human brain has about 1011 neurons and close
to 1015 synapses.
3) Robot planning.
Vertices represent states the robot can be in and the edges the possible
transitions between the states. This requires approximating continuous
motion as a sequence of discrete steps. Such graph plans are used, for
example, in planning paths for autonomous vehicles
Topological Sorting
 A topological sort or topological ordering of a directed graph
is a linear ordering of its vertices such that for every
directed edge uv from vertex u to vertex v, u comes before
v in the ordering.
 The vertices of the graph may represent tasks to be
performed, and the edges may represent constraints that
one task must be performed before another.
 A topological ordering is just a valid sequence for the tasks.
 A topological ordering is possible if and only if the graph has
no directed cycles, that is, if it is a directed acyclic graph
(DAG).
 Any DAG has at least one topological ordering, and
algorithms are known for constructing a topological ordering
of any DAG in linear time.
Algorithm
 Compute the indegrees of all vertices
 Find a vertex U with indegrees 0 and print it (store it in
the ordering)
 If there is no such vertex then there is a cycle
and the vertices cannot be ordered. Stop.
 Remove U and all its edges (U,V) from the graph.
 Update the indegrees of the remaining vertices.
 Repeat steps 2 through 4 while there are vertices to be
processed.
Topological Sort :-5 4 2 3 1 0
Application of topological
sort
 Scheduling jobs from the given dependencies among
jobs.
 Ordering of formula cell evaluation when re-computing
formula values in spreadsheets.
 Logic synthesis.
 Data serialization.
 Build Systems
Topoloical sort

More Related Content

What's hot

presentation
presentationpresentation
presentationjie ren
 
Topological Sort
Topological SortTopological Sort
Topological SortMdAlAmin187
 
ANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series PredictionANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series PredictionM Baddar
 
Geographic Information Systems (April – 2015) [Question Paper | IDOL: Revised...
Geographic Information Systems (April – 2015) [Question Paper | IDOL: Revised...Geographic Information Systems (April – 2015) [Question Paper | IDOL: Revised...
Geographic Information Systems (April – 2015) [Question Paper | IDOL: Revised...Mumbai B.Sc.IT Study
 
Discrete Mathematics Presentation
Discrete Mathematics PresentationDiscrete Mathematics Presentation
Discrete Mathematics PresentationSalman Elahi
 
Petri nets by Barkatllah
Petri nets by BarkatllahPetri nets by Barkatllah
Petri nets by BarkatllahBarkat Ullah
 
Convolution using Scilab
Convolution using ScilabConvolution using Scilab
Convolution using Scilabsachin achari
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithmsguest084d20
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithmami_01
 
connecting discrete mathematics and software engineering
connecting discrete mathematics and software engineeringconnecting discrete mathematics and software engineering
connecting discrete mathematics and software engineeringRam Kumar K R
 
Geographic Information Systems (December - 2018) [IDOL - Revised Course]
Geographic Information Systems (December - 2018) [IDOL - Revised Course]Geographic Information Systems (December - 2018) [IDOL - Revised Course]
Geographic Information Systems (December - 2018) [IDOL - Revised Course]Mumbai B.Sc.IT Study
 
Transformation of Random variables & noise concepts
Transformation of Random variables & noise concepts Transformation of Random variables & noise concepts
Transformation of Random variables & noise concepts Darshan Bhatt
 
Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithmmansab MIRZA
 
Software of Time Series Forecasting based on Combinations of Fuzzy and Statis...
Software of Time Series Forecasting based on Combinations of Fuzzy and Statis...Software of Time Series Forecasting based on Combinations of Fuzzy and Statis...
Software of Time Series Forecasting based on Combinations of Fuzzy and Statis...ITIIIndustries
 

What's hot (20)

presentation
presentationpresentation
presentation
 
Topological Sort
Topological SortTopological Sort
Topological Sort
 
Topological sort
Topological sortTopological sort
Topological sort
 
ANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series PredictionANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series Prediction
 
Geographic Information Systems (April – 2015) [Question Paper | IDOL: Revised...
Geographic Information Systems (April – 2015) [Question Paper | IDOL: Revised...Geographic Information Systems (April – 2015) [Question Paper | IDOL: Revised...
Geographic Information Systems (April – 2015) [Question Paper | IDOL: Revised...
 
Discrete Mathematics Presentation
Discrete Mathematics PresentationDiscrete Mathematics Presentation
Discrete Mathematics Presentation
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Petri nets by Barkatllah
Petri nets by BarkatllahPetri nets by Barkatllah
Petri nets by Barkatllah
 
Convolution using Scilab
Convolution using ScilabConvolution using Scilab
Convolution using Scilab
 
A new radix 4 fft algorithm
A new radix 4 fft algorithmA new radix 4 fft algorithm
A new radix 4 fft algorithm
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithm
 
connecting discrete mathematics and software engineering
connecting discrete mathematics and software engineeringconnecting discrete mathematics and software engineering
connecting discrete mathematics and software engineering
 
Shortest path algorithm
Shortest  path algorithmShortest  path algorithm
Shortest path algorithm
 
Cad for vlsi design june2013 (2)
Cad for vlsi design june2013 (2)Cad for vlsi design june2013 (2)
Cad for vlsi design june2013 (2)
 
Geographic Information Systems (December - 2018) [IDOL - Revised Course]
Geographic Information Systems (December - 2018) [IDOL - Revised Course]Geographic Information Systems (December - 2018) [IDOL - Revised Course]
Geographic Information Systems (December - 2018) [IDOL - Revised Course]
 
Transformation of Random variables & noise concepts
Transformation of Random variables & noise concepts Transformation of Random variables & noise concepts
Transformation of Random variables & noise concepts
 
Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithm
 
Software of Time Series Forecasting based on Combinations of Fuzzy and Statis...
Software of Time Series Forecasting based on Combinations of Fuzzy and Statis...Software of Time Series Forecasting based on Combinations of Fuzzy and Statis...
Software of Time Series Forecasting based on Combinations of Fuzzy and Statis...
 
Blue print
Blue printBlue print
Blue print
 

Similar to Topoloical sort

Similar to Topoloical sort (20)

data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
Vanmathy no sql
Vanmathy no sql Vanmathy no sql
Vanmathy no sql
 
VANU no sql ppt.pptx
VANU no sql ppt.pptxVANU no sql ppt.pptx
VANU no sql ppt.pptx
 
Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ program
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
Topological Sort and Shortest Path in Directed Acyclic Graph with Single Source
Topological Sort and Shortest Path in Directed Acyclic Graph with Single SourceTopological Sort and Shortest Path in Directed Acyclic Graph with Single Source
Topological Sort and Shortest Path in Directed Acyclic Graph with Single Source
 
Graphs
GraphsGraphs
Graphs
 
Regularity and complexity in dynamical systems
Regularity and complexity in dynamical systemsRegularity and complexity in dynamical systems
Regularity and complexity in dynamical systems
 
CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1
 
Graph 1
Graph 1Graph 1
Graph 1
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
POLAR PLOT (1).pptx
POLAR PLOT (1).pptxPOLAR PLOT (1).pptx
POLAR PLOT (1).pptx
 
POLAR PLOT.pptx
POLAR PLOT.pptxPOLAR PLOT.pptx
POLAR PLOT.pptx
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

Topoloical sort

  • 2. Graph  A graph is an abstract data type that is meant to implement the undirected graph and directed graph concepts from mathematics.  A graph data structure consists of a finite set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph.  These pairs are known as edges, arcs, or lines for an undirected graph and as arrows, directed edges, directed arcs, or directed lines for a directed graph.
  • 5. Application of Graph 1) Topological Sorting. 2) Neural networks. Vertices represent neurons and edges the synapses between them. Neural networks are used to understand how our brain works and how connections change when we learn. The human brain has about 1011 neurons and close to 1015 synapses. 3) Robot planning. Vertices represent states the robot can be in and the edges the possible transitions between the states. This requires approximating continuous motion as a sequence of discrete steps. Such graph plans are used, for example, in planning paths for autonomous vehicles
  • 6. Topological Sorting  A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering.  The vertices of the graph may represent tasks to be performed, and the edges may represent constraints that one task must be performed before another.  A topological ordering is just a valid sequence for the tasks.  A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph (DAG).  Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of any DAG in linear time.
  • 7. Algorithm  Compute the indegrees of all vertices  Find a vertex U with indegrees 0 and print it (store it in the ordering)  If there is no such vertex then there is a cycle and the vertices cannot be ordered. Stop.  Remove U and all its edges (U,V) from the graph.  Update the indegrees of the remaining vertices.  Repeat steps 2 through 4 while there are vertices to be processed.
  • 9. Application of topological sort  Scheduling jobs from the given dependencies among jobs.  Ordering of formula cell evaluation when re-computing formula values in spreadsheets.  Logic synthesis.  Data serialization.  Build Systems