File tree 1 file changed +14
-11
lines changed
1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 4
4
var BLACK = 2
5
5
6
6
var GraphAlgorithm = {
7
- //
8
- // Detect loop in a directed graph, use graph coloring algorithm.
9
- //
10
- // @param vertices - array of vertices, a vertex is either an integer or a
11
- // string
12
- // @param edges - array of edges, an edge is an array of length 2 which
13
- // marks the source and destination vertice.
14
- // i.e., [source, dest]
15
- //
16
- // @return { hasLoop: true, loop: [...] }
17
- //
7
+ /**
8
+ * Detects loops in a directed graph using a graph coloring algorithm.
9
+ *
10
+ * @param {Array } vertices - An array of vertices. Each vertex can be either
11
+ * an integer or a string.
12
+ * @param {Array } edges - An array of edges. Each edge is represented as an array of length 2,
13
+ * specifying the source and destination vertices. Format: [source, destination].
14
+ *
15
+ * @returns {Object } An object indicating whether a loop is present and, if so, the vertices
16
+ * forming the loop. The return value has the following structure:
17
+ * - hasLoop: A boolean value indicating whether a loop is present in the graph.
18
+ * - loop: An array of vertices forming the loop, listed in the order they are encountered
19
+ * during traversal.
20
+ */
18
21
hasLoop : function ( vertices , edges ) {
19
22
var colors = { }
20
23
var path = [ ]
You can’t perform that action at this time.
0 commit comments