https://github.com/sleekpanther/graph-strong-connectivity
Application of Breadth-First Search to see if a directed graph is Strongly Connected
https://github.com/sleekpanther/graph-strong-connectivity
algorithm-design bfs breadth-first-search directed directed-edge directed-graph edge graph-algorithms graphs noah noah-patullo noahpatullo pattullo pattulo patullo patulo strong-connectivity strongly strongly-connected strongly-connected-components
Last synced: about 1 month ago
JSON representation
Application of Breadth-First Search to see if a directed graph is Strongly Connected
- Host: GitHub
- URL: https://github.com/sleekpanther/graph-strong-connectivity
- Owner: SleekPanther
- Created: 2017-07-28T22:39:21.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-30T15:00:46.000Z (almost 9 years ago)
- Last Synced: 2025-12-06T14:24:16.614Z (6 months ago)
- Topics: algorithm-design, bfs, breadth-first-search, directed, directed-edge, directed-graph, edge, graph-algorithms, graphs, noah, noah-patullo, noahpatullo, pattullo, pattulo, patullo, patulo, strong-connectivity, strongly, strongly-connected, strongly-connected-components
- Language: Java
- Homepage:
- Size: 170 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Strong Connectivity
Application of Breadth-First Search to see if a directed graph is Strongly Connected
## Problem Statement
- Vertex `u` and `v` are **mutually reachable** if there is a path from `u` to `v` and also a path from `v` to `u`
- A directed graph is **strongly connected** if every pair of nodes is mutually reachable
## Algorithm
- Run BFS from any vertex
- Make Grev, a new graph with edge directions reversed
- Run BFS on Grev
- Return true iff every vertex is reachable in both BFS on G and BFS on Grev
## Input Graphs
### Graph 1 (is stronly connected)

### Graph 1 Reversed

### Graph 2 (NOT stronly connected)

### Graph 2 Reversed

## Usage
- Make a `new StrongConnectivity()` object
- Create a graph as an `ArrayList>` **Adjacency List**
- Each `graph.get(u)` is an `ArrayList` of vertices representing edges going **From `u`**
- Vertex names are simply increasing integer values, no need for human-readable vertex ID's like `S` or `T`
- Graph adjacency list must have all edges represented
- If there are no outgoing edges from a vertex, add an empty `ArrayList`
`graph2.add(new ArrayList());`
- Call `isStronglyConnected()` and pass in a graph
`boolean isGraph1StronglyConnected = strongConnectivityFinder.isStronglyConnected(graph1);`
## Code Notes
- `isStronglyConnected()` always chooses vertex `0` to start BFS, but that's completely arbitrary
## References
- [Strong Connectivity - Richard Zanibbi](https://www.cs.rit.edu/~rlaz/algorithms20082/slides/DAGs.pdf#page=4)
- [Strong Connectivity - Kevin Wayne](https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/03Graphs.pdf#page=41)
- [Strong Connectivity - Jaehyun Park](https://web.stanford.edu/class/cs97si/06-basic-graph-algorithms.pdf#page=36)