Binary Search Tree (also: Binary Search Tree, Binary Sort Tree)

definition

Binary sort tree is a kind of binary tree that stores data in nodes. A sort-two tree is either empty or has the following properties:

  • The root node holds a data item (and its key code).
  • If the left subtree is not empty, then all the nodes of the left subtree save the (key code) value less than (if it is not required to be strictly less than, it can also be "not greater than") the root node saves the (key code) value.
  • If the right subtree is not empty, then all the nodes of the right subtree save the (off code) value greater than the value of the root node (off code).
  • The non-empty left subtree or right subtree is also a binary sort tree.

For example, consider the key sequence KEY=[36,65,18,7,60,89,43,57,96,52,74]. The following figure shows two binary trees, each of which stores this set of data. It is not difficult to check carefully to confirm that both binary trees are binary sort trees. From this example, it can be seen that the binary sort tree corresponding to the same set of data is not unique. But the key code sequence obtained after the middle order traversal is an increasing sequence.

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44322234/article/details/111310846