Saturday, September 19, 2020

Bridges and Articulation points ------Amazon OA !!!!!

 You are given an undirected connected graph. An articulation point (or cut vertex) is defined as a vertex which, when removed along with associated edges, makes the graph disconnected (or more precisely, increases the number of connected components in the graph). The task is to find all articulation points in the given graph.

Input:
The input to the function/method consists of three arguments:

  • numNodes, an integer representing the number of nodes in the graph.
  • numEdges, an integer representing the number of edges in the graph.
  • edges, the list of pair of integers - A, B representing an edge between the nodes A and B.

Output:
Return a list of integers representing the critical nodes.

Example:

Input: numNodes = 7, numEdges = 7, edges = [[0, 1], [0, 2], [1, 3], [2, 3], [2, 5], [5, 6], [3, 4]]

Output: [2, 3, 5]


A:

每次删掉一个点,然后看其余的点和edge, 能否组成一个size 为n -1的tree。

然而这样复杂度太高~~~~~~


答案看这里:O(V +E)

Bridges and Articulation points Algorithm | Graph Theory




No comments:

Post a Comment