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
著作權歸領扣網絡所有。商業(yè)轉載請聯系官方授權,非商業(yè)轉載請注明出處。

  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
著作權歸領扣網絡所有。商業(yè)轉載請聯系官方授權,非商業(yè)轉載請注明出處。

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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容