4

I have a graph G containing N nodes and E edges.Each edge is undirectional.The goal is to find the no. of crucial nodes.

A node which makes the graph disconnected when it is removed is called a crucial node. The goal is to find the no. of such nodes in the graph.

A solution would be:-

For each node belonging to the graph, remove it from the graph, pick a node from the remaining graph, perform dfs, if we are able to reach everywhere then it is not a crucial node.

This solution is O(N*E) or worst case O(N^3).

Is there a O(N^2) solution or O(E) solution because N^3 is a bit too slow.

Dominique Fortin
  • 2,212
  • 15
  • 20
Sr1n4th
  • 251
  • 2
  • 8

1 Answers1

2

A crucial node is a node that when removed, will cut the graph into 2 or more disjoint sub-graphs ..

Thus, a crucial node is a node that is connected to 2 or more sub-graphs that are only connected through this crucial node ..

A possible solution might be like this:

  • For every node i in the graph G:

    1. list L: all nodes directly connected to to node i

    2. if there exist 2 nodes u and v in list L such that there is no path that connect u by v not though i, then i is a crucial node

Reference: Wikipedia:Cycle Detection

Example (in Java):

public class CrucialNode
{
    public static ArrayList<Node> crucialVertices (Graph g)
    {
        ArrayList<Node> crucial = new ArrayList<Node> ();

        for (Node n : g.getV()) if (isCrucial(g,n)) crucial.add(n);

        return crucial;
    }

    public static boolean isCrucial (Graph g, Node n)
    {
        Graph h = new Graph(g);

        h.removeVertex(n);

        for (Node u : n.getNext())
        {
            for (Node v : n.getNext())
            {
                if (u.equals(v)) continue;

                if (!h.connected(u,v)) return true;
            }
        }

        return false;
    }
}
Khaled.K
  • 5,828
  • 1
  • 33
  • 51
  • 2
    a crucial node need not have a crucial edge. Consider this graph as an example http://www.cs.umd.edu/class/summer2006/cmsc451/cut-vertex.gif The common vertex in the two squares is a crucial vertex, but has no crucial edge to it. – Five Apr 07 '13 at 10:11
  • "Crucial node" is actually more formally known as an articulation point,dont know how i got to know that but a simple google search will reveal very good algorithms for finding out articulation points.. – Sr1n4th Apr 08 '13 at 22:00