StudyDSA logoStudyDSA

Command Palette

Search for a command to run...

Sign InSign Up
Sign Up

Two PointersFast & Slow PointersSliding WindowBinary SearchPrefix SumsRecursionTree TraversalSortingBacktracking1D Dynamic ProgrammingGreedyIntervalsBit OperationsDepth-First SearchBreadth-First Search2D Dynamic ProgrammingTwo-Heaps PatternDijkstra's AlgorithmA* Search AlgorithmFloyd-Warshall's AlgorithmBellman-Ford AlgorithmPrim's AlgorithmKruskal's AlgorithmTopological SortDAG Shortest Path

Definition
StudyDSA

Where complexity meets clarity.
By Armas Zarra.

Topics

  • Data Structures
  • Algorithms
  • Big-O Notation
  • Robotics
  • AI Research
  • Machine Learning

Practice

  • Blind 75
  • LeetCode 75
  • NeetCode 150

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Armas Films LLC

IntroductionAlgorithms

Algorithms

A step-by-step procedure for solving a problem or accomplishing a task.

Definition

A simple program on your PC can take either seconds or hours to run, and it all depends on the algorithm used. An algorithm is an exact sequence of steps the program takes to reach an answer. It's a procedure that a computer follows very precisely, so you need to be careful to choose a good algorithm. Optimizing an algorithm is one of the easiest ways to unlock a performance upgrade, and it's a skill you can master over time. Good luck!

Learning Path

These are not all the algorithms in the world. There are thousands, if not millions, of famous algorithms developed by programmers around the world to solve a specific issue (check out Chess Programming for some wacky algorithms!). However, the algorithms below will equip you with a methodical way of thinking that will allow you to not only understand existing algorithms but also invent and optimize your own. This stuff will genuinely change the circuitry in your brain (check out this research paper).

Basics

These are the foundational algorithms that everything else builds on. I urge you to spend extra time within these pages to try and understand when and why to use a certain algorithm. You will notice that algorithms are often closely tied to a certain data structure, which is why I have also linked algorithms at the bottom of every data structure's page.

Two Pointers

→

Checks every pair without visiting every pair. Two markers closing in from opposite ends replace an entire nested loop.

1
3
5
7
9
11
L →← R

Fast & Slow Pointers

→

Detect an infinite loop without marking a single node. If the fast runner ever laps the slow one, the list has a cycle.

+1+2ABCDEFslowfast

Sliding Window

→

When one element enters and one leaves, the rest of the work is reusable. That single trick turns quadratic scans linear.

2
1
5
1
3
2
length = 3

Binary Search

→

Find any entry among a billion sorted items in about 30 looks. Each guess throws away half of what remains.

1
3
5
7
9
11
13
L
mid
R

Prefix Sums

→

Pay for one pass up front and the sum of any range becomes a single subtraction, no matter how often you ask.

1
2
3
4
5
↓↓↓↓↓
1
3
6
10
15

Recursion

→

A function that calls itself sounds like it should run forever. Add a base case and it becomes the cleanest way to shrink a problem down to nothing.

f(4)f(3)f(2)return 1

Tree Traversal

→

Every node visited exactly once, none missed, none repeated. The order you choose decides what the walk computes.

1253467

Sorting

→

The setup move for everything else: once data is sorted, searching, merging, and finding duplicates all get cheap.

Intermediate

These algorithms are harder because instead of doing a single pass on the input, we are now actively making decisions on the data that we see. The majority of your time will be spent here since this type of problem-solving takes a while to grasp, but the visuals will get you through, I promise.

Backtracking

→

Try a choice, follow it until it dead-ends, undo it, try the next. Brute force with an undo button, and it solves Sudoku.

✕✕

1D Dynamic Programming

→

When each answer builds on the previous few, store them once and stop recomputing. Exponential problems collapse to a single pass.

0
1
1
2
3
5
8
0
1
2
3
4
5
6

Greedy

→

Grab the best option available and never reconsider. For the right problems, that shortcut is provably optimal.

10¢
50¢
1¢
25¢
5¢
pick largest first

Intervals

→

Meetings, bookings, IP ranges. Sort by start time and most overlap problems untangle in a single sweep.

Bit Operations

→

Thirty-two yes/no answers packed into one integer, each readable in a single operation. This is the machine's native language.

A
10110100
B
11010010
&
10010000

Depth-First Search

→

Commit to one path until it bottoms out, then back up and try the next. The recursion stack remembers the way home.

Breadth-First Search

→

Explores in expanding rings, so the first time it touches a node is also the shortest way there. No weights needed.

ABCDEFGL0L1L2
Advanced

Frankly, this stuff is hard to whip out mid-interview if you've never seen this before. The other algorithms actually give you a fighting chance of working through it, but there's a reason these algorithms are named after people. Some of the people who invented these algorithms went on to win the Turing Award, the highest achievement in computer science, for inventing them (I'm talking about Dijkstra). Don't be frustrated, just give yourself time to understand why and how they work.

2D Dynamic Programming

→

When a problem has two moving parts, the memo grows into a grid. Edit distance and longest common subsequence live here.

m
a
s
t
e
r
m
i
n
d
m
1
1
1
1
1
1
1
1
1
1
i
1
1
1
1
1
1
1
2
2
2
n
1
1
1
1
1
1
1
2
3
3
d
1
1
1
1
1
1
1
2
3
4

Two-Heaps Pattern

→

Track the running median of a stream without ever sorting it. Two heaps lean against each other and the answer sits where they meet.

531max5.5median689min

Dijkstra's Algorithm

→

The idea behind your GPS: always extend the cheapest path found so far, and the first arrival is guaranteed optimal.

231745SABCD

A* Search Algorithm

→

Dijkstra with a sense of direction. A hint about where the goal lies lets it skip most of the map and still return the best path.

·
·
·
·
·
S
E

Floyd-Warshall's Algorithm

→

Every shortest path between every pair of nodes, computed by three nested loops you can write from memory.

A
B
C
D
A
0
3
∞
7
B
3
0
2
∞
C
∞
2
0
1
D
7
∞
1
0

Bellman-Ford Algorithm

→

Shortest paths even when some edges have negative cost, plus a built-in alarm for cycles that make the question unanswerable.

4235-3SD

Prim's Algorithm

→

Wires every node together for the least total cost by growing one network outward, always taking the cheapest edge.

1232

Kruskal's Algorithm

→

Same goal as Prim, opposite move: sort every edge, then keep adding the cheapest one that doesn't close a cycle.

1234

Topological Sort

→

Orders tasks so every prerequisite comes first, or proves that no valid order exists. Build systems run on this.

123456

DAG Shortest Path

→

With no cycles to fear, shortest paths stop needing Dijkstra. One topological pass and every distance falls out in linear time.

213542SD

Importance

Algorithms optimize the efficiency of programs, allowing tasks to be completed quickly and using fewer resources. The gap between O(n) and O(n²) isn't noticeable when your input is 10, but at 10,000,000 the difference is too obvious.

Complexity

An algorithm's complexity measures how much time and space it needs as its input size (often called n) grows. It's usually written in Big-O notation, which is the upper bound of an algorithm's time or space requirements in the worst-case scenario.

TimeSpacefastest ↑least memory ↑LookupLookupCacheCacheIn-placeIn-placeStreamStream

Time and space costs are a tradeoff that you need to make when picking algorithms. Faster algorithms usually use more memory, and memory-efficient algorithms tend to take more time.

Problem Solving

Here is how I approach problem-solving when working with something I've never seen before. I have a quick checklist I run through as soon as I'm done reading a problem:

1. Problem Type

It's no surprise that different algorithms are best suited for different types of problems. Dynamic programming loves optimization problems that break into reusable subproblems, sliding window wants contiguous ranges, and breadth-first search goes after shortest paths. Think about the problem type, and you'll be able to narrow your list of choices.

2. Data Structure

Algorithms work with data structures, so choosing the right data structure is crucial for getting to the best solution. A lot of times, you will be given the data structure as part of the problem, which can actually help you choose the most efficient algorithm.

3. Space-Time Tradeoff

Speed usually costs memory, and saving memory usually costs speed. In interviews, it's assumed that you are aiming to make an algorithm faster, but the best course of action is to discuss the tradeoffs while coding. If you have a brute force solution, talk about its space and time complexity and whether you should continue optimizing for speed.

4. Scalability

There are entire books dedicated to this topic, but we are going to keep it very simple. Your code requires some kind of input to work. What happens when that input is extremely large? LeetCode problems will usually tell you the constraints, but in the real world this will be something you will need to consider. What would happen if you had a million customers, and how would you handle that?