0
0
DSA Cprogramming~20 mins

Articulation Points in Graph in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Articulation Points Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of articulation points detection in a simple graph
What is the output of the following code that finds articulation points in the given graph?
DSA C
/* Graph edges: 0-1, 1-2, 2-0, 1-3 */
#include <stdio.h>
#include <stdlib.h>
#define V 4

int time_counter = 0;

void APUtil(int u, int visited[], int disc[], int low[], int parent[], int ap[], int graph[V][V]) {
    visited[u] = 1;
    disc[u] = low[u] = ++time_counter;
    int children = 0;
    for (int v = 0; v < V; v++) {
        if (graph[u][v]) {
            if (!visited[v]) {
                children++;
                parent[v] = u;
                APUtil(v, visited, disc, low, parent, ap, graph);
                if (parent[u] == -1 && children > 1)
                    ap[u] = 1;
                if (parent[u] != -1 && low[v] >= disc[u])
                    ap[u] = 1;
                if (low[v] < low[u])
                    low[u] = low[v];
            } else if (v != parent[u]) {
                if (disc[v] < low[u])
                    low[u] = disc[v];
            }
        }
    }
}

void AP(int graph[V][V]) {
    int visited[V] = {0}, disc[V], low[V], parent[V], ap[V] = {0};
    for (int i = 0; i < V; i++) parent[i] = -1;
    for (int i = 0; i < V; i++) {
        if (!visited[i])
            APUtil(i, visited, disc, low, parent, ap, graph);
    }
    printf("Articulation points: ");
    for (int i = 0; i < V; i++) {
        if (ap[i]) printf("%d ", i);
    }
    printf("\n");
}

int main() {
    int graph[V][V] = {
        {0,1,1,0},
        {1,0,1,1},
        {1,1,0,0},
        {0,1,0,0}
    };
    AP(graph);
    return 0;
}
AArticulation points: 2 3
BArticulation points: 1
CArticulation points: 3
DArticulation points: 0 1
Attempts:
2 left
💡 Hint
Focus on the node whose removal increases the number of connected components.
🧠 Conceptual
intermediate
1:30remaining
Understanding articulation points in a tree
In a tree with 5 nodes connected as 0-1, 1-2, 1-3, 3-4, which nodes are articulation points?
ANodes 0 and 4
BNodes 2 and 4
CNodes 1 and 3
DNodes 0, 2, and 4
Attempts:
2 left
💡 Hint
Articulation points are nodes which, when removed, increase the number of connected components.
🔧 Debug
advanced
2:00remaining
Identify the error in articulation points code
What error will the following code produce when run on a graph with 3 nodes connected linearly (0-1-2)?
DSA C
#include <stdio.h>
#define V 3

int time = 0;

void APUtil(int u, int visited[], int disc[], int low[], int parent[], int ap[], int graph[V][V]) {
    visited[u] = 1;
    disc[u] = low[u] = ++time;
    int children = 0;
    for (int v = 0; v < V; v++) {
        if (graph[u][v]) {
            if (!visited[v]) {
                children++;
                parent[v] = u;
                APUtil(v, visited, disc, low, parent, ap, graph);
                if (low[v] >= disc[u])
                    ap[u] = 1;
                if (low[v] < low[u])
                    low[u] = low[v];
            } else if (v != parent[u]) {
                if (disc[v] < low[u])
                    low[u] = disc[v];
            }
        }
    }
}

void AP(int graph[V][V]) {
    int visited[V] = {0}, disc[V], low[V], parent[V], ap[V] = {0};
    for (int i = 0; i < V; i++) parent[i] = -1;
    for (int i = 0; i < V; i++) {
        if (!visited[i])
            APUtil(i, visited, disc, low, parent, ap, graph);
    }
    printf("Articulation points: ");
    for (int i = 0; i < V; i++) {
        if (ap[i]) printf("%d ", i);
    }
    printf("\n");
}

int main() {
    int graph[V][V] = {
        {0,1,0},
        {1,0,1},
        {0,1,0}
    };
    AP(graph);
    return 0;
}
ALogical error: root node with one child incorrectly marked as articulation point
BNo error, output: Articulation points: 0 1
CNo error, output: Articulation points: 0
DNo error, output: Articulation points: 1
Attempts:
2 left
💡 Hint
Check how root nodes with one child are handled in articulation point logic.
Predict Output
advanced
2:30remaining
Output of articulation points in a complex graph
What is the output of the following code for articulation points in the graph with edges: 0-1, 1-2, 2-0, 1-3, 3-4, 4-5, 5-3?
DSA C
#include <stdio.h>
#define V 6

int time = 0;

void APUtil(int u, int visited[], int disc[], int low[], int parent[], int ap[], int graph[V][V]) {
    visited[u] = 1;
    disc[u] = low[u] = ++time;
    int children = 0;
    for (int v = 0; v < V; v++) {
        if (graph[u][v]) {
            if (!visited[v]) {
                children++;
                parent[v] = u;
                APUtil(v, visited, disc, low, parent, ap, graph);
                if (parent[u] == -1 && children > 1)
                    ap[u] = 1;
                if (parent[u] != -1 && low[v] >= disc[u])
                    ap[u] = 1;
                if (low[v] < low[u])
                    low[u] = low[v];
            } else if (v != parent[u]) {
                if (disc[v] < low[u])
                    low[u] = disc[v];
            }
        }
    }
}

void AP(int graph[V][V]) {
    int visited[V] = {0}, disc[V], low[V], parent[V], ap[V] = {0};
    for (int i = 0; i < V; i++) parent[i] = -1;
    for (int i = 0; i < V; i++) {
        if (!visited[i])
            APUtil(i, visited, disc, low, parent, ap, graph);
    }
    printf("Articulation points: ");
    for (int i = 0; i < V; i++) {
        if (ap[i]) printf("%d ", i);
    }
    printf("\n");
}

int main() {
    int graph[V][V] = {
        {0,1,1,0,0,0},
        {1,0,1,1,0,0},
        {1,1,0,0,0,0},
        {0,1,0,0,1,1},
        {0,0,0,1,0,1},
        {0,0,0,1,1,0}
    };
    AP(graph);
    return 0;
}
AArticulation points: 0 1 3
BArticulation points: 1
CArticulation points: 3
DArticulation points: 1 3
Attempts:
2 left
💡 Hint
Check root node with multiple children and nodes whose removal disconnects subgraphs.
🧠 Conceptual
expert
1:00remaining
Minimum number of articulation points in a biconnected graph
What is the minimum number of articulation points in a biconnected graph with more than two vertices?
AZero
BOne
CTwo
DDepends on the number of vertices
Attempts:
2 left
💡 Hint
Recall the definition of biconnected graph regarding articulation points.