๐ŸŒฟBinary Search Tree

Follow Me

๐ŸŒณ Binary Search Tree (BST)

๐Ÿ”น Definition:

A Binary Search Tree is a type of binary tree in which each node has:

  • At most two children: left and right

  • Left child contains nodes less than the parent

  • Right child contains nodes greater than the parent

๐Ÿ”ง Rules of BST:

  1. Left subtree has values less than the node

  2. Right subtree has values greater than the node

  3. No duplicate nodes allowed

๐Ÿง  Basic Operations:

OperationPurpose
Insertion()
    Add a new value    ๐Ÿ‘ˆ Click Here
Searching()
    Find a value    ๐Ÿ‘ˆ Click Here
Deletion()
    Remove a value    ๐Ÿ‘ˆ Click Here
InOrder()
    Traverse in sorted order    ๐Ÿ‘ˆ Click Here
PreOrder()
    Traverse node → left → right    ๐Ÿ‘ˆ Click Here
PostOrder()
    Traverse left → right → node    ๐Ÿ‘ˆ Click Here

Advantages:

  • Faster searching than regular binary tree (O(log n) for balanced trees)

  • In-order traversal gives sorted data

Disadvantages:

  • If unbalanced, time complexity can degrade to O(n)

  • Need rebalancing (e.g., using AVL or Red-Black Trees)

๐Ÿ“Š Use Cases:

  • Search engines

  • Databases (indexing)

  • File systems


No comments:

Post a Comment

➡️DSA using Python: Assignment-8: Stack Extending List

This assignment is designed for practicing Stack implementation using Python by extending the built-in list class. It helps you learn how ...