简体   繁体   English

为什么在树遍历的 PreOrder、InOrder 和 PostOrder 中,LEFT 总是在 RIGHT 之前遍历

[英]Why LEFT is always traversed before RIGHT in PreOrder, InOrder & PostOrder of Tree Traversal

The total traversal combinations, possible for the below mentioned Sample Tree are下面提到的样本树可能的总遍历组合是

DLR, LDR, LRD, DRL, RDL, RLD

Sample Tree [ D=root, L= LeftNode, R= RightNode ]样本树 [ D=root, L= LeftNode, R= RightNode ]

  D
 / \
L   R

PreOrder: DLR预购:DLR

InOrder: LDR顺序:LDR

PostOrder: LRD邮购:LRD

Why other combinations like DRL, RDL & RLD never considered?为什么从未考虑过DRL、RDL 和 RLD等其他组合?

In a binary tree, the first child is on the left and the second child is on the right.在二叉树中,第一个孩子在左边,第二个孩子在右边。 In the combinations, DRL, RDL, and RLD , R comes before L which is against the concept of Tree and therefore they are never considered for the traversal of a binary tree.DRL、RDL 和 RLD的组合中, R L之前,这违反了树的概念,因此从不考虑将它们用于二叉树的遍历。

Check this to learn more about the Tree data structure.检查以了解有关 Tree 数据结构的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM