4 kyu
Strongly connected components
108user5697006
Description:
Strongly connected components
Let be the set of vertices of the graph. A strongly connected component of a directed graph is a maximal subset of its vertices , so that there is an oriented path from any vertex to any other vertex .
Example
In this graph, strongly connected components are
[{a, b, e}, {f, g}, {c, d ,h}]
Task
Write a function strongly_connected_components
which accepts a graph represented as an adjacency list, and returns a list containing set of connected components.
Examples:
# Graph from the image
# The vertexes are numbered as follows:
# (0, 1, 2, 3, 4, 5, 6, 7) = (a, b, e, f, c, g, d, h).
# The list in the i-th position of the adjacency list
# contains vertices that have an incoming edge from vertex i.
# For example, from vertex 1 <=> (b), you can get to vertices
# [2, 3, 4] <=> (e, f, c).
>>> graph = [[1], [2, 3, 4], [0, 3], [5],
[5, 6], [3], [4, 7], [5, 6]]
>>> strongly_connected_components(graph)
[{3, 5}, {4, 6, 7}, {0, 1, 2}]
# One more sample
>>> graph = [[1], [2], [3, 4], [0], [5], [6], [4, 7], []]
>>> strongly_connected_components(graph)
[{7}, {4, 5, 6}, {0, 1, 2, 3}]
Note: in python scipy is disabled.
Algorithms
Data Structures
Performance
Graph Theory
Similar Kata:
Stats:
Created | Sep 30, 2020 |
Published | Sep 30, 2020 |
Warriors Trained | 458 |
Total Skips | 21 |
Total Code Submissions | 767 |
Total Times Completed | 108 |
Python Completions | 108 |
Total Stars | 38 |
% of votes with a positive feedback rating | 90% of 36 |
Total "Very Satisfied" Votes | 29 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 8 kyu |