Рет қаралды 4,074
⭐ Shop on Amazon to support me: www.amazon.com...
⭐ NordVPN to protect your online privacy: go.nordvpn.net...
⭐ NordPass to help manage all of your passwords: go.nordpass.io...
This is the 2nd part of topological sort talking about applying Kahn's algorithm to solve LeetCode problems.
Link to the full video: • Video
Problem link on LeetCode:
Course Schedule: leetcode.com/p...
Course Schedule II: leetcode.com/p...
⭐ Support my channel and connect with me:
/ @fishercoder
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:
○ Memory Foam Set Keyboard Wrist Rest Pad - amzn.to/3cOGOAj
○ Electric Height Adjustable Standing Desk - amzn.to/2S9YexJ
○ Apple Magic Keyboard (Wireless, Rechargable) - amzn.to/36gy5FJ
○ Apple Magic Trackpad 2 (Wireless, Rechargable) - amzn.to/36ltimu
○ Apple MacBook Pro - amzn.to/30iSvKE
○ All-In One Printer - amzn.to/34etmSi
○ Apple AirPods Pro - amzn.to/2GpVYQf
○ My new favorite Apple Watch - amzn.to/2EIIUFd
// MY FAVORITE BOOKS:
○ Introduction to Algorithms - amzn.to/36hxHXD
○ Designing Data-Intensive Applications - amzn.to/2S7snOg
○ Head First Java - amzn.to/2ScLDKa
○ Design Patterns - amzn.to/2SaGeU2
Follow me on Github for complete LeetCode solutions: github.com/fis...
Support me on Patreon: / fishercoder
My ENTIRE Programming Equipment and Computer Science Bookshelf:
www.amazon.com...
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