Skip to lesson content
navan✳THE BUILD LABDSA
0/66 complete
BUILD LAB / DSA/ Think like a problem solver
EXPERIMENT 01 / 66

A better way to think.

Learn how to turn an unclear task into a model, an algorithm, and evidence.

BY NAVAN SAMI◷ 7 MIN READSTARTERCONCEPT

01 Model the idea

Data structures organise information; algorithms describe how to work with it. Neither is a contest to use the most elaborate technique. Start by writing the required input and output, choose operations that matter, and test a small example by hand. This course explains the ideas independently of a language and uses readable Python 3.11+ implementations you can run with only the standard library. You do not need to finish the separate Python track first, but basic variables, loops, functions, and lists will help.

THE THING THAT MUST STAY TRUE

The candidate is the smallest value in the inspected prefix.

02 State the strategy

Read the steps independently of syntax. Explain what each step preserves before translating it into code.

the_strategy.txt
SET candidate to the first value
FOR each remaining value
  replace candidate if the value is smaller
RETURN candidate
A worked trace for this experiment
Value examinedSmallest so far
1212
44
194
74

03 Make it concrete

The implementation uses Python 3.11+ with only the standard library. Run it locally, or download the independent DSA workbench.

welcome.py
values = [12, 4, 19, 7]
smallest = values[0]
for value in values[1:]:
    if value < smallest:
        smallest = value
print(smallest)
↳ EXPECTED OUTPUT
4
  1. 1

    The problem asks for a value, not a sorted list. Sorting the entire input would do unnecessary work just to obtain its minimum.

  2. 2

    Trace the current candidate after each comparison. The candidate represents a claim about the prefix already inspected, which is the beginning of an invariant.

  3. 3

    Run examples from the downloadable DSA workbench or copy one into a .py file. Use the visualiser to predict the next operation, then compare your prediction with the step explanation.

04 Count the cost

TIME

O(n)

SPACE

O(n) temporary slice in this exact example

Bounds refer to the shown implementation and exclude printed output unless stated. n is input size; V and E are graph vertices and edges.

05 Your next move

A SMALL MISSION

Write a minimum function that explicitly rejects an empty sequence.

Reveal one possible solution +
one_possible_solution.py
def minimum(values):
    if not values: raise ValueError("At least one value required")
    best = values[0]
    for value in values[1:]:
        if value < best: best = value
    return best
print(minimum([12, 4, 19, 7]))

06 Check your reasoning

QUICK SIGNAL CHECK

What should you define before choosing an algorithm?

ANOTHER PATTERN IN YOUR TOOLKIT.

Understand it. Then own it.

Can you explain the invariant, trace an edge case, and defend the cost model? Log the experiment when the reasoning makes sense.

Built with curiosity. By Navan Sami. ↗Patterns over panic. One step at a time.