Skip to content

Update documentation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions graph_algorithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
var BLACK = 2

var GraphAlgorithm = {
//
// Detect loop in a directed graph, use graph coloring algorithm.
//
// @param vertices - array of vertices, a vertex is either an integer or a
// string
// @param edges - array of edges, an edge is an array of length 2 which
// marks the source and destination vertice.
// i.e., [source, dest]
//
// @return { hasLoop: true, loop: [...] }
//
/**
* Detects loops in a directed graph using a graph coloring algorithm.
*
* @param {Array} vertices - An array of vertices. Each vertex can be either
* an integer or a string.
* @param {Array} edges - An array of edges. Each edge is represented as an array of length 2,
* specifying the source and destination vertices. Format: [source, destination].
*
* @returns {Object} An object indicating whether a loop is present and, if so, the vertices
* forming the loop. The return value has the following structure:
* - hasLoop: A boolean value indicating whether a loop is present in the graph.
* - loop: An array of vertices forming the loop, listed in the order they are encountered
* during traversal.
*/
hasLoop: function(vertices, edges) {
var colors = {}
var path = []
Expand Down