Skip to content

Conversation

Pasan11504
Copy link

📝 Add Articulation Points and Bridges Algorithm

Description

This PR implements an algorithm to find Articulation Points (Cut Vertices) and Bridges (Cut Edges) in undirected graphs using a DFS-based approach with discovery times and low-link values.

Articulation Point: A vertex whose removal increases the number of connected components.
Bridge: An edge whose removal increases the number of connected components.

Features

  • ✅ Finds articulation points in O(V + E) time
  • ✅ Finds bridges in O(V + E) time
  • ✅ Single DFS traversal for efficiency
  • ✅ Handles disconnected graphs correctly
  • ✅ Convenience methods for finding only points or only bridges
  • ✅ Comprehensive Javadoc with examples and applications
  • ✅ Extensive test coverage with 15 test cases

Algorithm Details

Time Complexity: O(V + E)
Space Complexity: O(V)

Detection Rules:

  • Root vertex is an articulation point if it has more than 1 child in DFS tree
  • Non-root vertex u is an articulation point if it has a child v where low[v] >= discovery[u]
  • Edge (u,v) is a bridge if low[v] > discovery[u]

Test Coverage

The test suite covers:

  • Simple graphs with single/multiple articulation points
  • Graphs with no articulation points (biconnected components)
  • Star graphs (center as articulation point)
  • Disconnected graphs
  • Edge cases (empty graph, single vertex)
  • Edge equality and symmetry validation
  • Exception handling for invalid inputs

Real-World Applications

  • 🌐 Network reliability analysis (finding critical routers/connections)
  • 👥 Social network analysis (identifying influential individuals)
  • ⚡ Circuit design (locating critical components)
  • 🚗 Transportation networks (finding critical roads/bridges)

Files Changed

  • src/main/java/com/thealgorithms/datastructures/graphs/ArticulationPointsAndBridges.java - Main implementation (270 lines)
  • src/test/java/com/thealgorithms/datastructures/graphs/ArticulationPointsAndBridgesTest.java - Test suite (371 lines)

Checklist

  • I have read the contributing guidelines
  • The code follows the repository's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added comprehensive tests
  • The algorithm is not a duplicate of existing implementations

References


Hacktoberfest 2025 🎃

Example Usage

// Create graph
int vertices = 5;
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i < vertices; i++) {
    graph.add(new ArrayList<>());
}

// Add edges
graph.get(0).add(1); graph.get(1).add(0);
graph.get(1).add(2); graph.get(2).add(1);
graph.get(2).add(3); graph.get(3).add(2);

// Find articulation points and bridges
Result result = ArticulationPointsAndBridges.findArticulationPointsAndBridges(vertices, graph);
System.out.println(result.getArticulationPoints()); // [1, 2]
System.out.println(result.getBridges()); // [(0,1), (1,2), (2,3)] 

Implement DFS-based algorithm to find articulation points (cut vertices) and bridges (cut edges) in undirected graphs.

Features:
- Find articulation points: vertices whose removal increases connected components
- Find bridges: edges whose removal increases connected components
- Time complexity: O(V + E) using single DFS traversal
- Handles disconnected graphs
- Comprehensive test suite with 15 test cases

Implementation details:
- Uses discovery time and low-link values
- Follows Tarjan's approach for graph analysis
- Includes convenience methods for finding only points or only bridges
- Full Javadoc documentation with examples and applications

Test coverage:
- Simple graphs with single/multiple articulation points
- Graphs with no articulation points (biconnected components)
- Star graphs, disconnected graphs, edge cases
- Validates edge symmetry and proper error handling

Applications: Network reliability, social network analysis, circuit design, transportation networks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant