Explore tens of thousands of sets crafted by our community.
Topological Sorting
5
Flashcards
0/5
Definition of Topological Sort
A topological sort is a linear ordering of the vertices of a directed graph such that for every directed edge UV from vertex U to vertex V, U comes before V in the ordering. It's used in scheduling tasks, organizing dependencies, and resolving symbol dependencies in linkers.
Applications of Topological Sorting
Topological sorting is used in various applications like scheduling jobs, course prerequisite planning, resolving dependencies in build systems like Makefiles, and ordering tasks to avoid conflicts.
Kahn's Algorithm
Kahn's Algorithm is a famous algorithm for topological sorting. It involves initializing a queue with vertices that have no incoming edges and then repeatedly removing vertices from the queue and their outgoing edges until the queue is empty.
Conditions for Topological Sorting
Topological sorting can only be performed on a Directed Acyclic Graph (DAG). If a graph has a cycle, then a valid topological order does not exist.
Depth-First Search (DFS) Approach
DFS can be used to perform a topological sort by visiting vertices recursively and adding each vertex to the front of a list after visiting all descendants. It uses a 'post-order' traversal to achieve the sort.
© Hypatia.Tech. 2024 All rights reserved.