Can anyone give me a code of using adjacency lists to represent a graph using arrays only( perhaps by using an 2D array). asked 16 Jan '15, 18:21

I was in the same position as you are just a few weeks back. In fact, I haven't even practiced enough graph problems. I wanted answers only in terms in what I know. But trust me, arrays are a lot more harder to maintain adjacency lists. Anyway, you can check these out http://www.iarcs.org.in/inoi/onlinestudymaterial/topics/graphsrepresentation.php http://web.stanford.edu/class/cs97si/06basicgraphalgorithms.pdf A better option would be to use an array of vectors or a vector of vectors whose size can be adjusted dynamically, you don't have to specify it in advance. To use a vector of vectors to maintain an adjacency list, google how it works and for a better understanding refer this, an implementation of the FIREESC problem http://discuss.codechef.com/questions/17801/introductiontographsdefinitionstraversaldepthfirstsearch Hope it helps! answered 16 Jan '15, 23:31
