Collection Kit

BTree

Tree

A BTree is a self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time.

Import Statement
import { BTree } from "collection-kit";

Key Features

  • Multi-way Tree: Can have multiple children per node, allowing for efficient storage.
  • Balanced Structure: Ensures that all leaf nodes are at the same depth.

Common Operations

Insert
Add a new element while maintaining balance.
Remove
Delete an element while maintaining balance.
Search
Retrieve an element from the tree.

Example Code

import { BTree } from "collection-kit";

const tree = new BTree(3); // order 3
tree.insert(10);
tree.insert(20);
tree.insert(5);
tree.insert(15);

console.log("Search 15:", tree.search(15)); // true