B-Tree
B-Tree
Description:-
B-tree is a special type of self-balancing search tree in which each node can contain more than one key
and can have more than two children. It is a generalized form of the binary search tree. It is also known
as a height-balanced m-way tree.
Program:-
// Searching a key on a B-tree in C
#include <stdio.h>
#include <stdlib.h>
#define MAX 3
#define MIN 2
struct BTreeNode {
};
// Create a node
newNode->val[1] = val;
newNode->count = 1;
newNode->link[0] = root;
newNode->link[1] = child;
return newNode;
}
// Insert node
int j = node->count;
node->val[j + 1] = node->val[j];
node->link[j + 1] = node->link[j];
j--;
node->val[j + 1] = val;
node->link[j + 1] = child;
node->count++;
// Split node
void splitNode(int val, int *pval, int pos, struct BTreeNode *node,
int median, j;
median = MIN + 1;
else
median = MIN;
j = median + 1;
j++;
node->count = median;
} else {
*pval = node->val[node->count];
(*newNode)->link[0] = node->link[node->count];
node->count--;
int pos;
if (!node) {
*pval = val;
*child = NULL;
return 1;
} else {
if (val == node->val[pos]) {
return 0;
} else {
return 1;
return 0;
int flag, i;
if (flag)
// Search node
if (!myNode) {
return;
*pos = 0;
} else {
if (val == myNode->val[*pos]) {
return;
return;
}
// Traverse then nodes
int i;
if (myNode) {
traversal(myNode->link[i]);
traversal(myNode->link[i]);
int main() {
insert(8);
insert(9);
insert(10);
insert(11);
insert(15);
insert(16);
insert(17);
insert(18);
insert(20);
insert(23);
traversal(root);
printf("\n");
search(11, &ch, root);
OUTPUT:-
8 9 10 11 15 16 17 18 20 23
11 is found