Professional Documents
Culture Documents
1 Algorithm Description
1.1 Explanation of Pseudocode
The fields in the vertex structure are:
• mark: boolean
• mark as cut vertex: boolean
• position: integer
• inDegree: integer
• outDegree: integer
Note that the inDegree and outDegree fields are not exactly the in-degree and out-degree of the vertex.
They are used to keep track of the in-degree and out-degree of the vertices in the subgraph induced by the
vertices with positions between start and end. I am assuming that the graph G is in the form of an adjacency
list.
1.1.3 CutVertices(G, s, t)
• This function identifies the cut vertices between vertices s and t.
• It iterates over the vertices in topological order within the range from s to t.
• It keeps track of a counter ctr, which is increased by the out-degree and decreased by the in-degree of
each vertex.
• When ctr becomes zero (except for s and t), it records the vertex as a cut vertex.
1.1.4 Driver(G, s, t)
• This is the main function that initializes vertex positions, in-degrees, and out-degrees using Preprocess.
• It sets up the range (start to end) between vertices s and t.
• Finally it calls CutVertices to find the cut vertices between s and t
1.2 Pseudocode
1
Algorithm 1 CutVertices
1: procedure SpecialDFS(G, v, start, end)
2: mark v
3: if start ≤ position(v) ≤ end then
4: for all edges v → w do
5: if w is unmarked then
6: if start ≤ position(w) ≤ end then
7: outDegree(v) ← outDegree(v) + 1, inDegree(w) ← inDegree(w) + 1
8: end if
9: SpecialDFS(G, w, start, end)
10: end if
11: end for
12: else
13: for all edges v → w do
14: if w is unmarked then
15: SpecialDFS(G, w, start, end)
16: end if
17: end for
18: end if
19: end procedure
2
1.3 Summary
The algorithm works by initializing positions, in-degrees, and out-degrees to the vertices in the graph using
topological sort ordering. Then, it runs a DFS on the graph, and computes in-degrees and out-degrees for the
vertices which are between the positions of s and t. Finally, it iterates over the vertices in the topological order
that are between the positions of s and t, and checks if the vertex that is currently being iterated over has the
value of ctr equal to 0 after we subtract the in-degree of the vertex from ctr. If yes, this vertex is a cut vertex,
and we store it in our list containing the (s, t) cut vertices. Following this check, we add the out-degree of the
vertex to ctr.
4 Contributors
• Angadjeet Singh (2022072)
• Avi Sharma (2022119)