Data Structures · Visualization

Find Minimum

Array

Finding the minimum means scanning through every element once and keeping track of the smallest value seen so far. Time: O(n). Space: O(1).

Big-O: Random access O(1); insert/delete in the middle O(n).

Find Minimum

Array

Finding the minimum means scanning through every element once and keeping track of the smallest value seen so far. There is no shortcut in an unsorted array — you must look at every element at least once, because the smallest value could be anywhere.

How Find Minimum Works

  1. Assume the first element is the smallest so far.
  2. Move to the next element and compare it with the current smallest.
  3. If the new element is smaller, update the smallest value.
  4. Repeat until every element has been checked.
  5. Whatever remains is the minimum.

Find Minimum Worked Example

Input: [7, 2, 9, 1, 5]

  1. Start: min = 7
  2. Compare 2 < 7 → min = 2
  3. Compare 9 < 2? No → min stays 2
  4. Compare 1 < 2 → min = 1
  5. Compare 5 < 1? No → min stays 1

Output: 1

Try your own input
Find MinimumO(n)
Scans every element once, keeping track of the smallest value seen so far.
7
0
2
1
9
2
1
3
5
4
Active / shifting Result
Find Minimum
Press ▶ Run to watch it step by step.
Python · Arrays in Code
def find_min(arr):
    best = arr[0]
    for v in arr[1:]:
        if v < best:
            best = v
    return best

def find_max(arr):
    best = arr[0]
    for v in arr[1:]:
        if v > best:
            best = v
    return best
# example: find minimum of on [7, 2, 9, 1, 5]
Input: [7, 2, 9, 1, 5]

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Find Minimum Time & Space Complexity

TimeO(n)
SpaceO(1)

When to Use Find Minimum

  • Finding the cheapest product in a price list
  • Detecting the lowest temperature recorded in a day
  • A building block inside selection sort and other algorithms

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.