Lesson 5 - Graph Algorithms (BFS, DFS & Shortest Paths)

Please visit the Lesson Page for more detailed info :point_up:

:play_or_pause_button: Live Session Links:
English: https://youtu.be/SmOrBW22R2k
Hindi: https://youtu.be/avSKR73MqBE

Lecture Date and Time:
English: Add to Calendar (Google)
Hindi: Add to Calendar (Google)

:zap: In this lesson, we look at the graph data structure and implement common graph algorithms like breadth-fist search, depth-first search, and shortest paths.

Notebooks used in this lesson:

:question: Asking/Answering Questions :
Reply to this thread to ask questions during and after the lecture. Before asking, scroll through the thread and check if your question (or a similar one) is already present. If yes, just like it. During the lecture, we’ll answer 8-10 questions with the most likes. The rest will be answered on the forum. If you see a question you know the answer to, please post your answer as a reply to that question. Let’s help each other learn!

Hi, the notebook is not updated with the lecture material. Seems Aakash forgot to commit the notebook. Can we have the codes recreated in the notebook, please?


Hello, The notebook linked from the lesson page contains all the code, please go through it.

1 Like

Has anybody done the DFS Exercises? I’m trying to get the parent of DFS nodes! not sure if it’s correct! I write code parent=current aftet popping it!


so it gives me this! is it right!??
should i write…
parent.append(current) after popping!!(then it gives long list!)

1 Like


I have done it like this and it gives correct result…

Hope it helps…

1 Like

Has anyone implemented this…

If so please help me i don’t have a clue for this…

My only breakthrough is that if len(edges) > num_nodes then graph must contain a cycle

1 Like

I am also stuck at he time complexities of DFS and BFS and Dijkstra’s algorithm
Pls can someone explain them ???

1 Like

Thanks for the reply. Yes I figured it out too and sure it helps.

1 Like

I practiced it from This: https://www.geeksforgeeks.org/detect-cycle-undirected-graph/
and from some you tube channel(better to search). it took good amount of time to get the hang of it. but the explanation is good. there’s another way of graph coloring!! i have to check it too.
Oh and yes try to break it the whole code first to understand properly then practice together!

1 Like

Check this out: https://youtu.be/XB4MIexjvY0 for Djikstra’s algiorithm.

1 Like

Thank You very much…I would be checking and learning all of these in a couple of days…
I might become a champion in Graphs becuase of You…Thank You once again Mariha…

1 Like