Can someone provide with easier implementations of graph algorithms including dfs and bfs. I tried studying from some sites and books including geeksforgeeks but the implementation seemed quite tough…Please help
try this link it has everything , implementation , tutorials , and problems .
This is on the front page. I mean, its worthwhile to search a forum first, as you might get an answer instantly. You are lucky that many people are active this hour, else the Q can go unanswered for some time and you will have to wait/waste-time-waiting unnecessarily.
This will be really helpful I think. Though they are written in pseudocodes, but if you understand it you can easily turn them into real codes.
These will be pretty much helpful
This is the best video lectures i have seen on BFS and DFS(which will help you in implementation):
Source: NPTEL : Course: Data Structures and Algorithms (IIT Delhi)
1. BFS(After 21:00)
This is the bfs code I use:
Implementation of dfs:
thanks bro. .
yes its one of the top posts.
vijju I already had this page bookmarked long ago. But as I said I didn’t understand quite well their implementations(here they gave link to geeksforgeeks and that implementation seems quite tough to me as I said). If u have any other better implementations please suggest.
thanks… I am studying from it. Also if u get some free time can u give link to some solutions of problems related to dfs and bfs…I am quite weak in graph theory
Well, you didnt mention that in @raj79 's comment, so i felt that you didnt came across that thing yet. I think others have already answered it well enough, should you still need help then i will be happy to ^^
yes u can definitely suggest if u have some easier implementations…
In that case, what things have you already looked over. And what type of issues are you facing in implementation? Does a simple DFS code (code to visit vertice and print the order of visit) is being problematic to you? Or you are on a bit of medium side and feel need of easy problems to practice?
no I am completely noob.Yes I cant even solve a simple graph problem
One last Q, How familiar are you with Data structures then?Graph theory is easier if you know a bit about them, else simple codes will also seem tough.
I will agree with hruday’s hackerearth links. Its simpler than codeforces there. And i think geeksforgeeks have a video tutorial for DFS, BFS. If you watched it but didnt understood, give it another try few days later (after doing some of hackerearth).
I find hackerearth to be detailed (Learnt segment tree from there so ^^)
Do you want some problems or solutions? If problems, there’s many problem under ‘dfs’ tag you can find in codechef, try to at first solve those, see editorials if you need and still if you can’t, we are always here!
thanks I have already watched them. I have understood how the algo works but I am facing problem with implementation.Now I am studyng frm the links others suggested