Binary Search Tree
An ordered tree where left < node < right — insert, search and traverse.
A Binary Search Tree keeps its keys ordered: everything in a node's left subtree is smaller, everything in the right subtree is larger. That invariant makes search, insert, and delete run in O(h) time, where h is the height of the tree.
BSTs are the foundation for balanced trees (AVL, red-black) and for understanding `std::set` / `std::map`. The classic pitfall is that an unbalanced BST degrades to a linked list — seeing the tree shape is the best way to build that intuition.
AlgoLens renders the tree from the real pointers in memory, so you watch each insertion walk down the correct path and attach a new node.
The code
#include <bits/stdc++.h>
using namespace std;
struct Node {
int val;
Node* left;
Node* right;
};
Node* insert(Node* root, int x) {
if (root == nullptr) return new Node{x, nullptr, nullptr};
if (x < root->val) root->left = insert(root->left, x);
else root->right = insert(root->right, x);
return root;
}
int main() {
Node* root = nullptr;
for (int x : {5, 3, 8, 1, 4, 7, 9}) {
root = insert(root, x);
}
cout << root->val << '\n';
return 0;
}
Now run your own Binary Search Tree
AlgoLens traces your code — arrays, graphs, trees and recursion — from a real execution, so you see how it actually behaves, not a canned animation.
Paste your codeKeep going
Binary Tree Traversal
In-order, pre-order, post-order — where the visit sits in the recursion.
Segment Tree
Range queries and point updates in O(log n) on an array-shaped tree.
Bubble Sort
The simplest sort — watch the largest value bubble to the end each pass.
Binary Search
Halve the search space every step — find a value in a sorted array in O(log n).