Btree DB
Btree DB
Sign In
Home
Saved Videos
Courses
Data Structures and Algorithms
ML & Data Science
Web Development
Languages
Interview Corner
CS Subjects
Jobs
Practice
Contests
GBlog
Puzzles
What's New ?
Change Language
DSA Tutorial
Data Structures
Algorithms
Array
Strings
Linked List
Stack
Queue
Tree
Graph
Searching
Sorting
Recursion
Dynamic Programming
Binary Tree
Binary Search Tree
Heap
Hashing
Divide & Conquer
Mathematical
Geometric
Bitwise
Greedy
Backtracking
Branch and Bound
Matrix
Pattern Searching
Randomized
Open In App
Introduction of B-Tree
Last Updated : 28 Dec, 2023
The limitations of traditional binary search trees can be frustrating.
Meet the B-Tree, the multi-talented data structure that can handle
massive amounts of data with ease. When it comes to storing and
searching large amounts of data, traditional binary search trees can
become impractical due to their poor performance and high memory
usage. B-Trees, also known as B-Tree or Balanced Tree, are a type of
self-balancing tree that was specifically designed to overcome these
limitations.
Unlike traditional binary search trees, B-Trees are characterized by the
large number of keys that they can store in a single node, which is why
they are also known as “large key” trees. Each node in a B-Tree can
contain multiple keys, which allows the tree to have a larger branching
factor and thus a shallower height. This shallow height leads to less
disk I/O, which results in faster search and insertion operations. B-
Trees are particularly well suited for storage systems that have slow,
bulky data access such as hard drives, flash memory, and CD-ROMs.
B-Trees maintains balance by ensuring that each node has a minimum
number of keys, so the tree is always balanced. This balance
guarantees that the time complexity for operations such as insertion,
deletion, and searching is always O(log n), regardless of the initial
shape of the tree.
Time Complexity of B-Tree:
1. Search O(log n)
2. Insert O(log n)
3. Delete O(log n)
struct Node {
int n;
int key[MAX_KEYS];
Node* child[MAX_CHILDREN];
bool leaf;
};
int i = 0;
i++;
return x;
if (x->leaf) {
return nullptr;
return BtreeSearch(x->child[i],
k);
C
Java
Python3
C#
Javascript
Examples:
Input: Search 120 in the given B-Tree.
Solution:
In this example, we can see that our search was reduced by just
limiting the chances where the key containing the value could be
present. Similarly if within the above example we’ve to look for 180,
then the control will stop at step 2 because the program will find that
the key 180 is present within the current node. And similarly, if it’s to
seek out 90 then as 90 < 100 so it’ll go to the left subtree
automatically, and therefore the control flow will go similarly as shown
within the above example.
Below is the implementation of the above approach:
C++
#include <iostream>
// A BTree node
class BTreeNode {
// of keys)
BTreeNode** C; // An array of
child pointers
public:
void traverse();
// this node.
BTreeNode*
search(int k); // returns NULL if
k is not present.
};
// A BTree
class BTree {
public:
BTree(int _t)
root = NULL;
t = _t;
void traverse()
if (root != NULL)
root->traverse();
}
BTreeNode* search(int k)
};
t = _t;
leaf = _leaf;
n = 0;
}
// Function to traverse all nodes in
a subtree rooted with
// this node
void BTreeNode::traverse()
int i;
if (leaf == false)
C[i]->traverse();
if (leaf == false)
C[i]->traverse();
BTreeNode* BTreeNode::search(int k)
{
// Find the first key greater
than or equal to k
int i = 0;
i++;
if (keys[i] == k)
return this;
if (leaf == true)
return NULL;
return C[i]->search(k);
Java
Python3
C#
Javascript
Note: The above code doesn’t contain the driver program. We will be
covering the complete program in our next post on B-Tree Insertion.
There are two conventions to define a B-Tree, one is to define by
minimum degree, second is to define by order. We have followed the
minimum degree convention and will be following the same in coming
posts on B-Tree. The variable names used in the above program are
also kept the same
Applications of B-Trees:
It is used in large databases to access data stored on the disk
Searching for data in a data set can be achieved in
significantly less time using the B-Tree
With the indexing feature, multilevel indexing can be achieved.
Most of the servers also use the B-tree approach.
B-Trees are used in CAD systems to organize and search
geometric data.
B-Trees are also used in other areas such as natural language
processing, computer networks, and cryptography.
Advantages of B-Trees:
B-Trees have a guaranteed time complexity of O(log n) for
basic operations like insertion, deletion, and searching, which
makes them suitable for large data sets and real-time
applications.
B-Trees are self-balancing.
High-concurrency and high-throughput.
Efficient storage utilization.
Disadvantages of B-Trees:
B-Trees are based on disk-based data structures and can have
a high disk usage.
Not the best for all cases.
Slow in comparison to other data structures.
Insertion and Deletion:
B-Tree Insertion
B-Tree Deletion
163
Next Article
Insert Operation in B-Tree
Similar Reads
Introduction to R-tree
R-tree is a tree data structure used for storing spatial data indexes in
an efficient manner. R-trees are highly useful for spatial data queries
and storage. Some of the real-life applications are mentioned below:
Indexing multi-dimensional information.Handling geospatial
coordinates.Implementation of virtual maps.Handling game data.
Example: R-Tre
1 min read
Introduction of B+ Tree
B + Tree is a variation of the B-tree data structure. In a B + tree,
data pointers are stored only at the leaf nodes of the tree. In a B+
tree structure of a leaf node differs from the structure of internal
nodes. The leaf nodes have an entry for every value of the search
field, along with a data pointer to the record (or to the block that
contains
8 min read
Article Tags :
Advanced Data Structure
DBMS
DSA
DBMS Indexing
+1 More
Practice Tags :
Advanced Data Structure
Corporate & Communications Address:- A-143, 9th Floor, Sovereign Corporate Tower,
Sector- 136, Noida, Uttar Pradesh (201305) | Registered Address:- K 061, Tower K,
Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh,
201305
Company
About Us
Legal
In Media
Contact Us
Advertise with us
GFG Corporate Solution
Placement Training Program
GeeksforGeeks Community
Languages
Python
Java
C++
PHP
GoLang
SQL
R Language
Android Tutorial
Tutorials Archive
DSA
Data Structures
Algorithms
DSA for Beginners
Basic DSA Problems
DSA Roadmap
Top 100 DSA Interview Problems
DSA Roadmap by Sandeep Jain
All Cheat Sheets
Data Science & ML
Data Science With Python
Data Science For Beginner
Machine Learning
ML Maths
Data Visualisation
Pandas
NumPy
NLP
Deep Learning
Web Technologies
HTML
CSS
JavaScript
TypeScript
ReactJS
NextJS
Bootstrap
Web Design
Python Tutorial
Python Programming Examples
Python Projects
Python Tkinter
Web Scraping
OpenCV Tutorial
Python Interview Question
Django
Computer Science
Operating Systems
Computer Network
Database Management System
Software Engineering
Digital Logic Design
Engineering Maths
Software Development
Software Testing
DevOps
Git
Linux
AWS
Docker
Kubernetes
Azure
GCP
DevOps Roadmap
System Design
High Level Design
Low Level Design
UML Diagrams
Interview Guide
Design Patterns
OOAD
System Design Bootcamp
Interview Questions
Inteview Preparation
Competitive Programming
Top DS or Algo for CP
Company-Wise Recruitment Process
Company-Wise Preparation
Aptitude Preparation
Puzzles
School Subjects
Mathematics
Physics
Chemistry
Biology
Social Science
English Grammar
Commerce
World GK
GeeksforGeeks Videos
DSA
Python
Java
C++
Web Development
Data Science
CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved