Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CSCE 310
Graph Search
Commits
d71074c0
Commit
d71074c0
authored
Sep 28, 2022
by
Brady James Garvin
Browse files
Implemented a recursive DFS.
parent
8bd2a1ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
graph-search/src/features/search/search.js
View file @
d71074c0
...
...
@@ -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
;
}
graph-search/src/features/search/solution.js
View file @
d71074c0
...
...
@@ -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
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment