Class BTree<T>

Class representing a B-Tree, a balanced tree structure for efficient insertion, deletion, and search operations. Each node can have a variable number of keys and child nodes, based on the minimum degree.

Type Parameters

  • T

    The type of keys stored in the tree.

Constructors

Methods

Constructors

  • Creates an instance of BTree.

    Type Parameters

    • T

    Parameters

    • t: number

      Minimum degree (defines the range for the number of keys in nodes).

    • comparator: ((a: T, b: T) => number)

      A comparator function for comparing keys.

        • (a, b): number
        • Parameters

          Returns number

    Returns BTree<T>

Methods

  • Prints the B-Tree structure for visualization, showing levels and keys at each node.

    Parameters

    • node: BTreeNode<T> = ...

      The node to print (default is the root).

    • depth: number = 0

      The current level of the node.

    Returns string

    • The string representation of the tree.
  • Searches for a key in the B-Tree, starting from the root or a specified node.

    Parameters

    • key: T

      The key to search for.

    • Optionalnode: BTreeNode<T> = ...

      The node to start the search from.

    Returns BTreeNode<T>

    • The node containing the key, or null if not found.