'select'에 해당되는 글 1건

  1. 2016.12.08 [Algorithm] About Select Sort
2016. 12. 8. 17:24


Hello, i am GameDeveloperPlayground.

I am a Korean student and I post it for English practise.

I would appreciate pointing out grammar or typos.


In this posting in about select sort.


About Select Sort


Select sort is sorted is three ways.


1. Find the minimum value in a give array.

2. Replace the value with the value at the front of the array.

3. Replace the array with the first position subtracted in the same way.


Sorting Process


Let's start by randomly array numbers.


9 5 4 3 8 1 7


First find the lowest value in the unaligned array { 9 5 4 3 8 1 7}


It's 1. Replace the found value with the first value.


9 5 4 3 8 1 7 => 1 5 4 3 8 9 7


this one loop is over.


The second is to sort the array except for the first value, 


Find the lowest value 1 { 5 4 3 8 9 7 }. It's 3. Replace with the first array except 1


1 3 4 5 8 9 7


This is the way to go to the end.



(출처 : 위키백과 선택정렬)



Sample Code.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void SelectionSort(int arrays[], int length) 
{
    for(int i=0; i<length; ++i)
    {
        int Minindex = i;
        for(int j= i+1; j<length; ++j)
        {
            if(arrays[j] < arrays[Minindex])
                Minindex = j;
        }
 
        int swap = arrays[i];
        arrays[i] = arrays[Minindex];
        arrays[Minindex] = swap;
    }
}
cs


Implemented simply.



Algorithms analysis


Select sort is should be done entirely to get he minimum value. Therefore.

(n-1) + (n-2) + ..... + 2 + 1 = n(n-1)/2 


The time Complexity will be O(N²) with Big O notation.




Example.



(source:  위키백과 선택정렬 )


Video Example

( source: Youyube )




Thank you

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

[Algorithm] About Quick Sort.  (0) 2016.12.09
[Algorithm] About Insertion Sort  (0) 2016.12.08
[Algorithm] About Bubble Sort !!  (0) 2016.12.08
[Algorithm] About Linear Search  (0) 2016.12.08
[Algorithm] About Binary Search Algorithm.  (0) 2016.12.08
Posted by 시리시안