hello nowadays i am having a rough time learning graph because i face difficulty understanding adjacency matrix and list.I don’t understand them very well.First help expecting from you all

1)am i the only one who faces this difficulty in these topics

2)can you drop a link to your dfs & bfs(or any other graph algorithm)implementation so that i can look upon it and try to implement them.(this will teach different ways to do same thing)

3)anyway to learn implementation effectively except geeksforgeeks(this website is good but i barely understand them )

PS: i have watched many video lectures but they don’t teach implementation.my main point of concern is that i don’t get good implementation source.

I had the same problem a few months ago and I posted the same question here. I got many useful resources. Among them, my personal favorite is e-maxx.ru. This is a Russian web site, so use google translator.

A few pointers before you go there.

First learn adjacency matrix for undirected graph. It is a bit easier and easy to visualize as it considers all possibilities.

Implement breadth first search and depth first search on adjacency matrix and solve a few easy problems on it.

Most graph searching problems rely on connected components which is just a simple extension of regular traversal. (Ask if you are having trouble with it after learning dfs and bfs).

After that, learn a few problems that are basically just a bit extension of the bfs and dfs like connected components and few others(I can’t recall right now, sorry).

Then learn these above for directed graph and try to understand topological sort, finding articulation points, bridges etc. (e-maxx.ru).

All the above will work if number of vertices are small. If not, you need adjacency matrix. So learn it now.

If you still have problem, just try to implement and then ask with your code. It is easier to understand when a fault is found in your own code, rather in some one else’s code.

p.s. BFS requires a queue. You can implement it easily. But use STL as it provides list which is easy to use and is less prone to errors.

hey i am in the same boat but yeah i think i might be able to help you a bit.yo might google codechef tags and there you can find questions taged with bfs or dfs or whatever you want.as per implementation part i would recomend doing those question and see their editorial.i am posting a editorial of one good question as per implementation part in this editorial even code is given do see it as you will learn a lot from it.you might also see these tutorials

you might also search quora for this there are really really good answers for any coding problem.
this is the editorial which i was saying http://discuss.codechef.com/problems/DIGJUMP
a link for the tagged problems of bfs Bfs Coding Problems - CodeChef do some questions from here and do those which have more submission so it is to see the understandable code from others.
hope this help as i said earlier i am in the same boat …

Yes you are right. For beginners ( and sometimes for experienced coders also ) trees and graph theories are difficult to understand and comprehend.

No, I’m sure you are not the only one facing such difficulty.

Check this and this. Also go through the wiki articles about these topics and search online for codes/help but do not implement blindly. Understand/modify /alter to suit your needs. Go through the links in other answers. @dragonemperor provided some very good basic steps for your problem.

Geekforgeeks is a good site but if you are facing difficulty then ask for help there or go through different sites. Read books on Algorithm by Cormen or any other author (as you like) and go through tutorials, editorials on codechef, topcoder, codeforces, spoj.

Always practice what you have learnt. Implement your logic into code and evaluate them. Test your code in various graph/tree problems available on codechef ( or other places) and check if your implementations are correct. If wrong, try again. If TLE then use efficient approach. Practice is the key to understand such problems ( actually all problems) .