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
ArrayFinding 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
- Assume the first element is the smallest so far.
- Move to the next element and compare it with the current smallest.
- If the new element is smaller, update the smallest value.
- Repeat until every element has been checked.
- Whatever remains is the minimum.
Find Minimum Worked Example
Input: [7, 2, 9, 1, 5]
- Start: min = 7
- Compare 2 < 7 → min = 2
- Compare 9 < 2? No → min stays 2
- Compare 1 < 2 → min = 1
- Compare 5 < 1? No → min stays 1
Output: 1
Press ▶ Run to watch it step by step.
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]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
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
Ready for the next step?
See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.