课程: Java Algorithms
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
What are tree traversals?
- [Instructor] With a binary tree, data is stored without any ordering constraints. Data is simply placed in the next available slot. This means, that in order to search for an element or manipulate data in the tree, one must iterate through the tree. We call this traversing a tree, or visiting each node in the tree to display or manipulate its data. When traversing a tree, we have a few different options, depending on which nodes we visit first, and which nodes we visit last. For example, one way we could traverse the tree is to recursively traverse the left subtree, then visit the root node, and then recursively traverse the right subtree. The leftmost subtree is eight, with no children nodes. So that would be displayed first. Then it's root, two, and then the right subtree, 11. Continuing up the tree, the root is five, and its right subtree has seven. These nodes are visited in an order from left to right, eight, two, 11, five, and seven. So we call this an in-order traversal…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。