You are not logged in. Please login at www.codechef.com to post your questions!

×

Adjacency list

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

anupam_datta's gravatar image

4★anupam_datta
379526
accept rate: 7%


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/online-study-material/topics/graphs-representation.php

http://web.stanford.edu/class/cs97si/06-basic-graph-algorithms.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/introduction-to-graphs-definitions-traversal-depth-first-search

Hope it helps!

link

answered 16 Jan '15, 23:31

sandy999's gravatar image

3★sandy999
39111537
accept rate: 10%

edited 17 Jan '15, 14:17

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×811
×1

question asked: 16 Jan '15, 18:21

question was seen: 981 times

last updated: 17 Jan '15, 14:17

Related questions