使用 BST 时,根节点的右 child 的左后代是否可以大于根节点且 visa-versa
When working with a BST, can the left descendant of the right child of the root node be greater than the root node and visa-versa
我们在做BST的时候,我明白了一个很关键的点就是左边child一定要小于右边child。当我们创建一个 BST 并有一个根节点时,是否有可能当您遍历该根节点的左侧并到达它的右侧 child 时,右侧 child 也大于根节点?
如果我们在该根节点的右侧遍历,则同样如此。如果我们在根节点的右边遍历,会不会出现碰到一个小于根节点值的左边child?
When we are doing a BST, I understand that one major key point is that the left child must be less than the right child.
是的,这是 BST 结构的结果之一。
Is it possible when we create a BST and have a root node, that as you traverse on the left side of that root node, and reach a right child of it, that right child is also greater than the root node?
不,这是不允许的。
Wikipedia 将 BST 定义为(我以粗体突出显示)
...a rooted binary tree data structure whose internal nodes each store a key greater than all the keys in the node’s left subtree and less than those in its right subtree.
我们在做BST的时候,我明白了一个很关键的点就是左边child一定要小于右边child。当我们创建一个 BST 并有一个根节点时,是否有可能当您遍历该根节点的左侧并到达它的右侧 child 时,右侧 child 也大于根节点?
如果我们在该根节点的右侧遍历,则同样如此。如果我们在根节点的右边遍历,会不会出现碰到一个小于根节点值的左边child?
When we are doing a BST, I understand that one major key point is that the left child must be less than the right child.
是的,这是 BST 结构的结果之一。
Is it possible when we create a BST and have a root node, that as you traverse on the left side of that root node, and reach a right child of it, that right child is also greater than the root node?
不,这是不允许的。
Wikipedia 将 BST 定义为(我以粗体突出显示)
...a rooted binary tree data structure whose internal nodes each store a key greater than all the keys in the node’s left subtree and less than those in its right subtree.