ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Selection Sort
    AlgoDS/Algorithm 2020. 1. 22. 17:35

    1. Overview

    The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from the unsorted part and putting it at the beginning. It's one of the Greedy Algorithms.

    2. Description

    2.1 Procedure

    The algorithm maintains two subarrays in a given array. In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray.

    • The subarray is already sorted.
    • Remaining subarray which is unsorted.
    arr[] = 64 25 12 22 11
    
    // Find the minimum element in arr[0...4]
    // and place it at beginning
    11 25 12 22 64
    
    // Find the minimum element in arr[1...4]
    // and place it at beginning of arr[1...4]
    11 12 25 22 64
    
    // Find the minimum element in arr[2...4]
    // and place it at beginning of arr[2...4]
    11 12 22 25 64
    
    // Find the minimum element in arr[3...4]
    // and place it at beginning of arr[3...4]
    11 12 22 25 64 

    2.2 Time and Space Complexity

    Particular Complexity
    Worst-case performance O($n^{2}$) comparisons, O(n) swaps
    Best-case performance O($n^{2}$) comparisons, O(n) swaps
    Average performance O($n^{2}$) comparisons, O(n) swaps
    Worst-case space complexity O(1) auxiliary

    3. Reference

    https://en.wikipedia.org/wiki/Selection_sort

    https://www.geeksforgeeks.org/selection-sort/

    https://www.youtube.com/watch?v=xWBP4lzkoyM

    'AlgoDS > Algorithm' 카테고리의 다른 글

    Tail Recursion  (0) 2020.04.08
    DivideAndConquer  (0) 2020.01.22
    Greedy Algorithm  (0) 2020.01.22
    Insertion Sort  (0) 2020.01.17
    Choosing sorting algorithm  (0) 2020.01.17

    댓글

Designed by Tistory.