Find the k'th Largest or Smallest Element of an Array: From Sorting To Heaps To Partitioning

  Рет қаралды 271,663

Back To Back SWE

Back To Back SWE

Күн бұрын

Пікірлер: 415
@anthonyesquire9830
@anthonyesquire9830 5 жыл бұрын
Good day. I don't ever comment. However, I just wanted to say that all your videos are really helpful to both me and many others. I respect the level of time and effort you put into these video and how many people you are helping. What most tutors/lecturers don't understand is that even you help that ONE child at the back of the class, they might just end up being able to build the next big startup. This being just because of the extra effort people like you put. Of course the material is NOT easy. However, I respect and thank you for both me and many others who are really struggling or just want enrichment. So hopefully you can keep it up and just know that there is at least someone who benefits from your effort (probably many though). Channels like these are hard to come by. So please keep up the good work. You will never know who it may help!
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
"even you help that ONE child at the back of the class" I resonate with that the most. The problem with lectures is that it is always tens of people anywhere in the classroom that are confused but don't speak up because a lecture is a hard environment to be a real, inquisitive, student in. (this is why whenever I get a youtube comment I try to say..."keep asking questions" because if a student is afraid to ask...they lose the very curiosity that makes a great lesson...you know that quote....'the teacher and the student make the teaching' or something like that) Thank you for your comment. It is a lot of work and every week I have to tell myself to keep doing this (but I mean...I want to make it sustainable eventually with products I'm building right now, etc...at that point I won't need motivation because this will hopefully be a sustaining business) This comment served as my weekly energy renewal :)
@damodarmahawar9748
@damodarmahawar9748 3 жыл бұрын
I6
@Sarah-re7cg
@Sarah-re7cg 9 ай бұрын
As the student in the back, thank you. I think it’s videos like these that really make me want to also help students out since we’ve all been there. I feel a great level of gratitude
@sourabhk2373
@sourabhk2373 5 жыл бұрын
Huge respect to this guy. The way he phrased his sentences, like " We are doing more work than we need to" , these will help you and move you in the direction of optimizing your solution. Thanks for the videos my dude.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
thanks - this guy
@CodeSuccessChronicle
@CodeSuccessChronicle 3 жыл бұрын
@@BackToBackSWE haha
@addiegupta
@addiegupta 5 жыл бұрын
"We're doing more work than we need to " that is a very clever way to think about a solution's quality while solving a problem.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
yeah
@sarojinigarapati95
@sarojinigarapati95 5 жыл бұрын
I don't usually comment but this is the best explanation for quick select algorithm ever ! All of your videos are amazing and easier to understand than many other resources online. Thank you so much !!
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
thanks
@vedantiyangar151
@vedantiyangar151 5 жыл бұрын
Man, you're like a brother to me. I've learnt so much from your simple videos that I couldn't from my college years. Thanks a lot. I am considering binge watching your whole channel.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
Haha, nice to hear, I mean, as humans we are all siblings. Anyway, glad they are helping you. - Ben
@jiazhengguo5493
@jiazhengguo5493 5 жыл бұрын
the best channel for preparing coding interview
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
I know. Give me 2 more years. KZbin is 😴😴😴 on me.
@colorfulcodes
@colorfulcodes 5 жыл бұрын
Facts.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
@@colorfulcodes hahaha
@kumarchandan9685
@kumarchandan9685 3 жыл бұрын
Among other KZbinrs, your way of explaining the thought process besides logic (which other coding channels usually lack) is right at the top. Awesome content. Thank you good sir!
@gyrogojo
@gyrogojo 5 жыл бұрын
Great Video. The way you walked us through the problem and ended up at the average linear time solution was brilliant. Appreciate you taking time out to make such videos.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
sure
@roman_mf
@roman_mf Жыл бұрын
I really like how in-depth your videos are. Comparing to many other channels where people either go lightning fast or just gloss over the details, your step by step handholding and the big O analysis rock! I know what is next on my bingewatch list. ;-)
@amishagupta990
@amishagupta990 5 жыл бұрын
Your understanding of the fundamental concepts is phenomenal and rare to find.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
thanks
@jameshuddle4712
@jameshuddle4712 4 жыл бұрын
Excellent vids. Good sense of humor. Clear explanations. Two things: I have seen the partitioning solution *after* the date you posted this, but have never come across it before -- or seen references in videos prior. Is this your solution? Incredible! The other thing: when referring to a "good" pivot, you are of course thinking quicksort. This is different. If I have a million item array and I want the 20th largest, the best first pivot should be just smaller than the 20th largest. You *read* a million elements, and if they're larger, you *swap* them. So if your pivot is (for instance) 999900, you only do the swap like 100 times. This is good for speed. And then your next search is finding your k-spot in a list of 100 items. See how much faster that goes? Instead of n + n/2 + n/4 ... it's more like n+200. YMMV Hope you like this twist HALF as much as I enjoyed discovering "your" partitioning solution. It was a delight! (there *is* a general case and there *is* a quick pivot-finding algo)
@helloiam2mas
@helloiam2mas 4 жыл бұрын
Hey man, you have the best algo + ds explanations and walkthroughs on the entire internet. Bar none. Was a wahoo but go terps lol.
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thanks! yeah uva is perty
@abhishek-n-chaudhary
@abhishek-n-chaudhary 5 жыл бұрын
One of your best videos when it comes to an explanation. It's clearly visible that you have put your heart and soul while explaining deeper logic. What an honest effort, may you get all the success you wish for!
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
Yeah haha, this is fire. Thanks haha
@Pooja-xu4lp
@Pooja-xu4lp 4 жыл бұрын
Benyam, you are a gem of teacher and person. This is by far the best way to make me think. Thanking is not enough but thank you. Specially for keeping it for free, many of us could not have stumbled upon this or be able to afford this level of video. Please do keep up and more love from India. Btw, the donation option doesn't work in India yet and i'm sure your fans like me in India would like to contribute in some capacity.
@kaustubhtrivedi5403
@kaustubhtrivedi5403 5 жыл бұрын
Keep it up man, I really think this channel will be well known very soon.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
working on it
@SocajowaRS
@SocajowaRS 5 жыл бұрын
11:50 is literal gold, I never thought of representing K and N in that way visually. It makes accessing K and thinking about how to index into it manageable. Freaking awesome.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
thanks haha, I don't remember what I say in like all my videos
@SocajowaRS
@SocajowaRS 5 жыл бұрын
@@BackToBackSWE Again appreciate this video, I swear I was struggling all day to try to understand this algorithm, and I watched your video, then your quicksort video, and then whiteboarded some examples on paper and finally got it. Thanks a ton.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
@@SocajowaRS nice
@PoulJulle-wb9iu
@PoulJulle-wb9iu 5 жыл бұрын
cuz u noob
@johnvanschultz2297
@johnvanschultz2297 3 жыл бұрын
This is the best explanation of quick select I have found online. Thank you for this video.
@brainstorming1369
@brainstorming1369 2 жыл бұрын
You know that feeling when it just clicks. You and NeetCode always get me there. Thanks for all your hard work
@殷源源
@殷源源 4 жыл бұрын
Thanks from China.I liked several videos of you since I met your channel yesterday. Really appreciate the details and the way you present.
@rohanangajala548
@rohanangajala548 4 жыл бұрын
Why do we get largest from min heap? The root of min heap is smallest, so isn't it more beneficial to use a max heap?
@TheSridharraj
@TheSridharraj 3 жыл бұрын
I just went through just once. Its been looong that i dont even remember what is quick sort. but with this video i just understood quick sort as well as how and where to apply quick sort. Good work buddy.
@francocamborda5076
@francocamborda5076 4 жыл бұрын
I also never ever comment videos, and I never ever subscribe, specially when somebody asks me to subscribe. Nevertheless, your videos show a couple things: 1) A great amount of effort to condense the information to what's truly needed 2) An intuitive explanation 3) Barely any overhead in the video itself 4) Charisma when teaching 5) The importance of sharing knowledge For this I am very thankful, subscribed and if you open a Patreon or alike, willing to contribute to your cause. Kudos.
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thanks for the detailed analysis haha
@chuckchen2851
@chuckchen2851 3 жыл бұрын
It's awesome that you showed the entire thought process, including the well-worth detour of heap solution. Also the time analysis part is eye-opening. Unlike the merge sort, we avoided the sorting in partitions, leaving only the n/2^i as the leading term in big O, which adds up to O(n). Thanks for going into all the details, it really pays off as a better learning outcome!
@adityasaxena3903
@adityasaxena3903 4 жыл бұрын
Dude, your explanation! Absolute magic. Better than the paid courses!
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thanks
@ricardoorellana1168
@ricardoorellana1168 5 жыл бұрын
Ben, it's amazing the amount of knowledge you have on CS fundamentals, I am learning a lot, thank you!
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
haha, thanks
@tapasu7514
@tapasu7514 5 жыл бұрын
No one can ever match your style of explanation. Super !
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
thanks
@navyakalra6774
@navyakalra6774 4 жыл бұрын
You're awesome!! Appreciate all your efforts that you put in to explain a problem, the thought process, solution, time complexity analysis. Huge respect for you!
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thanks and sure and thx
@shiveshbharti5442
@shiveshbharti5442 3 жыл бұрын
I have watched so many videos till now and still you are the best. Man you make these concepts feel so easy and your videos are damn amazing and very easy to understand. Thank you so much and also its available for free loved them man
@AJ3000_
@AJ3000_ Жыл бұрын
This man is better than 90% of my cs department at explaining these concepts
@SinghFlex
@SinghFlex 4 жыл бұрын
14:00 you choose first element as pivot and swap it to the last , rather than doing this directly choose the last value as pivot.
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
Any number can be the pivot? Why the last?
@SinghFlex
@SinghFlex 4 жыл бұрын
@@BackToBackSWE yes any element can be the pivot ..But since we have to make a search space from L to R , so its better to choose last element, just an opinion:)
@ankuragarwal4014
@ankuragarwal4014 5 жыл бұрын
Keep Making Videos please....a humble request from your regular student..you are truly a great teacher
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
ok, say no more, I got u
@roman_mf
@roman_mf Жыл бұрын
@25:30 Can anyone explain why is the summation on the right is simplified to lg(n)and not lg(n)-1? Where did the minus one go?
@redherring27
@redherring27 5 жыл бұрын
Congratulations your final dialogue of happiness in everyone's life earned you a subscribe. Aight imma make my chemistry major roommate subscribe too.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
wut
@OP-yw3ws
@OP-yw3ws Жыл бұрын
Its amazing how easy your explanations are
@advertronicssystems8377
@advertronicssystems8377 3 жыл бұрын
I am a programming newbie and I am learning a lot from your channels. Just one observation, from your python code, where there is a while loop (while left
@mr.mystiks9968
@mr.mystiks9968 5 жыл бұрын
Reading up on quickselect thru leetcode solutions wasn’t effective at all for me but this video is simply brilliant. Realizing that we don’t have to perfectly sort EVERY integer is the first thought that tells us a heap is overkill, then using a pivot from quicksort to partially sort ONLY the half of the array we care about (and split the array further with each pivot) is the second thought that makes sorting FASTER possible. Really going into depth on how we conceptualize quick Select is what’s more valuable than the code itself. Explaining it this way is sure to blow the interviewer’s mind as it shows the raw thought process being formed from simple observations.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
yuh
@deepraj279
@deepraj279 5 жыл бұрын
I am never going to forget quicksort because you taught me how to actually use it. Beautiful explanation
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
ye
@tedytedy8918
@tedytedy8918 5 жыл бұрын
Mannn you are the kinggg❤️❤️ A day before the exam on data structures i saw this video.. N this question was on the exam 🙂🙂
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
hahaha nice
@footerrykim
@footerrykim 4 жыл бұрын
For partitioning, why input size cut in half every stage? Isn't Input size still adjusted to n-1 based on the pivot??
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
The pivot just defines the value we partition against. We split in half (in a best case) since that is most optimal and if a good pivot is choosen then that will happen.
@footerrykim
@footerrykim 4 жыл бұрын
Back To Back SWE thx for quick reply. I was just making an assumption that the first pivot is the highest index and you keep searching towards to left partition..
@qwarlockz8017
@qwarlockz8017 3 жыл бұрын
Makes such great sense... you do amazing work. Thanks... Finding the big of the work.. I still totally suck at that .... thanks for doing great work for us all
@adityasoni1207
@adityasoni1207 2 жыл бұрын
Huge respect to this guy! Thanks a lot, these videos are amazing!
@Mrwiseguy101690
@Mrwiseguy101690 4 жыл бұрын
You have the best explanations I have ever seen. Definitely earned a sub.
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
welcome, you are loved
@nirajchowdhary7372
@nirajchowdhary7372 5 жыл бұрын
Ben you are a genius. Thank you so much you made this problem so easy!!!. Appreciate you for your efforts and time :D Love your channel!!
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
I seem smart but I'm not. And nice - sure - and thanks!
@stk1526
@stk1526 4 жыл бұрын
Amazing explanation!This has really helped me understand how partitioning works , and the details that i have missed .
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
great to hear
@ashutoshtiwari4398
@ashutoshtiwari4398 4 жыл бұрын
I like the way you walked through your thought process.
@mubarakoyeyinka8520
@mubarakoyeyinka8520 3 жыл бұрын
Thank you for all videos ! Very understanble !
@BackToBackSWE
@BackToBackSWE 3 жыл бұрын
Glad you like them!
@DarshanSenTheComposer
@DarshanSenTheComposer 5 жыл бұрын
The distinction between: i. T(N) = T(N / 2) + O(N) ii. T(N) = *2* T(N / 2) + O(N) took me by surprise! _sigh_ stupid me I've been watching some of your lectures for a while. I've gotta say, you're a really good teacher. Keep up the good work! :)
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
Thanks. Yeah, former bounds to linear time, latter bounds to n*log(n)
@wanderlustsiddhi
@wanderlustsiddhi 3 жыл бұрын
Thank you so much for such in depth explaination! The video content is gold! Love and support from India!😀
@badal1985
@badal1985 5 жыл бұрын
you are too good Ben! your videos are very helpful. please keep making them.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
haha ok, I will, as long as I'm a live
@akankshasharma148
@akankshasharma148 3 жыл бұрын
Your explanations are so easy to understand.Thanks a lot🙌🙌
@pushpendrasingh1819
@pushpendrasingh1819 5 жыл бұрын
BRO... you also need to share your upper push body workout. You are in great shape
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
hahahahaha
@bharathik6479
@bharathik6479 4 жыл бұрын
Clear Explanation... Thanks a lot for taking the time and effort to make these videos. Good Vibes and Blessings from CS Students.
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thansk and ye
@5ko99
@5ko99 4 жыл бұрын
Why there is no code in the description??? You said 5 times look that code, but where is it??
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
The repository is deprecated - we only maintain backtobackswe.com now.
@ryoyamamoto6488
@ryoyamamoto6488 4 жыл бұрын
This channel is fuuuuuckin amazing man. Sorry for cursing but I had to.
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thanks and ur good
@ivanleon6164
@ivanleon6164 3 жыл бұрын
you are great! keep the good work. Greetings from Mexico.
@shubhampareek2378
@shubhampareek2378 5 жыл бұрын
This is my 2nd or 3rd comment ever on KZbin. But all I wanna say is: "I wish there was a provision of giving more than one like". Thanks a lot.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
Hahahahhahaha, this vid was fire, not sure if I can drop more like it. Let's see haha
@chanish163
@chanish163 4 жыл бұрын
U are awesome 👌 ...u are helping many students 🤜🤛
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
sure
@TCErnesto
@TCErnesto 2 жыл бұрын
as a math lover I really enjoy your explanations, thanks man
@ojuskhanolkar7146
@ojuskhanolkar7146 4 жыл бұрын
I officially love you and I love this channel. You save me!!!!
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
great
@factsheet4930
@factsheet4930 4 жыл бұрын
I think you could have just said, in the complexity analysis part, that the sum from i = 0 to something of (1/2)^i, is strictly less than the sum from i=0 to infinity of (1/2)^i = 2, and so you end up with the answer being less than 2n - log(n), therefore it is linear complexity.
@laksh5228
@laksh5228 4 жыл бұрын
This partitioning is linear time only when we can ensure the pivot is proper right? but when we measure an algorithm's time complexity, do we not go by the worst case? And when we choose the pivot to be the worst(largest element), we would lose the entire left partition and thus losing the actual answer too in some cases right? Please clarify if am I missing something
@Ambs_2024
@Ambs_2024 4 жыл бұрын
Very good teaching style. Thanks for the tutorial!
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
sure
@BullishBuddy
@BullishBuddy 5 жыл бұрын
This is very good, man! Very good!! Thanks for teaching!!!!
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
haha thanks
@lokeshs9449
@lokeshs9449 4 жыл бұрын
Keep it up!! I read all your reply to the public comments that are brilliant& interesting. And I wait for your reply...!!
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
lol most are basic
@adityasrivastava8790
@adityasrivastava8790 4 жыл бұрын
Overpowered John!Great work;)
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
lol thx
@adityasrivastava8790
@adityasrivastava8790 4 жыл бұрын
@@BackToBackSWE he he @johnlegend aka all of me! Gr8 work byddy
@rupadosapati7628
@rupadosapati7628 4 жыл бұрын
for choosing the pivot int choosenPivotIndex = rand.nextInt(right - left + 1) this should be enough to pick a random index correct, why we need to add left for this. Please help me to understand
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
to compute the range of numbers?
@NGBigfield
@NGBigfield 4 жыл бұрын
Great video! So much effort that you've put into it!
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
ye, change da world, my final message
@vansh2k6
@vansh2k6 4 жыл бұрын
The explaination was too simple but the complexity analysis was little complicated to understand. However the code implementation was so easy t understand that this problem looks easy for me. Thanks a lot :)
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
cool
@arunprakash1101
@arunprakash1101 4 жыл бұрын
I am puzzled! Just by using Priority Blocking Queue, We can solve it in 0(n) Complexity, right? Why to rely on the Re-implementation of the QuickSort algorithm again? Please correct me if I am wrong ! public int findKthLargest(int[] nums, int k) { // TODO Auto-generated method stub PriorityBlockingQueue pq = new PriorityBlockingQueue(); for (int n : nums) { pq.add(n); if (pq.size() > k) { pq.remove(); } } return pq.remove(); }
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
That structure has operations underneath that likely add complexity? Not sure never used it
@arunprakash1101
@arunprakash1101 4 жыл бұрын
@@BackToBackSWE PriorityBlockingQueue solves the problem in O(n)! But using Quick select is even more efficient, I am able to increase the performance of my code more than 80 percent!! Cool! Kudos to your efforts !!
@Endlessvoidsutidos
@Endlessvoidsutidos 5 жыл бұрын
29 minutes of explanation multiple levels of complex thought involved both in math and computer science so much so that trying to explain it gets you kicked out of buildings .... LeetCode - Problem difficulty = Easy
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
lol
@netopedia8733
@netopedia8733 4 жыл бұрын
Awesome Explanation 🙏🏻 Thanks a lot
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
sure
@Mardil
@Mardil 5 жыл бұрын
Your videos are awesome dude, keep it up.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
thx and ok
@growingwithtech
@growingwithtech 5 жыл бұрын
Buddy, I think you have calculated the average case time complexity. What happens if pivot doesn't manages to split the array in halves, and the pivot happens to be one of the extremes. In that case, the worst case time complexity would be T(n)=T(n-1)+(n-1), which evaluates to O(n^2), which is even worse than heap-based approach. But anyways, I liked the way you think.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
What was the recurrence I solved?
@growingwithtech
@growingwithtech 5 жыл бұрын
You solved for the best case i.e., T(n)=T(n/2)+(n-1)
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
@@growingwithtech Ah, yeah, rewatched it, yes the worst case is O(n^2). I analyzed the best case (where we assume a 50/50 split), and it follows near the same reasoning as the average case (where we assume a 75/25 split) which also bounds to O(n). More on the average case: web.stanford.edu/class/archive/cs/cs161/cs161.1138/lectures/09/Small09.pdf Thanks for the question
@growingwithtech
@growingwithtech 5 жыл бұрын
Exactly!! Thanks for the clarification
@jyotisingh8183
@jyotisingh8183 5 жыл бұрын
Hello sir, can you please tell me in heap approach for kth largest or Kth smallest element we used minheap or maxheap respectively, but on what bases we're removing smallest element from minheap and largest element from maxheap. I want to know the implementation like how we're comparing elements inside both heap so that we could remove smallest or largest element. Thank you.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
Are you asking about how the heap works internally? Or at what capacity ejections happen?
@jyotisingh8183
@jyotisingh8183 5 жыл бұрын
@@BackToBackSWE Sir I mean that suppose for Kth largest Element we use Priority Queue and create a variable let's say large. Now I'll do large.add(arr); Next as you said to check if large.size ()>k then remove(); so how my large variable know which element is smallest? Same in the case of Kth smallest element how my variable know which element is largest so that we remove it.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
@@jyotisingh8183 Ah, so the point is we remove the largest items so that only the k smallest are left over. If I have [1, 2, 3] and I want the 2 smallest, I will not want 3 to be in there. So when capacity hits 3, the largest item in the heap (3) leaves.
@jyotisingh8183
@jyotisingh8183 5 жыл бұрын
@@BackToBackSWE yeah sir I got the logic but how my variable know that I have 3 which is largest then remove it? There should be some condition which checks which is largest or smallest element is there in heap to remove it if heap.size()>k.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
@@jyotisingh8183 It is a max heap so it is designed to keep the max element at the top to be removed.
@kiwixuerong7383
@kiwixuerong7383 5 жыл бұрын
Could you provide the order that we should follow to watch those videos? Because the beginning of the video shows that you've already covered the sorting methods, but it is the 2nd video in this "Sorting, Searching, and Heaps" playlist, so I got a bit confused by which one to start. Thanks for teaching, and your videos are really easy to understand and get to the point!
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
Hey, I'm rapid fire responding to comments (I got behind 250 after 2 weeks) I'd answer this but in a hurry, so sorry I recommend no specific order, just work on what you are weak on ...at one point in time I could answer everything ugh - ben
@rajivsarkar277
@rajivsarkar277 3 жыл бұрын
One doubt ... if the array is sorted then only the kth largest element will be at 4th index at 18:29. without sorting how we came to a conclusion that the kth largest will be in the right half of pivot.
@vanducnguyen346
@vanducnguyen346 4 жыл бұрын
Always love your enthusiastic when explaining, down to the smallest detail. Keep up the good work. I wish i've chosen CS major
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thanks & u can always do whatever. life is long in years.
@colorfulcodes
@colorfulcodes 5 жыл бұрын
I see your comments all over leetcode lol, great vid.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
hahaha yeah...those were the days..
@chuckchen2851
@chuckchen2851 3 жыл бұрын
One question on the heap solution: are we supposed to implement the heap bottom to top before solving problems in real interview (in case that's the solution we come up with)? Just thinking it'd be quite hard to do heavy and bug-free implementations under gunpoint.
@andrews2945
@andrews2945 4 жыл бұрын
Your explanations and visuals are always on point, thanks again. No flame, just thought it was funny, but did you have a stroke @ 20:57 😆
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
sure, and my bad
@DonTaldo
@DonTaldo 3 жыл бұрын
love your content man, kudos to you
@BackToBackSWE
@BackToBackSWE 3 жыл бұрын
I appreciate that!
@Messirobben047
@Messirobben047 3 жыл бұрын
If I ever have to pay for coding interview preparation platform, it'd be back to back swe
@gauravchaudhari3843
@gauravchaudhari3843 4 жыл бұрын
your explanation skills on point how do you grown like that
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
not sure
@tumul1474
@tumul1474 4 жыл бұрын
this was an awesome tutorial man ! thanks !
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thanks and sure
@sinaanyounus5449
@sinaanyounus5449 4 жыл бұрын
studying for my algos final rn thank u so much
@evgeniifeygin1030
@evgeniifeygin1030 Жыл бұрын
thanks a lot. one question only. You say "the code is in the description". I have searched in the Description - there is neither code or link to it. So where to find the code ?
@reneeliu6676
@reneeliu6676 5 жыл бұрын
No can't watch this after I'm drunk...I need to come back all fresh in the morning.
@marlegagaming1274
@marlegagaming1274 5 жыл бұрын
Lol🤣
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
haha
@mohneeshgarg8706
@mohneeshgarg8706 5 жыл бұрын
I code better after drinking, it keeps me focus..
@JoseSagrero1
@JoseSagrero1 5 жыл бұрын
Thank you for your videos! You're an awesome for making them.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
thx
@vikrant_462
@vikrant_462 4 жыл бұрын
you are suberb, I always recommend your video to those who ask for help...
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thx
@sddhrtha
@sddhrtha 5 жыл бұрын
Love your channel and effort.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
thanks
@PankajThakur-tc1dw
@PankajThakur-tc1dw 3 жыл бұрын
@Back To Back SWE what do you think about what if you first build_heap in O(n) then rather than going for largest-MIN HEAP and smallest-MAX HEAP...... we can actually go largest-MAX HEAP and smallest-MIN HEAP delete k elements 1 by one from build_heap Array that way complexity will be klog(n).
@ateamcoolboy5815
@ateamcoolboy5815 5 жыл бұрын
The Greatest of All Time
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
ye
@ShubhamPandey-un2sy
@ShubhamPandey-un2sy 4 жыл бұрын
next level vid bro
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
yes
@dhyeyparekh4994
@dhyeyparekh4994 4 ай бұрын
very nice explanation of each and every point....
@ankitgoyal8556
@ankitgoyal8556 4 жыл бұрын
This was the first question interviewer asked me 🥳
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
nice
@minijain5936
@minijain5936 4 жыл бұрын
or can we do this way use max heap for kth largest element and popout the max element k times then well have the kth largest value?
@jagriti2978
@jagriti2978 3 жыл бұрын
Can it be a possible solution that we do a heap sort using a max heap and stop after kth iteration to get the kth largest element?
@longuyen10119
@longuyen10119 4 жыл бұрын
Awesome content as always! Go Terps!
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
hey.
@Ankit-jn8ew
@Ankit-jn8ew 4 жыл бұрын
The Like/Dislike ratio clearly shows how good your content is! Good luck in the future.
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
fascinating - thanks
@MhZnSO4
@MhZnSO4 4 жыл бұрын
Man! You the man!
@BackToBackSWE
@BackToBackSWE 4 жыл бұрын
thx
The Quicksort Sorting Algorithm: Pick A Pivot, Partition, & Recurse
26:31
Back To Back SWE
Рет қаралды 166 М.
Search A 2D Sorted Matrix - Fundamentals of Search Space Reduction
29:31
Back To Back SWE
Рет қаралды 51 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Sort A K Sorted Array - Investigating Applications of Min/Max Heaps
14:25
Why Is Merge Sort O(n * log(n))? The Really Really Long Answer.
36:50
Back To Back SWE
Рет қаралды 117 М.
The Change Making Problem - Fewest Coins To Make Change Dynamic Programming
23:12
Lowest Common Ancestor Between 2 Binary Tree Nodes (A Recursive Approach)
20:30
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 516 М.