Learn Selection Sort in 8 minutes 🔦
HTML-код
- Опубликовано: 19 окт 2024
- data structures and algorithms selection sort algorithm
#selection #sort #algorithm
// selection sort = search through an array and keep track of the minimum value during
// each iteration. At the end of each iteration, we swap variables.
// Quadratic time O(n^2)
// small data set = okay
// large data set = BAD
music credits 🎼 :
===========================================================
Block Party - Bad Snacks
link: • bad snacks: RUclips Au...
===========================================================
public class Main{
// selection sort = search through an array and keep track of the minimum value during
// each iteration. At the end of each iteration, we swap values.
// Quadratic time O(n^2)
// small data set = okay
// large data set = BAD
public static void main(String[] args) {
int array[] = {8, 7, 9, 2, 3, 1, 5, 4, 6};
selectionSort(array);
for(int i : array) {
System.out.print(i);
}
}
private static void selectionSort(int[] array) {
for(int i = 0; i < array.length - 1; i++) {
int min = i;
for(int j = i + 1; j < array.length; j++) {
if(array[min] > array[j]) {
min = j;
}
}
int temp = array[i];
array[i] = array[min];
array[min] = temp;
}
}
}
u forgot to pin it =)
Practicing...
Ascending Order
public class Main
{
public static void main(String[] args) {
int array[] = {8,3,4,1,0,5,2,6,7};
selectionSort(array);
for(int i : array){
System.out.print(i);
}
}
public static void selectionSort(int[]array){
for(int i = 0; i < array.length - 1; i++){
int min = i;
for(int j = i + 1; j array[j]){
min = j;
}
}
int temp = array[i];
array[i] = array[min];
array[min] = temp;
}
}
}
********************
Descending order
public class Main
{
public static void main(String[] args) {
int array[] = {8,3,4,1,0,5,2,6,7};
selectionSort(array);
for(int i : array){
System.out.print(i);
}
}
public static void selectionSort(int[]array){
for(int i = 0; i < array.length - 1; i++){
int min = i;
for(int j = i + 1; j
4:35
Half of my tension wipes away when he says sit back and relax
Man, I wish you will become the greatest programming RUclipsr in a year
He already is, he just has not enough visibility !
Me too, I love himmmm
Thanks guys! You are all the best! ❤️
@@BroCodez Thanks sir! For all the work!
May your dreams come true bro 😊😊
Studying as usual one day before a test and I was so confused on selection sort, but this video has helped me a lot! Thanks and keep up the great work!
Bro,,
Programming tortures me due to the bad teachers I have
But u, r the best programmer and teacher
U help me learn programming like it is just a childhood game.
Thanks a lot !,
I know how you feel! Hang in there. Thankfully, we have so many great resources online to ease the burden of poor instruction. Hope everything is going well.
I'm studying to become a software engineer atm... and I keep returning here time and time again for insanely good and fast introductions to pretty much ALL the concepts 🤣🤣 Bro is the master. Thank you!
I'm just going to leave this comment on your most recent video for the best chance of you seeing it.
You are insane. I'm going through your Python full course video atm and I'm about 3-4 hours in, and I just noticed that you have full course/crash course videos for several different programming languages and then also HTML/CSS on top of that.
That's amazing. I might even poke through your Java course just to see what new things I'll learn even though I already know a pretty good bit about Java.
I'll probably watch your Java swing videos since I don't know a whole bunch about swing.
This channel deserves *MUCH* more attention.
Thank you MinecraftTestSquad!
Yes I am a little insane 🤪
A man uses paint to explain in 8 minutes an algorithm and achieves more than a professor at the university in 6 Months. Well done and thanks.
I have seen that many people love Bubble sort because it is easier to learn however I think Selection sort is better as it seems simpler to me other than being faster than Bubble sort.
Oh my god. I completely agree. I never understood why people consider bubble sort to be easy. For me, selection and insertion sort are much easier.
insertion is even better , it just make the change everytime it needs to , after studying both for hours , and practice many of examples , the conclusion was that insertion will always be better than selection.
Bubble is extremely inefficient. Shouldn't be used in RL
Thanks brother, I really liked your explanation and the effort you made to graphically show the algorithm. Cheers!
Best selection sort explanation on RUclips
This was really helpfull. It made selection sort a piece of cake. Thanks a lot. Outstanding video
best Explanation + nice examples = This Video
Thank you so much for this video bro!!! It was really helpful
Hi bro. I just discovered this youtube channel so I'm happy. I learn English about for 1 years and I'll watch your videos
Thanks Kenan! I believe there's translation available if that helps
Super visual and incredibly interesting way of learning of DS and algorithms. Bro code rocks!!!
Just amazing how many videos you are going to upload in this data structure and algo series I want to learn a lot from you
I'm not quite sure yet. I'm planning 20+ topics for this series, there's a lot to cover
@@BroCodez yeah you can make it as long as you want because it is quite important series we will watch all of them
Everybody gangsta till your teacher gives sorting algorithm assignment on *linked lists with multiple variables* .
Bro, you use very accurate analogies. They say that when you master a subject, you can explain it to a 6 year old child or a dumb adult (I'm the latter). Your channel is worth pure gold
Thnx for the vid. Very clear explanation.
However, it implies that the algo is caching the VALUE of the array elements when searching for the min element. That's not the case. What the algo caches is simply the INDEX of the value, so @2:02 it should cache the index value "3", not the data value "2", then use that index value to locate the corresponding data and perform the swap.
It's basically the naive way of sorting, but slightly smarter because the array gets smaller each iteration.
Thanks for the video!
Lifesaver! Thank you!
Thanks for the visual presentation.
I figured out how tk do it on my own thanks to the slide.
Thanks for watching Raihan!
I created this without checking any algorithm:
array = input("Enter Array *[max element: (10)^18]
(Numbers Separated By Space):").split(" ")
a = len(array)
sorted_array = []
while a > 0:
smallest = 1000000000000000000
for i in array :
if(int(i)
Thanks so much for this! You are amazing.
Bro finished a 30min lesson in 8 minutes and looks like its more clearer than ever
you are very good person who is teaching free of cost i'm glad to found this channel and n amazing person ^^
Bro, you made this so easy to understand. Tysm
great job man, keep it up
Thanks Maurizio! I'll keep it up!
Bro, epic graphic design on the thumbnail and explanation!
Thanks Sylvan! I've been trying to improve the thumbnails. I'm no graphic designer tho :/
@@BroCodez They look great
Just got busy studying PHP for final project, here I am again studying Java😁 Big thanks😍
You're welcome Marckhycs! Thanks for watching!
This is a fantastic explanation, thank you.
Best explanation ever! Thank you
you are amazing you are the only youtuber in whole youtube let me know this topic very very thanks
wow , such a nice & simple explanation, Thank you so much Bro Code
You're welcome Anurag! Thanks for watching!
Thank you so much I have a data structure exam tomorrow I hope I will get full marks
I m lucky to find his
Btw im a new subascriba
love your videos bro thanks for the help 😃
Woah. That was a really good video.
Hey Bro! Can i ask a question? why in inner loop j = i + 1, why not just j = 1? I'm still trying to getting a hang of this
I think because you are not sorting the very last element in the array. Because once the first four items are sorted, you don't have to iterate through the last element in the array. There is no where else for it to go.
Wouldn't it be simpler if we just applied the bubble sort logic and start iterating from the end and keep swapping the smaller value to the front?
thanks bro
saved my butt in class
hey @Bro Code may I ask you what shoud I learn in free time at hight school? I mean for the future job what will be the best programming language for example in the US.
PS. I really appreciate you work at yt and I hope you will be very lucky in the future:)
Thanks for the support max!
It really varies on what U.S. employers want so it's difficult to give a definite answer. There's a lot of overlap between languages. If you know one, a lot of what you learned transfers to another.
thankyou so much for
teach me
sir your all videos are the best video
i was see many video of teach coding
but your teaching is best in world of youtube
thank you so much
Thank you for the kind words Tony!
I'm happy to help!
@@BroCodez welcome sir and
thank you for reply
Thanks for the tutorial!
bro code, your background music is great study music. Do you have a playlist?
"bro code"ur doing really great job bro!
Have the feeling he likes carrying nines around 😂
U earned another subscriber
time complexity o[n2], space complexity o[1], it seems the same as bubble sorting
You are great Sir.
Thanks Kashif!
Congrats for 100k
Hello, Bro. I know this course has completed but can you please add Dynamic Programming in it?
holy crap its a two
that quote killed me hahahaha
I guess if you knew there was no repeating numbers and if the new min is 1 above it, then you don't need to search the rest of the array.
Thanks bro, i really appreciate it
You're welcome! Thanks for watching Eueud!
Thank you bro!
Well said.
Bro what do you think of flutter? Are we going to get any guides on it down day?
maybe! I'll likely have you all vote on future video topics once I finish JavaScript and the C-family langauges
Amazing Explanation Bro
Thank you Aman! I'm happy to help
Great video! but may I ask what was the point of the code
temp=num[i];
num[i]=num[j];
num[j]=temp;
int a = 1; int b = 10;
now u swap the two value u need one extra variable to store it temp so declare
int temp;
execution temp = b; //temp store 10
b=a; //now b store 1
a=temp; // in the 2nd step b value is change so need a extra variable to store the b variable before the 2nd step, that's the logic behind that
@@vijayanks1714 Why is outer loop arraylength - 1? Instead of just being arraylength?
thx bro, love you
The best explanation
Thank you jrda!
Bro is really cool 🚀🚀🚀
Thanks!
You are the best
Great 🌸🌸🌸
why did you use length-1 in the nested loop.
Very good video! Friendly suggestions: It will be helpful if you can place the temp variable box further away from the min variable ... also, please explain what "swap using temp" means at the start of the video. This will help beginners (like my kiddo).
Thank you sir
What software are you using for your explanation?
Paint.net
I'm not skilled with animations, but I'm decent with my photoshop skillz
@@BroCodez thank you bro, you are an inspiration!
Thank you bro
best videos
just the best
int min = 1 i; on line 25. i goes from 0 to length of array-1 . how does that help?
thanks king
i don't even need an explanation atp i watch your videosjust for fun after studying
Why is it that at 7:10 (line 25) he defined int min = i? Why could it not be array[i] since we are focused on the element and it is the same position regardless? Also, could you explain to me the lines of code that go from line 32 to line 34? Thank you in advance.
@@LynnyrdRavage we declare the index only so it's easy to work with indexes when we want to traverse through the array
@@LynnyrdRavage we have 9 elements, outer for loop compares the first 8 elements with the inner loop/last 8 elements. we compare i with j and if i is bigger than j, we swap i with j using the help of the two variables, min & temp
@@LynnyrdRavage btw we use min variable so we don't lose the reference of i if you're wondering why not just directly use i
Hey Bro Code love ur videos
Thank you Sai!
can you do networking?
Great
S
thanks brother
Let bro cook🔥🔥🔥🔥🔥
Bro,
What will happen if the array elements are repeated..
Pls reply
👍👍👍
ty
Thanks
sweet
thanks bro
谢谢你
how are you printing the result am running the same code as you but it just print the first unsorted array...please help
Pls make a node js tutorial
I feel that this is the weirdest algorithm in the programming world i feel that it is too hard
thank u bro
Thanks for watching AAR!
is it better than Bubble sort.?
comic sans intro
tyyy
what are your c specs
Why is it that at 7:10 (line 25) you defined int min = i? Why could it not be array[i] since we are focused on the element and it is the same position regardless? Also, could anyone explain to me the lines of code that go from line 32 to line 34? Thank you in advance.
It can work both ways and those lines are for swapping the two elements. Temp is used as a temporary variable for seapping
I dont understand the code. but atlist i have the code for the homework.
nice voice :)