Developer

This experience deserves a bigger screen

The DSA Visualizer is designed for deep focus,
side-by-side code, and real-time execution insight.

On small screens, that level of clarity can't be preserved.

Open on a tablet (landscape) or desktop for the intended experience.

Desktop experience preview

Kth Smallest Element in a BSTStep-by-Step Visualization

In-order traversal of a BST yields sorted values, which is the key to solving this.

Problem Statement

Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.

Approach

Perform In-Order traversal (Left, Root, Right). Keep a counter. When counter reaches k, return the current node value.

Time & Space Complexity

Time complexity is O(H + k). Space complexity is O(H).

Interactive Visualization

Loading Interactive Visualizer...

Click "Play" or use arrow keys to step through the execution.