Topological sort is an algorithm that finds an ordering of tasks that respects their dependencies. It works by performing a depth-first search (DFS) on a directed graph where vertices represent tasks and edges represent dependencies. During DFS, each vertex is assigned a finishing time. The topological sort orders the tasks according to decreasing finishing time, so that all dependencies are satisfied. The algorithm runs in O(V+E) time, where V is the number of vertices and E is the number of edges.