LeetCode 207 & 210: Course Schedule I & II | Topological Sort | Kahn's algorithm - Interview Ep 78
In this video, we walk through this well known topological sorting algorithm: https://en.wikipedia.org/wiki/Topological_sorting.
This is a very popular, practical algorithm which could be used in quite a few places.
⭐ Support my channel and connect with me:
https://www.youtube.com/channel/UCPL5uAbYQ40HwAdOe4ikI0w/join
Problem link on LeetCode:
Course Schedule: https://leetcode.com/problems/course-schedule/
Course Schedule II: https://leetcode.com/problems/course-schedule-ii/
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 - https://amzn.to/3cOGOAj
○ Electric Height Adjustable Standing Desk - https://amzn.to/2S9YexJ
○ Apple Magic Keyboard (Wireless, Rechargable) - https://amzn.to/36gy5FJ
○ Apple Magic Trackpad 2 (Wireless, Rechargable) - https://amzn.to/36ltimu
○ Apple MacBook Pro - https://amzn.to/30iSvKE
○ All-In One Printer - https://amzn.to/34etmSi
○ Apple AirPods Pro - https://amzn.to/2GpVYQf
○ My new favorite Apple Watch - https://amzn.to/2EIIUFd
// MY FAVORITE BOOKS:
○ Introduction to Algorithms - https://amzn.to/36hxHXD
○ Designing Data-Intensive Applications - https://amzn.to/2S7snOg
○ Head First Java - https://amzn.to/2ScLDKa
○ Design Patterns - https://amzn.to/2SaGeU2
Follow me on Github for complete LeetCode solutions: https://github.com/fishercoder1534/Leetcode
Support me on Patreon: https://www.patreon.com/fishercoder
My ENTIRE Programming Equipment and Computer Science Bookshelf:
https://www.amazon.com/shop/fishercoder
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
Видео LeetCode 207 & 210: Course Schedule I & II | Topological Sort | Kahn's algorithm - Interview Ep 78 канала Fisher Coder
This is a very popular, practical algorithm which could be used in quite a few places.
⭐ Support my channel and connect with me:
https://www.youtube.com/channel/UCPL5uAbYQ40HwAdOe4ikI0w/join
Problem link on LeetCode:
Course Schedule: https://leetcode.com/problems/course-schedule/
Course Schedule II: https://leetcode.com/problems/course-schedule-ii/
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 - https://amzn.to/3cOGOAj
○ Electric Height Adjustable Standing Desk - https://amzn.to/2S9YexJ
○ Apple Magic Keyboard (Wireless, Rechargable) - https://amzn.to/36gy5FJ
○ Apple Magic Trackpad 2 (Wireless, Rechargable) - https://amzn.to/36ltimu
○ Apple MacBook Pro - https://amzn.to/30iSvKE
○ All-In One Printer - https://amzn.to/34etmSi
○ Apple AirPods Pro - https://amzn.to/2GpVYQf
○ My new favorite Apple Watch - https://amzn.to/2EIIUFd
// MY FAVORITE BOOKS:
○ Introduction to Algorithms - https://amzn.to/36hxHXD
○ Designing Data-Intensive Applications - https://amzn.to/2S7snOg
○ Head First Java - https://amzn.to/2ScLDKa
○ Design Patterns - https://amzn.to/2SaGeU2
Follow me on Github for complete LeetCode solutions: https://github.com/fishercoder1534/Leetcode
Support me on Patreon: https://www.patreon.com/fishercoder
My ENTIRE Programming Equipment and Computer Science Bookshelf:
https://www.amazon.com/shop/fishercoder
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
Видео LeetCode 207 & 210: Course Schedule I & II | Topological Sort | Kahn's algorithm - Interview Ep 78 канала Fisher Coder
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Course Schedule - Graph Adjacency List - Leetcode 207](https://i.ytimg.com/vi/EgI5nU9etnU/default.jpg)
![How to Crack Technical Interviews and Advance Your Career - Career Coaching Session by Paul Huang](https://i.ytimg.com/vi/DiOTbkLZeK0/default.jpg)
![Topological Sort Graph | Leetcode 207 | Course Schedule](https://i.ytimg.com/vi/rG2-_lgcZzo/default.jpg)
![Trie Data Structure Implementation (LeetCode)](https://i.ytimg.com/vi/giiaIofn31A/default.jpg)
![LeetCode 207 & 210: Course Schedule I & II | Topological Sort | Kahn's algorithm - Interview Ep 78.2](https://i.ytimg.com/vi/IWLpZbu1wco/default.jpg)
![AMAZON CODING INTERVIEW QUESTION - PARTITION LABELS (LeetCode)](https://i.ytimg.com/vi/ED4ateJu86I/default.jpg)
![14. Depth-First Search (DFS), Topological Sort](https://i.ytimg.com/vi/AfSk24UTFS8/default.jpg)
![LeetCode 220: Contains Duplicate III - Interview Prep Ep 47](https://i.ytimg.com/vi/Cu7g9ovYHNI/default.jpg)
![A Cambridge Interview: Queens' Computer Science](https://i.ytimg.com/vi/a7XwKVCBPfM/default.jpg)
![AMAZON - MINIMUM PATH SUM (LeetCode)](https://i.ytimg.com/vi/ItjZdu6jEMs/default.jpg)
![LeetCode 957. Prison Cells After N Days - Interview Prep Ep 81](https://i.ytimg.com/vi/mQQp6I985bw/default.jpg)
![LeetCode 1138. Alphabet Board Path - Interview Prep Ep 105](https://i.ytimg.com/vi/rk-aB4rEOyU/default.jpg)
![How to: Work at Google — Example Coding/Engineering Interview](https://i.ytimg.com/vi/XKu_SEDAykw/default.jpg)
![LeetCode 1490. Clone N-ary Tree - Interview Prep Ep 110](https://i.ytimg.com/vi/3Wnja3Bxeos/default.jpg)
![LeetCode 1657. Determine if Two Strings Are Close - Interview Prep Ep 100](https://i.ytimg.com/vi/-jXQK-UeChU/default.jpg)
![Course Schedule | Deadlock detection | Graph coloring | Leetcode #207](https://i.ytimg.com/vi/kXy0ABd1vwo/default.jpg)
![Course Schedule - LeetCode May 29 Challenge](https://i.ytimg.com/vi/j8QHeOg670M/default.jpg)
![Amazon Coding Interview Question - Clone Graph (LeetCode)](https://i.ytimg.com/vi/e5tNvT1iUXs/default.jpg)
![My Video Went Viral. Here's Why](https://i.ytimg.com/vi/fHsa9DqmId8/default.jpg)
![GOOGLE CODING INTERVIEW QUESTION - HOUSE ROBBER (LeetCode)](https://i.ytimg.com/vi/xlvhyfcoQa4/default.jpg)