📜  二叉树和B树的区别

📅  最后修改于: 2021-09-11 04:41:16             🧑  作者: Mango

B树:
B-Tree 被称为自平衡树,因为它的节点是按中序遍历排序的。与二叉树不同,在 B 树中,一个节点可以有两个以上的子节点。 B 树的高度为 logM N(其中“M”是树的顺序,N 是节点数)。每次更新时都会自动调整高度。在 B 树中,数据按特定顺序排序,最低值在左侧,最高值在右侧。在 B 树中插入数据或键比二叉树更复杂。

B-Tree必须满足一些条件:

  • B-tree 的所有叶子节点必须在同一层。
  • 在 B 树的叶子节点之上,应该没有空的子树。
  • B-树的高度应尽可能低。

二叉树:
二叉树是一般树的特殊类型。与 B 树不同,在二叉树中,一个节点最多可以有两个节点。在二叉树中,节点的度数是有限制的,因为二叉树中的节点不能有两个以上的子节点(或度数为二)。二叉树的最顶层节点称为根节点,主要有两种子树,一种是左子树,一种是右子树。与一般树不同,二叉树可以是空的。和 B 树一样,二叉树也可以按中序遍历排序。但它也可以按前序和后序排序。在二叉树中,数据插入并不比 B 树复杂。

让我们看看B树和二叉树的区别:

S.NO B-tree Binary tree
1. In a B-tree, a node can have maximum ‘M'(‘M’ is the order of the tree) number of child nodes. While in binary tree, a node can have maximum two child nodes or sub-trees.
2. B-tree is called as sorted tree as its nodes are sorted in inorder traversal. While binary tree is not a sorted tree. It can be sorted in inorder, preorder or postorder traversal.
3. B-tree has a height of logM N (Where ‘M’ is the order of tree and N is the number of nodes). While binary tree has a height of log2 N(Where N is the number of nodes).
4. B-Tree is performed when the data is loaded in the disk. Unlike B-tree, binary tree is performed when the data is loaded in the RAM(faster memory).
5. B-tree is used in DBMS(code indexing, etc). While binary tree is used in Huffman coding and Code optimization and many others.
6. To insert the data or key in B-tree is more complicated than binary tree. While in binary tree, data insertion is not complicated than B-tree.

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程。