Commit d71074c0 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Implemented a recursive DFS.

parent 8bd2a1ec
......@@ -129,6 +129,19 @@ export function bestFirst(graph, source, destination) {
return undefined;
}
export function recursiveDFS(graph, source, destination) {
return undefined; // TODO: stub
export function recursiveDFS(graph, source, destination, visited = new Set()) {
if (visited.has(source)) {
return undefined;
}
visited.add(source);
if (source === destination) {
return [destination];
}
for (const incidence of graph.getIncidences(source)) {
const suffix = recursiveDFS(graph, incidence.destination, destination, visited);
if (suffix !== undefined) {
return [source, ...suffix];
}
}
return undefined;
}
......@@ -29,7 +29,7 @@ function formatSolution(solution) {
}
export function Solution(props) {
const search = bestFirst;
const search = recursiveDFS;
const firstSolution = search(firstExample, 'a', 'd');
const secondSolution = search(secondExample, '123', '321');
return (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment