Type Parameters

  • T extends NodeData

Hierarchy

  • BinarySearchTree

Implements

  • BSTree<T>

Methods

  • Delete a node from the tree

    Returns

    a self reference to the BST

    Example

    const tree = new BST<number>()
    tree.insert(1).insert(2).insert(3).delete(1)
    // Tree now has a root of 2 and right branch of 3

    Parameters

    • data: T

      data you want to delete from the tree

    Returns BinarySearchTree<T>

  • Get the maximum depth of the tree

    Returns

    the maximum depth of the tree

    Example

    const tree = new BST<number>()
    tree.insert(1).insert(2).insert(3)

    tree.getMaxDepth(); // 1

    Returns number

  • Get the node with the maximum value

    Returns

    The node with the maximum value in the tree

    Example

    const tree = new BST<number>([5, 3, 7, 2, 4, 6, 8, 1, 9, 10]);
    tree.getMaxNode(); // 10

    Returns null | BSTreeNode<T>

  • Get the node with the minimum value

    Returns

    The node with the minimum value in the tree

    Example

    const tree = new BST<number>([5, 3, 7, 2, 4, 6, 8, 1, 9, 10]);
    tree.getMinNode(); // 1

    Returns null | BSTreeNode<T>

  • insert a node into the tree

    Returns

    a self reference to the BST

    Example

    const tree = new BST<number>()
    tree.insert(1).insert(2).insert(3)

    Parameters

    • data: T

      data you want to insert into the tree

    Returns BinarySearchTree<T>

  • Search for a node with the given value

    Returns

    the node with the data or -1 if not found

    Example

    const tree = new BST<number>([5, 3, 7, 2, 4, 6, 8, 1, 9, 10]);

    tree.search(7); // Node{data:7 ,left:Node{data:6}, right:Node{data:8} }
    tree.search(50); // -1

    Parameters

    • data: T

      data you want to search for

    Returns -1 | BSTreeNode<T>

  • Logs the tree to the console

    Returns

    a self reference to the BST

    Example

    const tree = new BST<number>([5, 3, 7, 2, 4, 6, 8, 1, 9, 10]);
    tree.view();
    // 5
    // / \
    // / \
    // / \
    // {3,4,,,2,,1,,} {7,8,9,10,,,,,6,,}

    Returns BinarySearchTree<T>

Generated using TypeDoc