Selection sort algorithm

preview_player
Показать описание
See complete series on sorting algorithms here:
In this lesson, we have described Selection sort algorithm and analyzed its time complexity.
Series on Time Complexity:

For updates on videos and courses, subscribe to our channel.

You may also like us on Facebook:
Рекомендации по теме
Комментарии
Автор

This is almost like online tuition. You can ask questions and even request videos. We can try to get them. :)

mycodeschool
Автор

Did you see our merge sort video? Its quite simplified. You may start loving recursion once it settles well in your head.

mycodeschool
Автор

We are always comparing with A[iMin] i.e the current minimum, , so, its against 7, then against 4 and then against 2. Its not always against 7 because iMin is getting updated.

mycodeschool
Автор

I saw a lot of comments below asking for new videos from this guy, This is 2020 and it has been 7 years since this video was posted and the content is top-notch. However the author is no more and suffered a loss of life by a speeding car while crossing a road. May he rest in peace.

bob_factory
Автор

These videos are really awesome.Please post more videos on C programming and if possible on java, python, c++ or any other language you want or on data structures and algorithms because you are doing a great job. Your videos helped me a lot.You make things simple and concise.

swetamahajan
Автор

Rest in Peace Harsha. You will be remembered through your amazing work.

CSSoda
Автор

One of the greatest lecture of all time on algorithm!

MelDen-hz
Автор

Great lesson, I think the final code can be optimized...

void selectionSort(int* A, int n){
int temp; // temporary variable

for (int i=0; i < n-1; i++){ // n-2 passes (last element comparisons are not necessary)

for (int j=i+1; j < n; j++){
if (A[j] < A[i]){ // there's a smaller value ahead
temp = A[i]; // interchange positions
A[i] = A[j];
A[j] = temp;
}

}
}

davidgmos
Автор

it probably would make sense to add another "if" statement, to check if the min is different from i (then swap is needed). Right now, we are swapping every time, even when it is not needed

anton.encours
Автор

It was difficult for me to understand but you made me understand in 10 minutes.
Thanks

tanmaysrivatsa
Автор

I just love you. You teach the way I learn !

LUX
Автор

dear sir, we are following ur entire content please update this course with more algorithms, please bros who like this series give thumbs .
(from india)

dileepbc
Автор

I really appreciate your work...one of the best channel for DS & Algo...Please make more videos

farazhusain
Автор

*_This guy sounds the same as the one on neso academy_*

hirakmondal
Автор

some of the best material online period

chelseakatsidzira
Автор

Selection sort. In computer science, selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort.

blake
Автор

Thank you so much, will probably binge watch your videos for my upcoming DSA exam

ryujiyamasaki
Автор

Such a masterpiece! It is still no.1 in 2023

BNFY
Автор

I think for selection sort, time complexity for best case should be O(n) because if one traverses through the already sorted list, then one can always come out of it after finding that it is already sorted instead of traversing again. Here is my code :

int temp, min = 0, index = 0;
bool swap = true;
for(int i = 0; i < num && swap; i++)
{
min = arr[i];
swap = false;
for(int j = i; j < num - 1; j++)
{
if(min > arr[j+1])
{
min = arr[j+1];
index = j+1;
swap = true;
}
}
if(swap == true)
{
temp = arr[i];
arr[i] = min;
min = temp;
arr[index] = min;
}
}

rupaliroychoudhury
Автор

I found it complicated than other explanations..Why can t you have variable to hold the index of minimum value from each pass. Then swap the first element and the minimum element. So in next pass start from 2nd element to find second element and so on...

jayshrinikam
welcome to shbcf.ru