Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 3: Indexing and B-Trees

Lesson 10 of 14 in the free Data Structure notes on Siksha Sarovar, written by Rohit Jangra.

Indexing: The Library Catalog Analogy

Searching a 1000-page book page-by-page is slow. An Index lets you jump directly to the right page. Database Indexing works identically — a small structure holding keys and pointers to actual data locations on disk.

Types of Indexing

TypeDescriptionLevelsSpeed
Primary IndexBuilt on the ordering key field1Fast for range queries
Secondary IndexBuilt on a non-ordering field1Slower, more flexible
Single-LevelOne index file1Good for small datasets
Multi-LevelIndex on index (tree structure)2+Required for large datasets

Multilevel Indexing: When the index itself is too large for RAM:

  • Outer Index: Fits in RAM → points to blocks of Inner Index.
  • Inner Index: On Disk → points to actual data.
  • Reduces disk accesses dramatically.

B-Trees: The Industry Standard

A B-Tree is a specialized M-Way tree that is always balanced — the gold standard for disk storage.

B-Tree Rules (Order M)

RuleDescription
RootHas at least 2 children (unless it's a leaf)
Internal NodesMust have at least ⌈M/2⌉ children
Keys per NodeMin: ⌈M/2⌉ - 1, Max: M - 1
GrowthGrows UPWARDS (splits promote median)
LeavesALL at the same depth (guaranteed)
OrderingKeys within each node are sorted

B-Tree Properties Table

PropertyFormula (Order M)Order 3Order 5
Max keys/nodeM - 124
Min keys/node (non-root)⌈M/2⌉ - 112
Max children/nodeM35
Min children/node (non-root)⌈M/2⌉23

B-Tree vs BST vs AVL — When to Use What

FeatureBSTAVLB-Tree
BalanceNoneStrict (BF ≤ 1)Strict (all leaves same depth)
Branching22M (hundreds)
HeightO(n) worstO(log n)O(log_M n)
Best ForSimple in-memoryGuaranteed in-memoryDisk/Database storage
Disk I/OMany readsMany readsMinimal reads
Used ByTeachingIn-memory mapsMySQL, PostgreSQL, NTFS, Ext4

Real World Use:

  • Databases: Oracle, MySQL, PostgreSQL use B-Trees (or B+ Trees) for indexes.
  • File Systems: NTFS (Windows), HFS+ (Mac), Ext4 (Linux) use B-Trees to organize files.