Find Minimum Value of an Array in Python

Beginner
⏱️ 9 min read
📚 Updated: May 2026
🎯 2 Code Examples
Lists

What you’ll learn

  • What minimum means in simple terms: smallest value in the list.
  • How a one-pass running minimum algorithm works.
  • Two Python examples, including all-negative values, plus live preview.

Overview

To find the smallest value, scan from left to right and keep the smallest seen so far in one variable.

Two examples

Mixed values and all-negative values.

Live preview

Uses the same sample list as code example 1.

Interview tip

Mention O(n) scan and empty-list safety.

Prerequisites

Basic Python loops and list indexing.

  • Know list syntax like [12, 5, 7, 3, 2, 8, 10].
  • Understand that numbers can be negative, and comparisons still work.

The idea

Use the first list value as current minimum. For each next value, if it is smaller, update the current minimum.

After the final element, the current minimum is the answer.

Live preview

Same sample list as example 1: 12, 5, 7, 3, 2, 8, 10.

Runs the same comparison logic in JavaScript.

Live result
Press "Find minimum".

Algorithm

Goal: return the smallest value from a list of n integers.

Validate input

If list is empty, report error first.

Initialize minimum

Set min_val = arr[0].

Scan remaining values

If a value is smaller than min_val, update it.

Return answer

Return final min_val.

📜 Pseudocode

Pseudocode
function find_min(arr):
    if arr is empty:
        error
    min_val <- arr[0]
    for each value from second element:
        if value < min_val:
            min_val <- value
    return min_val
1

Find minimum (reference program)

Same sample values as reference flow; output is 2.

python
def find_min(arr: list[int]) -> int:
    if not arr:
        raise ValueError("Array must contain at least one element.")

    min_val = arr[0]
    for i in range(1, len(arr)):
        if arr[i] < min_val:
            min_val = arr[i]
    return min_val

def main() -> None:
    array = [12, 5, 7, 3, 2, 8, 10]
    min_value = find_min(array)
    print(f"Minimum value in the array: {min_value}")

if __name__ == "__main__":
    main()
2

When every element is negative

Smallest means most negative, so answer is -9 here.

python
def find_min(arr: list[int]) -> int:
    if not arr:
        raise ValueError("Array must contain at least one element.")
    min_val = arr[0]
    for x in arr[1:]:
        if x < min_val:
            min_val = x
    return min_val

def main() -> None:
    negatives = [-9, -3, -1, -7]
    print(f"Minimum (most negative): {find_min(negatives)}")

if __name__ == "__main__":
    main()

Notes

Built-in. Python has min(arr), but manual scan is often required in interviews.

Parallel scan. Large systems can compute partial minima and combine them.

❓ FAQ

It is the smallest value in the list. On the number line, it is the value farthest to the left.
You need an initial candidate from real data. Then each next value can replace it only if smaller.
There is no minimum for an empty list. Validate first and handle this case explicitly.
Yes. For example, in [-9, -3, -1], the minimum is -9.
The algorithm still returns that minimum value correctly; duplicates do not change the answer.
No. One scan is enough and usually faster than sorting when you only need the minimum.
You scan n elements once: O(n) time and O(1) extra space.

🔄 Input / output

You can collect numbers from input, store in a list, and pass that list to find_min.

Edge cases

Empty

Empty list

There is no minimum; validate before reading first element.

Single

One element

The minimum is that one value.

⏱️ Time and space complexity

ApproachTimeExtra space
Single scanO(n)O(1)

Summary

  • Algorithm: running minimum in one pass.
  • Cost: O(n) time and O(1) extra space.
  • Important: define behavior for empty input.
Did you know?

Finding the smallest value in an unsorted list takes a single left-to-right pass: O(n) time and O(1) extra memory. In the worst case, any unseen element could still be the new minimum.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful