{"record":{"id":"02d62ae5f1949165","repo":"trekhleb/javascript-algorithms","slug":"kruskal-s-algorithms-works-only-for-undirected-gra","errorCode":null,"errorMessage":"Kruskal's algorithms works only for undirected graphs","messagePattern":"Kruskal's algorithms works only for undirected graphs","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/algorithms/graph/kruskal/kruskal.js","lineNumber":13,"sourceCode":"export default function kruskal(graph) {\n  // It should fire error if graph is directed since the algorithm works only\n  // for undirected graphs.\n  if (graph.isDirected) {\n    throw new Error('Kruskal\\'s algorithms works only for undirected graphs');\n  }","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/graph/kruskal/kruskal.js#L1-L31","documentation":"Error \"Kruskal's algorithms works only for undirected graphs\" thrown in trekhleb/javascript-algorithms.","triggerScenarios":"kruskal is called on a graph where graph.isDirected is true; the minimum spanning tree algorithm only works for undirected graphs.","commonSituations":"Passing a directed Graph instance to Kruskal's minimum spanning tree algorithm, which is defined only for undirected weighted graphs.","solutions":["Create the graph as undirected with new Graph() (the default) instead of new Graph(true).","Convert the directed graph to an undirected one before running Kruskal's algorithm.","For directed graphs use a directed-MST algorithm such as Edmonds' algorithm."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"85293e3e2b88f4d2ce330d956b139cf628aa1e82","analyzedAt":"2026-08-24T05:59:10.417Z","schemaVersion":2},"datasetVersion":"2026-08-24T07:17:09.176Z"}