Learn how to implement graph algorithms and how to use them to solve coding challenges.

✏️ This course was developed by Alvin Zablan from Structy. Check out Alvin's channel:

🔗 Learn data structures and algorithms:

⭐️ Course Contents ⭐️

⌨️ (0:00:00) course introduction

⌨️ (0:02:23) graph basics

⌨️ (0:07:10) depth first and breadth first traversal

⌨️ (0:29:13) has path –

⌨️ (0:42:11) undirected path –

⌨️ (1:00:44) connected components count –

⌨️ (1:13:29) largest component –

⌨️ (1:24:03) shortest path –

⌨️ (1:39:36) island count –

⌨️ (1:58:52) minimum island –

⌨️ (2:12:05) outro

🎉 Thanks to our Champion and Sponsor supporters:

👾 Wong Voon jinq

👾 hexploitation

👾 Katia Moran

👾 BlckPhantom

👾 Nick Raker

👾 Otis Morgan

👾 DeezMaster

👾 Treehouse

👾 AppWrite

—

Learn to code for free and get a developer job:

Read hundreds of articles on programming:

And subscribe for new videos on technology every day:

Alvin the ProgrammerHey Programmers! Thanks for checking out the course and I hope you find it useful as you prepare for those tech interviews. If you enjoyed this content, be sure to check out Structy for more data structure and algorithm tutorials from me. Links in the description!

There I cover all of the common interview topics and you can code along and run test cases directly on the platform. You’ll also be able to find video walkthroughs for every problem in JavaScript and Python, (more language support coming soon!).

Cheers!

-Alvin

Zhoufeng ZhengHi, Alvin, your videos are great! I have learn a lot, thank you so much.

one more thing is that,

Is there a reason you are using object (‘{}’), instead of using hashMap?

Beefpuuopppk

Nikhil GuptaJust AweSome… thanks for another great lecture..

Asami TamYou are such an amazing educator and programmer. Thank you so much!

osagie osemwotahello please i need help…on the Largest Component question, i decided to not use the recursive method in my DFS function but i am stuck in a bug… Every single one of the test cases on structy works except the first…here is my code :

// Write a function, largestComponent, that takes in the adjacency list of an undirected graph. The function should return the size of the largest connected component in the graph.

const largestComponent = (graph) => {

let largest=0;

//keep a track of visited nodes

let visited = new Set();

// loop through the graph object

for (node in graph) {

if(visited.has(String(node))) continue;

let currentCount = DFS(graph, node, visited);

largest = Math.max(largest, currentCount);

}

return largest;

}

const DFS = (graph, node, visited) => {

let currentCount = 1;

let stack = [node];

while(!!stack.length){

let current = stack.pop();

for( neighbor of graph[current]){

if(visited.has(String(neighbor))) continue;

stack.push(neighbor);

visited.add(String(current));

currentCount++;

}

}

return currentCount;

}

console.log(largestComponent({

0: [‘8’, ‘1’, ‘5’],

1: [‘0’],

5: [‘0’, ‘8’],

8: [‘0’, ‘5’],

2: [‘3’, ‘4’],

3: [‘2’, ‘4’],

4: [‘3’, ‘2’]

}))

Varun ShridharThe course on DP was a winner. Course on Graph algo is another winner. Hope to learn a lot more from you.

Ziggy Stardust@Keerthi you are another winner for appreciating another winner

Tetrax@Ziggy Stardust you are a winner for appreciating a winner appreciating a winner

LDAR@Tetrax this recursive call stack gotta stop somewhere XD

Tetrax@LDAR let’s assume we’re on an alternate universe where leetcode doesn’t have a time limit

Varun Shrivastavaif no_of_comments >= 6:

return “Every One’s a winnner!”

Chris KorbelThis guy is phenomenal. His course on dynamic programming was exceptionally well done as well.

Zhoufeng ZhengAgreed

after that course, I am so confident on DP.

George G@Elad did you find the link?

OLIWEBI’d always been scared of learning graphs, even though I wanted to… but this course took my fear away 😎👍🏻 excelente course, as always!

Annant SharmaThanks for the video. To be honest, this is one of the best graph tutorials I have ever witnessed. My core concepts and understanding towards this Data Structure has improved and I really appreciate the efforts you have put in to make this video.🙏

Stephen MainaThis course is hands-down, unequivocally fantastic!!! Best useful course I’ve seen about graphs. It ties together the algorithms with concrete use cases which just clicked. Thank you for the fantastic job!!!!

Kanak MittalMan! you have my respect. This was the best course for getting started with graph problems I have ever seen. Thank You so much.

Zeryab AlamThis course is exceptionally well done. Completely understood the theory and implementation behind them damned graphs.

rahulwatched your lecture on Dynamic Programming and now I am here. You are such a phenomenal teacher, thanks a ton for making these tutorials!

Harry ZachariouGreat video! At 1:00:00 isn’t there a slight optimisation where you add the src to visited, as it will add it twice as it goes back up the stack so could wrap in a conditional to only add to visited if it doesn’t already exist in visited?

RickThis was amazing. I’ve watched a bunch of these types of videos over the years and this is the only one that actually made it look easy. I can actually say I understand this now. Thank you.

Radhika TupkaryThis is phenomenal! I was finding Graph problems so difficult before watching this video, and now they seem fairly easy after watching the entire video! Thanks a ton!

TheBarthinatorWow amazing how you made me understand graphs and I have extreme comfortability with the recursive approach and queue method. Always struggled understanding these implementations in python but as a web dev it made a lot more sense in JS. Thank you for taking the time to make this video!

NikiThis is the only course I’ve found that has successfully got the concept of graphs through my thick skull, it’s been a subject that’s been so hard for me to learn. Thank you for making this!!

Jerald MacachorLeetcode – O(n^2) brute force.

Algoexpert – O(n) linear

Alvin / Structy – log(n)

Alex NeagoeI am actually studying C but I have found this video tremendeously helpfull in explaining how graphs are traversed and how not to use return in a bad way when you want to actually make use of recursion to backpedal from dead ends in situations where you don’t find your base case.

thank you again. subscribed!

Agustin VargasThis is fantastic. Makes graphs easy to digest. Thanks for that.

I did find a minor issue in the island count problem solution.

It assumes that each row will have the same number of columns. That assumption isn’t described in the problem. So a quick fix would be to run the nested loop to the length of the row instead of fixing it to zero. And doing the same for the inbounds check. That would present an issue in the exploration in that there might not be any map in either direction, so you’ll have to add an existence check in the explore to account for that.

This way if a row has less coordinates, or more, it would still work properly.

Bikki Kumar shaChanging lives, one algorithm at a time. Great work Alvin!

Ben Lplease do a similar video for weighted graphs. alvin has the best teaching style. clear concise with helpful drawings!!!

Aditya ByreddyThis is amazing. I found it really easy to understand the graph algorithms after referring to this video. Great job, Alvin 🙂

Small correction in the solution described for checking if a source and destination have a path in an undirected graph. (line no. 8)

The logic of traversing the neighbors and adding the source node to the visited list has to be part of the condition that validates whether ta node is visited or not.

if !(visited.has(src)) {

// add the src to the visitors list

// recursively traverse through the src neighbors

}