Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.
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.



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