Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Advanced
Aug 19, 2002

Efficient Storage of and Access to Adjacency Lists


Large graphs are stored as adjacency lists to save space. Traditional mechanisms based on arrays of pointers waste space. The following scheme is based on array of indices, which saves space and provides easier access.

Consider a weighted graph, G = (V, E), with |V|= n and |E| = m, where each edge and vertx has a weight.
0
Below, the two given arrays store all the info necessary to represent the edges of the graph and to facilitate all operations on them efficiently:
 
unsigned short xadj[n+1];
unsigned short adjncy[m];

adjncy[xadj[i]] to adjncy[xadj[i+1]] denote the edges from _
vertex i, where
number of edges from vetex i = xadj[i+1] - xadj[i]

The weights of vertices and edges can be stored as arrays as follows:
 
short edge_wgt[m];
short vertex_wgt[n];
Shailendra Kumar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date