filmov
tv
LeetCode 207 & 210: Course Schedule I & II | Topological Sort | Kahn's algorithm - Interview Ep 78
![preview_player](https://i.ytimg.com/vi/2l22FRtU45M/maxresdefault.jpg)
Показать описание
This is a very popular, practical algorithm which could be used in quite a few places.
⭐ Support my channel and connect with me:
Problem link on LeetCode:
Algorithm explained:
we first find a set of vertices that don't have any incoming edges;
then we loop through these vertices to remove any edges using them as incoming vertices;
along the way, if we find other vertices don't have any incoming edges any more, we'll add them into this set as well;
until this set becomes empty, we break out of this loop;
then we check if there are still any edges there, if so, this is a DAG (Directed Acyclic Graph), it's impossible to find such a topological ordering.
Otherwise, return the order.
Time complexity: O(V+E) (V is the number of vertices and E is the number of edges in the given graph)
// TOOLS THAT I USE:
// MY FAVORITE BOOKS:
My ENTIRE Programming Equipment and Computer Science Bookshelf:
And make sure you subscribe to my channel!
Your comments/thoughts/questions/advice will be greatly appreciated!
#Kahnsalgorithm #graphsearch #topologicalsorting #softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures
Комментарии