Sorting โ 6 Algorithms
๐ซง Bubble Sort โ Compares adjacent elements and "bubbles" the larger value to the right. Each pass is colour-coded to show the maximum value settling at the end. Live counters track comparisons (red), swaps (yellow), and sorted elements (green).
๐ฏ Selection Sort โ Scans the unsorted region for the minimum value (blue pivot ยท orange current minimum) and swaps it to the front. Always performs O(nยฒ) comparisons, but keeps the number of swaps to a minimum.
๐ Insertion Sort โ Takes the next element and inserts it into its correct position within the already-sorted region. An adaptive algorithm that approaches O(n) on nearly-sorted arrays.
๐ Merge Sort โ Recursively splits the array in half, then merges the halves back together. The merge step โ comparing two sub-arrays and placing elements in order โ is shown as blue bars. Stable sort with a guaranteed O(n log n) time.
โก Quick Sort โ Picks a pivot (orange) and partitions the array so smaller values go left and larger values go right, then recurses on each side. Average O(n log n), worst case O(nยฒ). Once a pivot's final position is confirmed, it turns green.
๐๏ธ Heap Sort โ Builds a Max-Heap from the array (heapification), then repeatedly extracts the root (maximum). In-place sort with a guaranteed O(n log n) time.
Graph โ 4 Algorithms
๐ BFS โ Explores outward from the start node one layer (hop) at a time. Guarantees the shortest path by hop count in unweighted graphs, then traces the route back through parent pointers once the goal is reached.
๐ DFS โ Recurses as deep as possible along each branch before backtracking. Does not guarantee the shortest path, but is the foundation for connectivity checks, topological sorting, and cycle detection.
๐บ๏ธ Dijkstra โ Finds the true shortest distance in a weighted graph. A priority queue ensures the lowest-cost node is always processed first; edge weights are displayed inside each node.
โญ A* โ Dijkstra plus a heuristic (Euclidean distance to the goal). The formula f(n) = g(n) + h(n) steers the search toward the target, making it faster than Dijkstra in practice. Guarantees an optimal path as long as the heuristic is admissible.