External memory graph traversal is a type of graph traversal optimized for accessing externally stored memory.
Graph traversal is a subroutine in most graph algorithms. The goal of a graph traversal algorithm is to visit (and / or process) every node of a graph. Graph traversal algorithms, like breadth-first search and depth-first search, are analyzed using the von Neumann model, which assumes uniform memory access cost. This view neglects the fact, that for huge instances part of the graph resides on disk rather than internal memory. Since accessing the disk is magnitudes slower than accessing internal memory, the need for efficient traversal of external memory exists.
For external memory algorithms the external memory model by Aggarwal and Vitter[1] is used for analysis. A machine is specified by three parameters: M, B and D.M is the size of the internal memory, B is the block size of a disk and D is the number of parallel disks.The measure of performance for an external memory algorithm is the number of I/Os it performs.
The breadth-first search algorithm starts at a root node and traverses every node with depth one. If there are no more unvisited nodes at the current depth, nodes at a higher depth are traversed. Eventually, every node of the graph has been visited.
For an undirected graph
G
Let
L(t)
A(t):=N(L(t-1))
L(t)
A(t)
A(t)
L(t-1)
O(|L(t-1)|+|A(t)|/(D ⋅ B))
A'(t)
A(t)
A(t)
O(\operatorname{sort}(|A|))
L(t):=A'(t)\backslash\{L(t-1)\cupL(t-2)\}
L(t-1)
L(t-2)
O((|A(t)|+|L(t-1)|+|L(t-2)|)/(D ⋅ B))
The overall number of I/Os of this algorithm follows with consideration that
\sumt|A(t)|=O(m)
\sumt|L(t)|=O(n)
O(n+\operatorname{sort}(n+m))
A visualization of the three described steps necessary to compute L(t) is depicted in the figure on the right.
Mehlhorn and Meyer[3] proposed an algorithm that is based on the algorithm of Munagala and Ranade (MR) and improves their result.
It consists of two phases. In the first phase the graph is preprocessed, the second phase performs a breadth-first search using the information gathered in phase one.
During the preprocessing phase the graph is partitioned into disjointed subgraphs
Si,0\leqi\leqK
F=F0F1...FK-1
Fi
Si
The breadth-first search phase is similar to the MR algorithm. In addition the algorithm maintains a sorted external file . This file is initialized with
F0
Fi
Si
L(t)
L(t-1)
v\inL(t-1)
L(t-1)
Fi
A(t)
A(t)
Edges might be scanned more often in, but unstructured I/Os in order to fetch adjacency lists are reduced.
The overall number of I/Os for this algorithm is
O\left(\sqrt | n ⋅ (n+m) |
D ⋅ B |
+\operatorname{sort}(n+m)\right)
The depth-first search algorithm explores a graph along each branch as deep as possible, before backtracing.
For directed graphs Buchsbaum, Goldwasser, Venkatasubramanian and Westbrook[4] proposed an algorithm with
O((V+E/B)log2(V/B)+\operatorname{sort}(E))
This algorithm is based on a data structure called buffered repository tree (BRT). It stores a multi-set of items from an ordered universe. Items are identified by key. A BTR offers two operations:
insert(''T, x'')
, which adds item x to T and needsO(1/Blog2(N/B))
extract(''T, k'')
, which reports and deletes from T all items with key k. It requiresO(log2(N/B)+S/B)
The algorithm simulates an internal depth-first search algorithm. A stack S of nodes is hold. During an iteration for the node v on top of S push an unvisited neighbor onto S and iterate. If there are no unvisited neighbors pop v.
The difficulty is to determine whether a node is unvisited without doing
\Omega(1)
For vertex u on top of S all edges (u,x) are extracted from D. Such edges only exist if x has been discovered since the last time u was on top of S (or since the start of the algorithm if u is the first time on top of S). For every edge (u,x) a delete(x) operation is performed on P(u). Finally a delete-min operation on yields the next unvisited node. If P(u) is empty, u is popped from S.
Pseudocode for this algorithm is given below.
1 procedure BGVW-depth-first-search(G, v): 2 let S be a stack, P[] a priority queue for each node and D a BRT 3 S.push(v) 4 while S is not empty: 5 v = =