# Relabel-to-front Algorithm

The relabel-to-front algorithm is employed to determine the network's maximum flow. The generic push-relabel approach is less effective than the relabel-to-front algorithm. The basic operations of push and relabel can be used in any order when using the push-relabel method. The relabel-to-front algorithm carefully selects the order and effectively controls the network data structures.

First, we must comprehend the fundamental operations, such as push and relabel:

The height variable (h) and excess flow are the 2 variables that are connected to each vertex in the network (e).

• Push: When a vertex has excess flow and an adjacent node in the residual graph has a lower height, we push the flow from the vertex to the node with the lower height.
• Relabel: When a vertex has too much flow and there are no nodes nearby that are lower in height, we use the relabel operation to make the vertex taller so that it can perform push operations.

The relabel-to-front algorithm keeps track of the network's vertices in a list. It repeatedly chooses an overflowing vertex u and executes a discharge operation on it, starting at the very beginning of the list.

Push and relabel operations are carried out during discharge operations up until vertex u has no positive excess flow (e)

In the event that a vertex is relabeled, the algorithm scans once more with the new vertex at the front of the list.

## Algorithm:

• Set the preflow and heights to their respective initial values for the aforementioned generic push-relabel algorithm.
• Create list L from scratch, leaving out the sources and sinks.
• Set each vertex's current pointer to the first vertex in its neighbour list N. Those vertices for which a residual edgeexists are included in the neighbour list N.
• as list L's end is reached by the algorithm.
• Perform the discharge operation on the vertex u after choosing it from list L.
• Put you at the top of the list if you were relabeled due to discharge.
• The vertex in the following iteration is the one that follows u in its new position in the list if u was moved to the front of the list.

### Example

• Consider the flow network as an example. The initial list L=(B, C) with initial value u=B is displayed on the right.
• following the initialization of the preflow. A neighbour list N with the current neighbour circled is located under each vertex in list L.
• Since Vertex B has an excess flow of 3 (e=3), a discharge operation is performed. Vertex B performs a relabel operation (h=1) and pushes flow 1 to vertex C because it lacks a node with a lower height.
• Vertex B performs a relabel operation (h=5) and pushes flow 2 to vertex A because it still has extra flow 2(e=2). Vertex B remains at the top of the list despite having its label changed. Now that vertex C has an excess flow of 1(e=1), it is discharged.
• Relabel operation (h=1) is carried out by vertex C, and flow 1 is pushed to node D. Vertex C is moved to the top of the list because it performed a relabel operation.
• Now, in L, vertex B follows vertex C, but B does not have an excess flow. Once it reaches theend of list L, the RELABEL-TO-FRONT comes to an end. Since there are no overflowing vertices, the preflow is at its highest level. Here, maximum flow is 1.
• Time Complexity: On network G, runs in O(V3) time (V, E). As a result, it performs better than the generic push-relabel algorithm, which takes O(V2E) time to complete.