pull/29225/head^2
Jozef Maloch 2019-05-13 00:35:05 +02:00 committed by Randell Dawson
parent 01163b2c6b
commit d23f5ea952
1 changed files with 7 additions and 6 deletions

View File

@ -17,16 +17,17 @@ Properties of B-Tree:
7) B-Tree grows and shrinks from root which is unlike Binary Search Tree. Binary Search Trees grow downward and also shrink from downward. 7) B-Tree grows and shrinks from root which is unlike Binary Search Tree. Binary Search Trees grow downward and also shrink from downward.
8) Like other balanced Binary Search Trees, time complexity to search, insert and delete is O(Log(n)). 8) Like other balanced Binary Search Trees, time complexity to search, insert and delete is O(Log(n)).
Search: ### Search:
Search is similar to search in Binary Search Tree. Let the key to be searched be k. We start from root and recursively traverse down. For every visited non-leaf node, if the node has key, we simply return the node. Otherwise we recur down to the appropriate child (the child which is just before the first greater key) of the node. If we reach a leaf node and dont find k in the leaf node, we return NULL. Search is similar to search in Binary Search Tree. Let the key to be searched be k. We start from root and recursively traverse down. For every visited non-leaf node, if the node has key, we simply return the node. Otherwise we recur down to the appropriate child (The child which is just before the first greater key) of the node. If we reach a leaf node and dont find k in the leaf node, we return NULL.
Traverse: ### Traverse:
Traversal is also similar to Inorder traversal of Binary Tree. We start from the leftmost child, recursively print the leftmost child, then repeat the same process for remaining children and keys. In the end, recursively print the rightmost child. Traversal is also similar to Inorder traversal of Binary Tree. We start from the leftmost child, recursively print the leftmost child, then repeat the same process for remaining children and keys. In the end, recursively print the rightmost child.
Insertion: ### Insert
We insert into the bottom of a B-tree, similar to binary search trees. First, find an appropriate place at the bottom of the tree to insert a given key, and perform the insertion (also adding an additional empty child). If the node is too big (it has m keys and m + 1 (empty) children), split the node. First we search and find out to which node the key should belong to and we insert it into it. Afterwards we look for and fix these problems:
If the number of keys is too high(greater than t - 1) then we move the middle key to the nodes parent. We do this recursively up until root. If the number of keys in the root is too high, then we make the middle key to be the new root of the whole tree and connect it to the node it was in before.
Time Analysis for B-Tree: ### Time Analysis for B-Tree:
Suppose a B-tree has n elements and M is the maximum number of children a node can have. What is the maximum depth the tree could have? What is the minimum depth the tree could have? Suppose a B-tree has n elements and M is the maximum number of children a node can have. What is the maximum depth the tree could have? What is the minimum depth the tree could have?