Комментарии:
This is great video! but, I feel the algo provided in the end is not the same as the way he was explaining.. I went ahead and wrote my code for it same way he explained:
```
class Solution:
def sortArray(self, nums: List[int]) -> List[int]:
def quicksort(nums, lo, hi):
if lo < hi:
partition_resting_point = partition(nums, lo, hi)
quicksort(nums, lo, partition_resting_point - 1)
quicksort(nums, partition_resting_point + 1, hi)
def partition(nums, lo, hi):
pivotIdx = random.randint(lo, hi)
nums[pivotIdx], nums[hi] = nums[hi], nums[pivotIdx]
pivot = nums[hi]
l_idx = lo
r_idx = hi-1
while l_idx <= r_idx:
if nums[l_idx] <= pivot:
l_idx+=1
elif nums[r_idx] >= pivot:
r_idx-=1
else:
nums[l_idx], nums[r_idx] = nums[r_idx], nums[l_idx]
l_idx+=1
r_idx-=1
nums[l_idx], nums[hi] = nums[hi], nums[l_idx]
return l_idx
quicksort(nums, 0, len(nums)-1)
return nums
```
dude thx ur so good quick sort explain,i watch so many video but i still cant understand, ur detail explain is amazing , thx
ОтветитьBogo Sort is simplier.
Ответитьmy code will not work!!!!!!!
ОтветитьI liked it, a clear and complete video. Thanks a lot :)
ОтветитьBest Quick Sort video ive ever seen!
Ответитьwhen you have a truly suffled list, i see no point in averaging the first, middle and last element. No difference between doing that and just averaging the first three elements. I would just pick the one that already on the right
ОтветитьTime for me to put the fries in the bag
ОтветитьThat was pretty quick
ОтветитьMaybe this isn't the sort of thing you can explain in 4 minutes. Only someone who already understand this will know what you're talking about. Too confusing and too many steps omitted
ОтветитьWhat kind of course it’s really confusing 🚶🏻♀️➡️🧎🏻♀️➡️
ОтветитьThat pseudocode was very confusing
ОтветитьI wish the video was longer… You explained quite well, but I would love to learn more about the details that you didn’t get a chance to cover.
ОтветитьI think we should pick the pivot and start comparing , value at i and pivot value not pivot is shifted at last.index and keep swaping based on element values
Pseudo Code :
QUICKSORT(A)
1: if A is empty then
2: return A
3: last← (length(A) − 1).index
4: pivot ← A[last] // Take last element as pivot
5: less ← {A[i] | A[i] ≤ pivot, i != last}
6: more ← {A[i] | A[i] > pivot, i != last}
7: return (QUICKSORT(less), pivot, QUICKSORT(more))
yea nvm
ОтветитьGreat series man! This week is my Algorithms II exam and these helped me. Keep it up :)
ОтветитьLet's make it simple
* - if array has single or no element, return it as already sorted
1 - select a pivot in array (best is to choose last element)
2 - maintain two set (less, greater)
3 - loop through the array till 2nd last index and move lesser or greater than pivot to respective sets
4 - return recursive(left), append pivot & append recursive(right)
pseudo logic
==========
function quickSort(arr) {
left =[], right =[]
pivot = arr[arr.length-1];
for(i=0;i<arr.length-1;i++){
if(arr[i]<pivot){
left.push(arr[i]);
} else {
right.push(arr[i]);
}
}
return quickSort(left).concat([pivot]).concat(quickSort(right));
}
Ain't nothing quick about this sort.... DAMM
ОтветитьThere was quiet a bit of sigma in this video wouldn't you say my fellow skibidis?
ОтветитьWhy do we move the pivot to the end in the beginning?
ОтветитьMy prof taught me this is in like 1 hour(nothing reached to my braincells)but this 4 minutes taught me well ☝️
ОтветитьI feel like this requires some hands on experience with recursion to understand properly. If anyone doesn't, please try to do a few binary tree problems on leetcode, makes a world of difference in understanding recurson based algorithms
Ответитьthese videos are all good, but I feel like it needs to connect the dots for some of us slow brains it feels like its throws at me dots that are not full circled.
ОтветитьThanks. Pretty simple explanation.
ОтветитьIf anyone is interested in the algorithm of quicksort written in javascript, i've just coded it myself when practicing the concepts of this video
```
function quickSort(arr) {
if (arr.length <= 1) return arr;
else if (arr.length === 2) {
if (arr[1] > arr[0]) return [arr[0], arr[1]];
else return [arr[1], arr[0]];
}
const pivotPosition = Math.floor(arr.length / 2);
// Swap pivot position with the end of the array
let tmp = arr[pivotPosition];
arr[pivotPosition] = arr[arr.length - 1];
arr[arr.length - 1] = tmp;
// Create left and right pointers
let left = 0;
let right = arr.length - 2;
// move left and right pointers
while (left < right) {
while (arr[left] <= arr[arr.length - 1]) {
left += 1;
}
while (arr[arr.length - 1] <= arr[right]) {
right -= 1;
}
if (left < right) {
tmp = arr[left];
arr[left] = arr[right];
arr[right] = tmp;
}
}
// swap pivot with left
tmp = arr[left];
arr[left] = arr[arr.length - 1];
arr[arr.length - 1] = tmp;
const sortedLeft = quickSort(arr.slice(0, left));
const sortedRight = quickSort(arr.slice(left + 1));
return [...sortedLeft, arr[left], ...sortedRight];
}
```
I've focused on didactic instead of performance:
- I have just choosed the middle element of the array as the pivot (for simplicity)
- I wasn't worrier about memory optimization, so i allowed myself to create copies of the array
feel free to rewrite the code using a better algorithm to choose the pivot, and optimize the memory usage
bro big fan
ОтветитьVery very good video, thank you! I really love how you never stutter over your words, and never say uhm or uhhhh. That makes this very easy to watch.
ОтветитьNow this one better!
ОтветитьI don't get it. What if the pivot has no greater than or less than itself? What numbers can it compare to?
ОтветитьAlan Turnpike
Ответитьbetter and much easier algo than any standard quicksort algo available in the books
Ответить"let's let recursion handle the rest" > "here's the rest of the owl"
ОтветитьPivot is reference. You just got to put all the values that is larger than the pivot to the right and values smaller than the pivot to the left. Thats all it is. Why are the comments overreacting??
ОтветитьThis is great for revision
ОтветитьIn your head don't move the pivot to the end and think of it more like one big tree.
ОтветитьBro Tamil la sollunga
ОтветитьVery good video, I learned quick sort easily thanks to this. Although, I did have to rewatch the "median-of-three" explanation.
ОтветитьI remember i wrote a quicksort program understood fully the concept and 6 months later i dont even remember the concept. Quicksort is such a weird algorithm
Ответить1,794,000th view!!!!! :D
Ответитьthank you sir give me ur no i will pay 100 bucks
ОтветитьThat’s a pretty slow quicksort
ОтветитьWait in (nlogn), is the log in base ten or base e?
ОтветитьI thought my dumbass couldn't understand it, then I read the comments and realised that I lack basic understanding and must work on quicksort properly. This video is just like last minute revision for us I guess.
Btw, ur videos help me understand a lot better and make me code the algorithms myself after learning the concept except this one
😅
this made it more confusing , i thought i was close smh
Ответитьthis ain't how they explained it to us... Like, how many different quicksort are there that the way it's shown are that different from each other...
ОтветитьHow do you make these animations for your videos?
Ответить