Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Iterative deepening depth-first search
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Algorithm for directed graphs== The following pseudocode shows IDDFS implemented in terms of a recursive depth-limited DFS (called DLS) for [[directed graph]]s. This implementation of IDDFS does not account for already-visited nodes. '''function''' IDDFS(root) '''is''' '''for''' depth '''from''' 0 '''to''' β '''do''' found, remaining β DLS(root, depth) '''if''' found β '''null''' '''then''' '''return''' found '''else if''' not remaining '''then''' '''return''' '''null''' '''function''' DLS(node, depth) '''is''' '''if''' depth = 0 '''then''' '''if''' node is a goal '''then''' '''return''' (node, '''true''') '''else''' '''return''' ('''null''', '''true''') ''(Not found, but may have children)'' '''else if''' depth > 0 '''then''' any_remaining β '''false''' '''foreach''' child '''of''' node '''do''' found, remaining β DLS(child, depthβ1) '''if''' found β null '''then''' '''return''' (found, '''true''') '''if''' remaining '''then''' any_remaining β true ''(At least one node found at depth, let IDDFS deepen)'' '''return''' ('''null''', any_remaining) If the goal node is found by '''DLS''', '''IDDFS''' will return it without looking deeper. Otherwise, if at least one node exists at that level of depth, the ''remaining'' flag will let '''IDDFS''' continue. [[Tuple|2-tuples]] are useful as return value to signal '''IDDFS''' to continue deepening or stop, in case tree depth and goal membership are unknown ''a priori''. Another solution could use [[sentinel value]]s instead to represent ''not found'' or ''remaining level'' results.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)