Learn Data Structures & Algorithms
Master the fundamentals with interactive visualizations and hands-on coding challenges.
BinarySearchTree.js
class Node {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor() {
this.root = null;
}
insert(value) {
const newNode = new Node(value);
if (!this.root) {
this.root = newNode;
return this;
}
let current = this.root;
while (true) {
if (value === current.value) return this;
if (value < current.value) {
if (!current.left) {
current.left = newNode;
return this;
}
current = current.left;
} else {
if (!current.right) {
current.right = newNode;
return this;
}
current = current.right;
}
}
}
find(value) {
if (!this.root) return false;
let current = this.root;
let found = false;
while (current && !found) {
if (value < current.value) {
current = current.left;
} else if (value > current.value) {
current = current.right;
} else {
found = true;
}
}
return found ? current : false;
}
}Master Data Structures & Algorithms
Our interactive platform helps you learn DSA concepts through visualizations, step-by-step explanations, and hands-on coding challenges.
Visualize Algorithms in Action
See how algorithms work step-by-step with our interactive visualizations
Bubble Sort
Speed:
Algorithm Details:
Bubble Sort works by repeatedly stepping through the list, comparing adjacent elements and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed.
Time Complexity: O(n²) in worst and average cases