Skip to content

Commit 66bb188

Browse files
committed
Update documentation
1 parent 2733b17 commit 66bb188

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

graph_algorithm.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
var BLACK = 2
55

66
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+
*/
1821
hasLoop: function(vertices, edges) {
1922
var colors = {}
2023
var path = []

0 commit comments

Comments
 (0)