Skip to content

Files

Latest commit

cb5db58 Β· Nov 8, 2024

History

History

Binary Search Tree (BST)

Binary Search Tree

Overview

A Binary Search Tree (BST) is a data structure that enables efficient searching, insertion, and deletion of values. In a BST, each node has at most two children: the left child contains values less than the parent node, and the right child contains values greater than the parent node.

Operations

1. Insertion

  • Iterative Insert: Insert a new node into the BST using an iterative approach.
  • Recursive Insert: Insert a new node using a recursive method.

2. Traversal

  • PreOrder Traversal: Visit nodes in the order of Root β†’ Left β†’ Right.
  • InOrder Traversal: Visit nodes in the order of Left β†’ Root β†’ Right.
  • PostOrder Traversal: Visit nodes in the order of Left β†’ Right β†’ Root.

3. Searching

  • Iterative Search: Search for a specific key using an iterative method.
  • Recursive Search: Search for a specific key using recursion.

4. Deletion

  • Delete: Remove a node from the BST while maintaining its properties.
  • Delete Iterative: Delete a node from the BST using an iterative approach.

5. Additional Functions

  • Height: Calculate the height of the BST.
  • Inorder Predecessor: Find the largest node in the left subtree of a given node.
  • Inorder Successor: Find the smallest node in the right subtree of a given node.
  • Generate Tree from PreOrder: Create a BST from a given preorder traversal.
  • Mirror: Create a mirror image of the BST.

Usage

Follow the menu prompts in the code to perform operations on the BST. You can insert values, traverse the tree, search for elements, delete nodes, and more.