Which Data Structure Is Used in Boost Graph Library?


Heather Bennett

The Boost Graph Library is a powerful tool for working with graphs and graph algorithms in C++. It provides a wide range of data structures and algorithms that can be used to represent and manipulate graphs. In this article, we will explore the data structures used in the Boost Graph Library and discuss their advantages and use cases.

The Graph Data Structure

The fundamental data structure used in the Boost Graph Library is the graph. A graph is a collection of vertices (or nodes) connected by edges. The Boost Graph Library supports both directed and undirected graphs, as well as various other types of graphs such as weighted graphs.

Adjacency List

One of the most commonly used data structures for representing a graph is the adjacency list. In an adjacency list, each vertex is associated with a list of its neighboring vertices. This allows for efficient traversal of the graph and easy access to adjacent vertices.

In the Boost Graph Library, the adjacency list data structure is implemented using two main components: a container to store the vertices and a container to store the edges. The choice of containers can be customized based on specific requirements.

Here’s an example of how to create an adjacency list graph using the Boost Graph Library:


typedef boost::adjacency_list Graph;

int main()
    Graph g;
    // Add vertices
    // Add edges
    boost::add_edge(0, 1, g);
    return 0;

In this example, we create an undirected graph using `boost::adjacency_list`. The `boost::vecS` container is used for both storing vertices and edges. The `boost::undirectedS` tag specifies that the graph is undirected.

Other Data Structures

While the adjacency list is a versatile and commonly used data structure, the Boost Graph Library also provides other data structures for specific use cases. Some of these data structures include:

  • Adjacency Matrix: A matrix representation where each cell indicates whether there is an edge between two vertices
  • Edge List: A simple list of edges
  • Property Map: A mapping between vertices or edges and their associated properties

Each of these data structures has its own advantages and trade-offs in terms of memory usage, performance, and ease of use. The choice of data structure depends on the specific requirements of your application.


In conclusion, the Boost Graph Library provides a wide range of data structures for representing graphs. The adjacency list is a commonly used data structure that allows for efficient traversal and easy access to adjacent vertices.

However, depending on your specific requirements, other data structures such as the adjacency matrix or edge list may be more suitable. It’s important to understand the strengths and weaknesses of each data structure to make an informed decision when working with graphs using the Boost Graph Library.

Remember to always refer to the official documentation for detailed information on how to use the different data structures provided by the Boost Graph Library. Happy graphing!

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy