Hello coders as i feel little uncomfort on graph theory problems So can u guys guide me . I prefer JAVA. Please help me in these topic in Java if possible : 1)How to represent graph in java in adjacency list ? 2)Searching a node in a graph. 3)BFS and DFS in JAVA. 4)Find all Path between 2 nodes in java. 5)And finally maximum flow problem in java. I will be thankful if u help in some of these problem as these are the frequently asked problems in programming contests. asked 26 Jun '14, 21:36

There is a tutorial on Topcoder on Graph , u can go through this . answered 27 Jun '14, 00:00
As i need java program for these problem but topcoder will only give me sudo code which is in c . So please refer me to link for java program of these problem thanks
(27 Jun '14, 10:20)
For the problem in the tutorial , you can go to the problem archive and then see the java solution . if u are still unable to find solution to a particular question , tell me the question name I`ll help u out in finding the solution .
(27 Jun '14, 14:30)
Thanks man question no 5) and one more thing is there any advantage of using c++ over java in contest
(27 Jun '14, 14:56)
I think u are asking for team builder here is solution : http://community.topcoder.com/stat?c=problem_solution&cr=159530&rd=4740&pm=2356 I haven`t used java , but C++ uses less time , that may be a benefit .
(27 Jun '14, 15:29)
1
Can you provide link of some graph based problems on codechef...
(27 Jun '14, 15:31)
1
U can use this site http://codeutils.appspot.com/ and search for graph in tags .
(27 Jun '14, 15:44)
http://www.codechef.com/tags/problems/graphs http://www.codechef.com/tags/problems/graph Of course you can search any category(graphs,trees,dp,greedy,....) using this format :
(27 Jun '14, 16:26)
showing 5 of 7
show all

This is how I do it. I'm still a novice so it might not be very efficient but it works. Please correct me if I'm wrong anywhere and suggestions for improving my methods will be extremely helpful and appreciated :) 1. How to represent graph in java in adjacency list ? One way: Let
To make the link we can use a
This is when all the nodes of the graph are integers,change the type according to your needs. Another way: Representation can also be done in this way. Its like an array of lists.
The i'th index of the array (graph[]) holds a list which contains all the nodes in the graph that the i'th node is connected to. If there are say N nodes,initialize the graph with empty lists.
2. Searching a node in a graph. This can be done by bfs/dfs. Which one to use can be determined by the depth of the graph. In short,if depth is very large,dfs is preferable otherwise bfs will be better. Here is a very neat code that will help you to understand how it is being done. If you don't prefer to make new node class for the purpose as shown in the link,in that case(it will get lengthy) create a method like Suggested problems
I haven't learnt max flow yet so can't say anything about that. Its an advanced topic so before working on maxflow make sure that you know the basic graph algorithms well. Good luck! answered 27 Jun '14, 18:25
