Depth-first
There are three types of depth-first traversal: pre-order, in-order, and post-order For a binary tree, they are defined as display operations recursively at each node, starting with the root node, whose algorithm is as follows:Pre-order
- Display the data part of root element (or current element)
- Traverse the left subtree by recursively calling the pre-order function.
- Traverse the right subtree by recursively calling the pre-order function.
In-order
- Traverse the left subtree by recursively calling the in-order function.
- Display the data part of root element (or current element).
- Traverse the right subtree by recursively calling the in-order function.
Post-order
- Traverse the left subtree by recursively calling the post-order function.
- Traverse the right subtree by recursively calling the post-order function.
- Display the data part of root element (or current element).
Class | Search algorithm |
---|---|
Data structure | Graph |
Worst case performance | for explicit graphs traversed without repetition, for implicit graphs with branching factor b searched to depth d |
Worst case space complexity | if entire graph is traversed without repetition, O(longest path length searched) for implicit graphs without elimination of duplicate nodes |
No comments:
Post a Comment