×

Biconnectivity in a Graph

What is a Graph?

A graph is a structure where values are stored at the vertex, and the relation between vertices is denoted by edges.

In a graph, if there is only one component, it is said to be a connected graph. So, a biconnected graph means a graph where there does not exist any articulation point.

What is an Articulation point?

If a graph contains an vertex that after removing that vertex, if the graph is divided into two or more components, then this vertex is called articulation point. For any articulation point, there will be the removal of that vertex and all its edges connected to it.

For getting an articulation point, the brute-force approach is by removing each vertex and checking if the graph is connected or not. If connected, then add it again and move to the next vertex. If not connected, then return true for articulation point.

For example:

Biconnectivity in a Graph

In the above graph, vertex 2 and vertex 4 are articulation points because if you remove any of them, the graph will be divided into two parts, and it will not be connected.

After removing vertex2:

Biconnectivity in a Graph

After removing 4:

Biconnectivity in a Graph

If we try the brute-force approach, then it will not be an optimal solution. Let's suppose the number of vertices is V and edges is E. so, Time complexity would be: O(V*(V+E)).

For an optimal solution, we will use the DFS approach. The basic idea would be that during DFS, we will assign two variables for each node. The first one is the time for the node to be introduced, and the second one is the minimum to get to the node.

Initially, we will use the timer variable and assign them the same as the time and increment time variable.

During dfs, if the node is unvisited, make it visited.

Visit its adjacent node except the parent.

If the adjacent node is not visited, then call the recursive DFS function for this adjacent node.

When the adjacent node of any node is visited, then compare its minimum time to the node’s minimum time.

If (min_time[adjacent]>=min_time[node]), it means if we remove the current node, then we can't reach the adjacent node because the adjacent node’s path is dependent on the current node. So the current node is an articulation point for this adjacent node.

Else we can simply put min_time[node] = min_time[adjacent] because it shows adjacent node’s minimum time to reach is lesser than current. It means we can reach the adjacent node also without the current node. So the current node can’t be an articulation point.

Note: if there is any source vertex from where we are starting the DFS, and it has more than one child who is not connected, then it can be an articulation point

For example:

Biconnectivity in a Graph

For the above, if we remove node 1, then it will be divided into more than one component.

So if there is any node whose parent is no node and it has more than one child, then it will definitely be an articulation point.

For implementing the code, we use a HashSet. If we encounter any articulation point, then we will add it to the HashSet.

In the end, if the HashSet contains more than zero elements, then the graph is not biconnected, else the graph is considered to be connected.

JAVA Code:

import java.util.*;
public class Main {
  public static void dfs(int node, int parent, int vis[], int tin[], int low[], ArrayList < ArrayList < Integer >> adj, int timer, HashSet < Integer > articulation) {
    vis[node] = 1;
    tin[node] = low[node] = timer++;
    int child = 0;
    for (Integer it: adj.get(node)) {
      if (it == parent) continue;


      if (vis[it] == 0) {
        dfs(it, node, vis, tin, low, adj, timer, articulation);
        low[node] = Math.min(low[node], low[it]);


        if (low[it] >= tin[node] && parent != -1) {
          articulation.add(node);
        }
        child++;
      } else {
        low[node] = Math.min(low[node], tin[it]);
      }
    }
    if (parent != -1 && child > 1) articulation.add(node);
  }


  public static void printBridges(ArrayList < ArrayList < Integer >> adj, int n) {
    int vis[] = new int[n + 1];
    int tin[] = new int[n + 1];
    int low[] = new int[n + 1];


    HashSet < Integer > articulation = new HashSet < > ();


    int timer = 0;
    for (int i = 0; i < n; i++) {
      if (vis[i] == 0) {
        dfs(i, -1, vis, tin, low, adj, timer, articulation);
      }
    }


    if (articulation.size() > 0)
      System.out.println("not biconnected");
    else
      System.out.println("bi-connected graph");
  }
  public static void main(String[] args) {
    int n = 5;
    ArrayList < ArrayList < Integer > > adj = new ArrayList < ArrayList < Integer > > ();
    for (int i = 0; i < n + 1; i++)
      adj.add(new ArrayList < Integer > ());


    adj.get(1).add(2);
    adj.get(2).add(1);


    adj.get(2).add(3);
    adj.get(3).add(2);


    adj.get(1).add(3);
    adj.get(3).add(1);


    adj.get(2).add(4);
    adj.get(4).add(2);


    adj.get(4).add(5);
    adj.get(5).add(4);


    printBridges(adj, n);
  }
}

So the time complexity for the above code is O(V+E) as we are doing normal DFS traversal.


Related Topics

CarryLook Ahead Adder

What is Adder? Adder is the combinational circuit that is used to add the bits in digital electronics. As we know, in the digital system, every number is represented in the...

4 minutes read.

Bipartite Graph

A graph is said to be bipartite if and only if we can divide all the vertices of a graph into two sets such that these sets are mutually exclusive...

4 minutes read.

Control Unit Organization

Control Unit Organization The Control Unit is the unit in the CPU, which controls the various components like input  & output devices, logic unit and memory. The Control Unit is the...

7 minutes read.

Digital Number System

Digital Number System: The computer understands digital language only. Many number systems are used in digital technology. The most common are Decimal, Binary, Octal and Hexadecimal number systems. Types of the...

7 minutes read.

8086 Microprocessor Pin Configurations

8086 microprocessor is invented and developed by Intel in 1976. The 8086 Microprocessor is an enhanced version of the 8085 Microprocessor. There are 20 address lines and 16 data lines...

6 minutes read.

Basic Terminologies Related to COA

Some Basic Terminologies Related to COA Computer organization and architecture is the detailed study of the internal components of the computer with their functionality. It describes how components arranged together and...

7 minutes read.

Data Path, ALU and Control Unit

Data Path, ALU(Arithmetic Logic Unit) and Control Unit What is the Data path? Suppose any data processing operation should be performed in the CPU like transferring the content of register from one...

5 minutes read.

Pipelining: Computer Organization and Architecture

Introduction to Pipelining Before learning pipeline, we have to understand about the Parallel processing. Parallel processing is the processing of data simultaneously. There are three techniques of parallel processing. Types of Processing: Vector ProcessingArray...

7 minutes read.

Machine Instructions

What is a Digital Computer? A computer that takes input in a binary form and produces output in binary form. The question arises of what kind of input the computer takes...

4 minutes read.

CPU Registers

CPU Registers Within the CPU, we have small- small storage units called registers. If we are executing a certain program within the CPU, there's a need to store that program content,...

11 minutes read.

Instruction Cycle: Computer Organization and Architecture

What is an effective Address? “Effective address is the address of operand in a computation-type instruction.” Computation type instructions are like ADD, SUB, MOV, OR, AND, etc., which require operand to...

4 minutes read.

Biconnectivity in a Graph

What is a Graph? A graph is a structure where values are stored at the vertex, and the relation between vertices is denoted by edges. In a graph, if there is only...

4 minutes read.

COA: Interrupt and its types

Introduction: In general terms, the word interrupt means to stop the progress of ongoing work in between or to break the continuation of the work. In early digital computing, the...

5 minutes read.

8085 Arithmetic Instructions

Arithmetic instructions are a type of instruction in a computer's instruction set that perform arithmetic operations on data. These operations can include addition, subtraction, multiplication, and division. Arithmetic instructions can...

4 minutes read.

Use Case Diagram for the online bank system

What is a Use Case Diagram? A tool is called a Use Case Diagram which is used to create, present, and comprehend the functional requirements for a system. The Use Case...

3 minutes read.

Fixed and Floating-Point Number

Fixed and Floating-Point Number: In digital technology, data is stored in memory registers with binary bits 0’s and 1’s because the computer only understands binary language. When we enter data...

6 minutes read.

Types of Microprocessors

Introduction:Microprocessor is known as the computer processor. The IC or integrated Circuit makes the microprocessor. That is the brain of the computer machine.  The microprocessor is the Processor or CPU (Central...

3 minutes read.

8085 instructions set

Introduction: In the computer, the user sends the data. The computer can use data and it also process the data. After the processing, send the result to the user. The specific...

10 minutes read.

Computer Organization and Architecture Tutorial

Introduction to Computer Organization and Architecture In this modern era, or we can say computer era, Technology from all around surrounds us. Human is conserved, connected and absorbed by Technology. From...

4 minutes read.

Flag Register of 8086 Microprocessor

In this article, we are going to study about the one of the registers named flag registers of 8086 microprocessor. We are also going to know where and how to...

3 minutes read.