2020-07-14(二叉树的类型)

  1. 二叉搜索树( binary search tree)的定义:
    Assume a BST is defined as follows:
  • The left subtree of a node contains only nodes with keys less than the node's key.
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • Both the left and right subtrees must also be binary search trees.

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/validate-binary-search-tree
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

  1. 高度平衡的二叉树

a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

3. 二叉树的类型

1. 满二叉树 Full Binary Tree

  • If each node of binary tree has either two children or no child at all, is said to be a Full Binary Tree.
  • Full binary tree is also called as Strictly Binary Tree.
full binary tree
  • Every node in the tree has either 0 or 2 children.
  • Full binary tree is used to represent mathematical expressions.

2. 完全二叉树 Complete Binary Tree

  • If all levels of tree are completely filled except the last level and the last level has all keys as left as possible, is said to be a Complete Binary Tree.
  • Complete binary tree is also called as Perfect Binary Tree.
complete binary tree
  • In a complete binary tree, every internal node has exactly two children and all leaf nodes are at same level.
  • For example, at Level 2, there must be 22 = 4 nodes and at Level 3 there must be 23 = 8 nodes.

2.AVL Tree

  • AVL tree is a height balanced tree.
  • It is a self-balancing binary search tree.
  • AVL tree is another balanced binary search tree.
  • It was invented by Adelson-Velskii and Landis.
  • AVL trees have a faster retrieval.
  • It takes O(logn) time for addition and deletion operation.
  • In AVL tree, heights of left and right subtree cannot be more than one for all nodes.
avl tree
  • The above tree is AVL tree because the difference between heights of left and right subtrees for every node is less than or equal to 1.
image.png
  • The above tree is not AVL because the difference between heights of left and right subtrees for 9 and 19 is greater than 1.
  • It checks the height of the left and right subtree and assures that the difference is not more than 1. The difference is called balance factor.
    参考链接:https://www.tutorialride.com/data-structures/types-of-binary-tree.htm

你可能感兴趣的:(2020-07-14(二叉树的类型))