Learn the basics of bubble sort algorithm. This video is a part of HackerRank’s Cracking The Coding Interview Tutorial with Gayle Laakmann McDowell.
Nguồn:https://quydinh.com/
Xem thêm Bài Viết:
- Chia sẻ đầy đủ về cách hướng dẫn Ghost Win Xp bằng USB cơ bản từ A tới Z
- Hướng dẫn tạo file ghost win 10 thông qua 3 bước đơn giản mà bạn không nên bỏ qua
- Mách bạn 4 bước trong cách bung file tib theo chuẩn UEFI đơn giản nhất
- Mật bí 4 kiểu hyperlink trong excel bị lỗi phổ biến mà bạn hay gặp nhất
- Khái niệm ma alt là gì và cách sử dụng bảng mã ATL như thế nào?
How do i print this in the console?
what is this isSorted magic!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!THIS CODE DOESN'T WORK!!!!!!!!!!!!!!!!!
array[i] > array[i++]; value of "i" is same both sides, hence this always fails..
There is like four different languages of books behind you. I feel overwhelmed for the wrong reasons. 😮
I learned sorting algorithms studying computer science. When I got a job I used the command array.sort()
Great video!
You're very attractive!
Thumbs up from Georgia Tech!
I remember this from high school — still a great presentation on the topic.
Personally, I'm tired of the pretense that employers aren't that concerned with language knowledge but are deeply concerned with algorithms and problem-solving. The more experience I get with looking for real jobs the more I find its the opposite — they don't care if you could ace a college algorithms test, nor do they care if you are skilled at developing your own algorithms and systems. No, they want someone already experience in some specific domain of programming and with expertise on specific libraries / frameworks / technologies; they want "spring and hibernate" or "Django, along with SQL, HTML, CSS, and JavaScript." They may also ask for a bunch of other things that aren't important to them, but toward the top you see something like this that is non-negotiable. Funny thing is, a talent dev who has good problem solving and self-teaching skills could learn what they need, but they don't care. All the videos on YouTube pushing algorithms, data structures, design patterns, "problem-solving," etc., are red herrings luring aspiring professional away from what they really need to learn to get that first job and make real progress toward starting a career. If you've bothered to read all this consider it your reality check for the day.
Perhaps (?) it's different for tech giants in areas with large tech industries, lots of local talent, and large teams capable of mentoring new employees — but the vast majority of business seeking devs are not like this at all.
When you "swap" an array, isnt it passing by reference, meaning that it only swaps that array on that line and it doesn't remember the "new sorted" array while it continues in the loop…?
Great video. This is the most efficient way we can implement the bubble sort algorithm??
two levels of optimization.
boolean isSorted = false;
while(!isSorted) {
isSorted = true;
…..
Confused. Can some please explain?
This is the first time I have seen someone improve the efficiency of bubble-sort. Anyone who is really really new may not understand on the first go but this video is really well made.
awesome !! thanks.
the exam after 6 hours exactly, thanks alot <3
animation is so good. how did u do that?~
But doesn't the performance of this implementation depend heavily upon how isSorted is defined? Or if it is a built-in function? Considering that it is not and you write it out, then this will be a terrible algo because you check if the array is sorted or not each time you iterate through the loop! Can we do better than this?
great presentation, great explanation, great voice !!
Pleaseeeeeeeeeeeeeeeeeeeeee, Bubble sort in Python !@!!!!!!!!!!!!!!
Your videos are honestly all shit. Horrendously explained.
Very nicely done. Gayle does an outstanding job here. I would like to see a similar presentation using C programming code. Thank you for providing this.
The algorithm shown does not sort the entire array, since you only go through the array (and potentially switch the elements) the amount of times the array is long. Thus you will only bubble the element once. You need another for loop to make it work. Other then that great video.
Exactly. Run. Nuclear. Vaginal. Wars. For. Space. Real. No. Shake. Em.
Thank you so much Gayle.
Straight after the while (!isSorted) condition, the next line is isSorted = true; so wouldn't the code just jump out there and never go through the following if statement? or will it complete the if statement first and then check whether to restart again?
Thank you Gayle for these brilliant videos that explain challenging coding techniques to junior programmers.
I really didn't get why everyone is saying bubble sort complexity is O(n^2),
Actually, if you consider the inner loop is getting shorter each time the outer loop loops,
You will find the execution complexity is O(n*(n-1)/2)
😤😑😑😑😑😓😓👹👿👹👹👹😮😮😓👐👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾👳🏾🙅🏿♂️
00:55 it should be O(n) space, because we've got one array of n elements. Or she just thought ok additional space that we need except for the array holding n elements is 0 so its constant => O(1) …
See my solution in c, c++, python and java
http://code2begin.blogspot.com/2016/12/bubble-sort-algorithm.html
I dont get the thing with the lastUnsorted index: if you get the highest element at the beginning then this element wont be able to make it to the other side of the array, or I am wrong ?
I wish I had she is my mother.
You folks that are critiquing Gales instruction and code obviously do not really know who this she is. You see those books behind her? She wrote at least three of them. I know because I read all three. I also believe she is the founder of Hacker Rank which is used by so many companies during job interviews. The big fat book was written by my professor at MIT which she also obviously understands well. Stop embarrassing yourselves.
I must be thick in the head because I have not yet understood why it was while(!isSorted). Like I would say as long as not sorted, keep doing this but apparently, the code is opposite. 🙁
You know in C# and other languages you can just use 1 line to efficiently sort: Array.Sort(myAwesomeArray);
Spend the rest of the time on something actually productive. No one will ever need to implement a bubble sort or even quick sort. What do you think?
Hello there.
Your code implementation is too complicated for my opinion. This is my example:
int[] initArray = new int[]{5,8,1,6,9,2};
for(int i = 0; i < initArray.length – 1; i++){
for(int b = i + 1; b < initArray.length; b++){
if(initArray[i] > initArray[b]){
int temp = initArray[b];
initArray[b] = initArray[i];
initArray[i] = temp;
}
}
}
Thanks.
These videos deserve much more views 😮 They're really well made, and well explained!