šŸ”
šŸ‘¶ KidsšŸ“ Blog About Contact šŸš€ Get Started Free

Algorithms

Understand what algorithms are, how to measure their efficiency, and explore common sorting and searching techniques.

What is an Algorithm?

An algorithm is a step-by-step set of instructions for solving a problem. Every program you use is built on algorithms — from Google Search ranking pages to your phone's GPS finding the fastest route.

Time & Space Complexity (Big O Notation)

Big O Notation describes how an algorithm's performance scales as input size grows. Common complexities from fastest to slowest:

  • O(1) — Constant time. Array index access.
  • O(log n) — Logarithmic. Binary search.
  • O(n) — Linear. Looping through an array.
  • O(n log n) — Merge sort, quicksort (average).
  • O(n²) — Quadratic. Bubble sort, nested loops.
  • O(2ⁿ) — Exponential. Brute-force recursion.

Sorting Algorithms

  • Bubble Sort — Repeatedly swaps adjacent elements. Simple but O(n²). Good for teaching only.
  • Selection Sort — Finds the minimum and places it at the front. Also O(n²).
  • Insertion Sort — Builds sorted array one item at a time. O(n²) worst, O(n) best.
  • Merge Sort — Divides and conquers. Always O(n log n). Stable sort.
  • Quick Sort — Picks a pivot and partitions. O(n log n) average, O(n²) worst.
  • Heap Sort — Uses a heap data structure. Always O(n log n).

Searching Algorithms

  • Linear Search — Check each element one by one. O(n). Works on unsorted data.
  • Binary Search — Halves the search space each step. O(log n). Requires sorted data.

Graph Algorithms

  • BFS (Breadth-First Search) — Explores all neighbors level by level. Used for shortest path in unweighted graphs.
  • DFS (Depth-First Search) — Goes as deep as possible before backtracking. Used for cycle detection and topological sort.
  • Dijkstra's Algorithm — Finds the shortest path in weighted graphs.

What's Next?

Practice with real code in our Web Tutorials, or explore Software Engineering to see how algorithms fit into larger systems.