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
Tree traversal
(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!
===Data structures for tree traversal=== Traversing a tree involves iterating over all nodes in some manner. Because from a given node there is more than one possible next node (it is not a linear data structure), then, assuming sequential computation (not parallel), some nodes must be deferred—stored in some way for later visiting. This is often done via a [[Stack (abstract data type)|stack]] (LIFO) or [[Queue (abstract data type)|queue]] (FIFO). As a tree is a self-referential (recursively defined) data structure, traversal can be defined by [[recursion]] or, more subtly, [[corecursion]], in a natural and clear fashion; in these cases the deferred nodes are stored implicitly in the [[call stack]]. Depth-first search is easily implemented via a stack, including recursively (via the call stack), while breadth-first search is easily implemented via a queue, including corecursively.<ref name="Pfaff">{{cite book|last1=Pfaff|first1=Ben|title=An Introduction to Binary Search Trees and Balanced Trees|date=2004|publisher=Free Software Foundation, Inc.}}</ref>{{rp|45−61}}
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)