Oh My Algorithm
Algorithm Guidecomplexity: O(n²)

Selection Sort

An intuitive in-place algorithm that repeatedly finds the smallest (or largest) element and swaps it to the front.

01 Explore How It Works

Interactive Step-by-Step
Selection Sort
45
12
89
34
67
23
56
10

선택 정렬을 시작합니다. 매 반복마다 미정렬 영역에서 최솟값을 찾아 앞으로 배치합니다.

Logic Node1 / 14

02 Understand It Simply

For Everyone
🔑Analogy

Repeatedly pick the smallest of what remains and place it at the front.

💡In Plain Words

Finds the minimum each pass and fills from the front.

Few swaps, but always O(n²) comparisons.

📍Where It's Used
  • When swap cost is high
  • learning sorting concepts

03 Python Implementation

A clean, readable reference implementation of the core logic of Selection Sort.

core_implementation.py
def selection_sort(arr):
    n = len(arr)
    for i in range(n):
        min_idx = i
        for j in range(i + 1, n):
            if arr[j] < arr[min_idx]:
                min_idx = j
        arr[i], arr[min_idx] = arr[min_idx], arr[i]
    return arr

04 Frequently Asked Questions

FAQ
What is Selection Sort?+

An intuitive in-place algorithm that repeatedly finds the smallest (or largest) element and swaps it to the front.

What is the time complexity of Selection Sort?+

The time complexity of Selection Sort is O(n²). Follow the step-by-step visualization to see exactly why.

Where is Selection Sort used?+

When swap cost is high, learning sorting concepts.

What's a simple analogy for Selection Sort?+

Repeatedly pick the smallest of what remains and place it at the front.

Guide Progress0%