DSA Lesson 16 of 33

Binary Search Tree

Learn how BSTs organize values for efficient searching.

Course Progress48%

Theory

A Binary Search Tree is a binary tree where values smaller than a node are placed in the left subtree and values greater than the node are placed in the right subtree. This ordering can make searching efficient when the tree is balanced.

Example

class Node { constructor(value) { this.value = value; this.left = null; this.right = null; } } const root = new Node(20); root.left = new Node(10); root.right = new Node(30); console.log(root.left.value); console.log(root.right.value);

Expected Output

10 and 30

Practice

Build a BST using the values 50, 30, 70, 20 and 40.

Interview Questions

  1. What is a binary search tree?
  2. What property does a BST follow?
  3. Why can BST searching be efficient?
  4. What happens when a BST becomes unbalanced?