Why is Radix Sort so Fast? Part 2 Radix Sort

Поділитися
Вставка
  • Опубліковано 8 чер 2024
  • Support What's a Creel? on Patreon: / whatsacreel
    Office merch store: whats-a-creel-3.creator-sprin...
    FaceBook: / whatsacreel
    In this 3 part series, we will explore sorting algorithms from the fundamentals all the up to implementations of both a comparison sort and a base 256 Radix Sort.
    In this second video, we look at how counting sort, and then radix sort overcome the NLogN barrier and sort data in linear time!
    Prefix Sum on Wikipedia: en.wikipedia.org/wiki/Prefix_sum
    Software used to make this vid:
    Visual Studio 2019 Community: www.visualstudio.com/downloads/
    Blender: www.blender.org/
    OBS: obsproject.com/
    Davinci Resolve 16: www.blackmagicdesign.com/prod...
    OpenOffice: www.openoffice.org/
    Gimp: www.gimp.org/
    80's 3D neon effect in the thumbnail is from Ducky 3D's: • Blender - 80's Style A...
    Background HDRI from thumbnail and intro is from HDRI Haven: hdrihaven.com/

КОМЕНТАРІ • 719

  • @BillTyler
    @BillTyler 3 роки тому +348

    Radix sort is exactly how punched card sorters worked in ancient times. The machine had a bin for each punch position. (There were 12 punch positions in each column.) The card deck was run through the sorter once for each digit position, and the bucket contents picked up in order, the deck restacked, and run through the sorter for the next punch position until the entire sort key had been covered. Sorting a couple of thousand cards could be done quite quickly.

    • @new_reZn
      @new_reZn 2 роки тому +6

      astonishing!

    • @vNCAwizard
      @vNCAwizard 2 роки тому +8

      Such equipment went by the name Unit Record Machines. This category of hardware included sorters, simple calculation tools (adders, multipliers, subtracts and dividers, for instance) and printers.

    • @deedewald1707
      @deedewald1707 2 роки тому +2

      Bucket sort at work being efficient !

    • @suntexi
      @suntexi 2 роки тому +5

      I worked in a clearing bank in London back in the '60s and we used the same technique to sort cheques by account number, by magnetising the digits on the cheques and reading them. Eight passes for the account number which also sorted in branch order. The cheques had already had anything other than those that belonged to the bank removed and sent to the other bank. London cheque clearing in action.

    • @joebarrett4353
      @joebarrett4353 2 роки тому +1

      Those were the days!!!

  • @bobwatkins1271
    @bobwatkins1271 3 роки тому +63

    Decrementing the prefix sum serves two purposes: 1) converting to a zero-based index, and 2) avoiding collisions in the output array. The latter is accomplished by updating the value stored in the prefix sum array. This is a crucial point that should be stated explicitly.

    • @WhatsACreel
      @WhatsACreel  3 роки тому +15

      You are right! Thank you for watching :)

    • @incription
      @incription 11 місяців тому +5

      I was confused at first, but the visualisation made it really easy to realise you can just increment the counter!

  • @amdreallyfast
    @amdreallyfast 3 роки тому +90

    A few years ago I was working on a project to create a bounding volume hierarchy for collision detection, and as part of organizing the objects (along a space-filling curve for efficiency's sake) I followed some technical papers to create a GPU-based, parallel binary radix sort. It was fast, and the particles that were being collided never had to leave GPU memory. But it was a right beast.

    • @theRPGmaster
      @theRPGmaster 2 роки тому +12

      That's why I'm here, octrees!

    • @musicdev
      @musicdev 2 роки тому +9

      It takes a highly specific kind of nerd to call that awesome, but god damn, that is awesome!

  • @KingThrillgore
    @KingThrillgore 3 роки тому +489

    Radix sort is truly a sort without comparison.
    Get it? Because Radix doesn't do comparisons

    • @shirosurfer8864
      @shirosurfer8864 3 роки тому +33

      Like discrete mathematics is the one that counts the most

    • @restcure
      @restcure 3 роки тому +30

      Glad *that's* sorted!

    • @NStripleseven
      @NStripleseven 3 роки тому +4

      I see what you did there

    • @leocomerford
      @leocomerford 3 роки тому +14

      Now, there's a time and a space for this sort of thing ...

  • @ddc9999
    @ddc9999 3 роки тому +78

    I’m just a random 20yo student and I discovered this channel out of YT’s algorithm
    Loved it after only one vid, subbed and have been binge watching this on this rainy sunday afternoon, sipping coffee.
    My life is pointless but at least I’m learning cool stuff

    • @andrewwalker2888
      @andrewwalker2888 2 роки тому +11

      Hey mate, your life isn't pointless! I found this channel last night, and it's been great. I "graduated early" with a 2-year degree in electrical engineering a long while ago, never used it outside of school unfortunately.. and today I'm employed as a full stack dev with 7+ years of professional experience in that position. Life can be crazy, and I don't know much about it (yet!), but I know for sure, your life isn't pointless :) This is an old post, but hit me up if you wanna chat, or have any questions about anything. Much love.

    • @maxm9960
      @maxm9960 2 роки тому +2

      if you "really" learn this, by which I mean you understand to the degree that you can explain it to others well by yourself, you are already on track to a great career as a good software engineer. In time, you'll build yourself a good career at a software company like Microsoft or Google. Regardless of whether you like the companies, you'll at least set yourself up for a good salary which'll enable you to do what you like. Keep it up!! - source : I'm a senior software engineer at Google myself.

    • @markusballsdeep6051
      @markusballsdeep6051 2 роки тому

      Cringe

  • @timberwolf4242
    @timberwolf4242 3 роки тому +16

    This is literally the only channel on youtube about programming that i watch solely because the videos are made so engaging and fun, and not because i have to prepare for test.
    Best channel

  • @awardofsky9908
    @awardofsky9908 3 роки тому +180

    I've seen many youtube videos and papers on this matter and I must say that I never have seen sorting algorithms explained so simply and with such passion!
    I really liked how you explained the logic behind comparison based sorts on part 1, it's really useful to understand sorting networks and their limitations.
    You are an excellent teacher and hands down one of the best youtube channels on this matter!
    Btw, just a note: to implement radix sort for signed integers you just need to do the prefix sum in the last digit that includes the signed bit in a different order, going from the middle of the array to end and then from the start to the middle again so that the digits starting with
    1 (the negatives) appear first.
    For floats the idea is similar, but instead, you also have to do the first partition of the prefix sum in reverse order (going from the end of the array to the middle, and then from the start to the middle again) and then you adjust the scattering part so it decrements the pointers corresponding to numbers from the first partition. There are also bit flipping solutions, so you don't need an extra radix pass.

    • @Wyld1one
      @Wyld1one Рік тому

      Just have counts from -9 to 9. Eg 19 counts

    • @Redditard
      @Redditard 11 місяців тому

      @@Wyld1one it won't work, we start from the once's place, if you want to do -9 to 9 i'll add some overhead such as add +9 to your counts etc etc, and would also have to check the -ve every digit cycle

  • @tucan1309
    @tucan1309 3 роки тому +410

    linked lists take a lot of memory
    me a python programmer:
    i have never heard of that guy

    • @jacknguyen5220
      @jacknguyen5220 3 роки тому +59

      me, a Java programmer {
      you missed the braces and semicolons;
      }

    • @cedric1731
      @cedric1731 3 роки тому +70

      @@jacknguyen5220 I doubt you are a Java Programmer... There is neither a class declaration nor any method indicator ;)

    • @qreeves
      @qreeves 3 роки тому +89

      Meanwhile, in Perl: !#$%&(%$%^#@#%&%^@#*

    • @binarycat1237
      @binarycat1237 3 роки тому +16

      Haskell: wait, there's an alternitive?

    • @bluesillybeard
      @bluesillybeard 3 роки тому +37

      me, an assembly programmer: what's a list?

  • @JJCUBER
    @JJCUBER 3 роки тому +83

    10:36 “0 to 9!” That’s quite the range for the array 😉

    • @Zeero3846
      @Zeero3846 3 роки тому +14

      That's a fact ...
      ... orial

    • @leyasep5919
      @leyasep5919 3 роки тому +3

      some amps even go to 11 !

  • @mikicerise6250
    @mikicerise6250 3 роки тому +15

    MIND. BLOWN. Never have I been so sad that my sorting list is short. xD

  • @gaius_enceladus
    @gaius_enceladus 3 роки тому +51

    Your energy and accent remind me of Steve Irwin!
    "Crikey! It's a radix sort! Now, we'll just sneak up behind heeeem and grab heeeem behind the head....... "
    Cheers from New Zealand!

  • @bluesillybeard
    @bluesillybeard 3 роки тому +46

    This year has been really nerdy for me. I learned Python, Java, and i'm watching this awesome series!

    • @Funcijej
      @Funcijej 3 роки тому +4

      That's awesome good for you

    • @user-im7km8tq7j
      @user-im7km8tq7j 3 роки тому +3

      I code in c++ and whole life is nerdy)

    • @davidlynch4202
      @davidlynch4202 3 роки тому +2

      Awesome, you should try c, c++ and your cpus assembly language to see what goes on under the hood

    • @bluesillybeard
      @bluesillybeard 3 роки тому

      @@davidlynch4202 I am learning C and C++, but x86 assembly is way out of my scope right now.

    • @1andrew123
      @1andrew123 3 роки тому

      @@bluesillybeard thats what i thought too before I started trying to learn it :P you could figure it out

  • @TheMR-777
    @TheMR-777 3 роки тому +50

    Seriously Mate, your this series ... I am a CS Student of 3rd Semester. We haven't started Data Structures and Algorithms yet, but will soon be (from 15th of Sept). And I am feeling so lucky, that you are making such a Great Series of videos based on Algorithms! This Counting and Radix Sort got me curious to understand all types of Sorting and other Algorithms. All Thanks to you mate :)

  • @kzdm5255
    @kzdm5255 3 роки тому +24

    The complexity of the Radix Algorithm is dependent on the size of the largest number. So if you had just one max value 64bit integer, you would be running the counting algorithm 19 times.

    • @user-cd2cl7vt7r
      @user-cd2cl7vt7r 9 місяців тому

      Not really. If you do MSB radix sort it is perfectly possible to skip empty buckets and buckets of size one.
      As usual, real performance depends on implementation and data distribution.

    • @Slicerwizard
      @Slicerwizard 9 місяців тому

      Nothing stopping you from using 100, 1000 or 10,000 counters. Gets you down to ten, seven or five passes. 22 upvotes for you, but not a single bright bulb in the crowd for two years - yikes!

    • @jacey0479
      @jacey0479 9 місяців тому

      ⁠​⁠​⁠
      No? Bc you will quickly run out of memory

    • @Slicerwizard
      @Slicerwizard 9 місяців тому

      @@jacey0479 You are mistaken. Why do you think memory will be exhausted?

    • @jacey0479
      @jacey0479 9 місяців тому

      Your counters have to be < the size of the list. That is the problem with Radix sort, trying to find a balance between memory allocation and speed. Obv it also isn’t good for small lists.

  • @romanmueller3479
    @romanmueller3479 3 роки тому +2

    Was blown away by count sort. Simple yet genious idea. Thanks for this video.

  • @aiacfrosti1772
    @aiacfrosti1772 3 роки тому +6

    Radix sort is O(d * n), where d is the length of the elements. For sorting elements whose length is shorter than log(n) radix sort absolutely blazes through the list. If sorting a list whose elements lengths are longer than log(n) radix sort actually performs worse than its contemporaries. Given that a randomly generated list of unique packed keys has a longest length of log(n) (you eventually run out of unique elements at any given length and have to add another digit), the d * n starts looking suspiciously similar to nlogn.
    However if you have a very long list of short, non-unique keys (if you wanted to sort a list of dice rolls or something I guess) this is absolutely the best way to do it!

    • @GuillaumeGris
      @GuillaumeGris 2 роки тому

      If you have to sort a list of dice rolls, Just count them in an array of 6 bins. This will most likely be faster than radix. If for some reason you want a long list instead of a compact array with the same information, you can always generate it from the bin array in O(n) time

  • @retinizer7702
    @retinizer7702 3 роки тому +7

    I think I am in love with counting sort

  • @Aristotle000001
    @Aristotle000001 3 роки тому +4

    I love the way you present yourself and talk about these subjects. I've learned great things on this channel that I didn't even ask to learn, but just watched for entertainment xD

  • @frale_2392
    @frale_2392 3 роки тому +2

    I discovered your channel like yesterday, and as a game programmer in training I love your videos, you always explain things perfectly. Keep up the good work

  • @scorch855
    @scorch855 3 роки тому +1

    Your enthusiasm for sorting algorithms and computing in general is really engaging.

  • @yorgle
    @yorgle 2 роки тому +3

    I love watching those animated sort algorithm demonstrations, and Radix sort was always one that looked neat... but your explanation is fantastic! I finally understand it, and goddamn, is it freaking clever! :D

  • @shards1627
    @shards1627 3 роки тому +34

    one thing that you can take advantage of in some languages is using something other than strictly an array for counting, so you can just leave holes where there are no items with that value, rather than having a bunch of memory full of 0's. unfortunately it's usually slower because these data structures have more overhead than arrays do.

    • @WhatsACreel
      @WhatsACreel  3 роки тому +8

      This is an great idea! I think it would be especially useful for Radix Sorting smaller arrays. If we didn't need to Zero the entire digit array each round, might save some time! Cheers for watching mate, and cheers for the info :)

    • @elliott8175
      @elliott8175 3 роки тому +4

      I'm not so sure. I don't know of any random-access data type that you can iterate over (for providing the solution), without having these "holes". We could provide a second mapping array, but this requires a sort to know how to get the right mapping (circular dependencies).
      Whether it's possible to sort in linear time is still an open question. Radix comes really close, but isn't actually linear. If we were able to use an array "without the holes" then I think we'd have solved this famous problem and be rather famous (among CS geeks) - so my guess is the appropriate data structure doesn't (yet) exist.

    • @michaelwilkes0
      @michaelwilkes0 9 місяців тому

      @@elliott8175 I was thinking you might be able to do that with a hash map, but it would require a special hashing algorithm that not only produces semi uniqueness, but ALSO internally stores larger keys after smaller keys, which is the bit we are missing. Maybe a fancy hash algorithm that tweaks itself on the fly in response to the data and performs some acceptable amount of rebalancing yadda yadda. Obviously I dont know the answer. It could also end up that just computing the hash is slow enough that it kills the idea.

  • @wlockuz4467
    @wlockuz4467 2 роки тому

    This is like the big interview you get after winning a championship, perfect!

  • @islandfireballkill
    @islandfireballkill 3 роки тому +47

    Nice video, but I have to complain about the supposition that radix sort is somehow O(n). Its extremely important to leave in the O(nd) where d is the number of digits.
    O(n) invites an extremely dangerous line of thinking where somehow people may come to the conclusion that radix sort somehow asymptotically beats nlog(n). It does in an extremely limited sense but its hardly the full story.
    Unless you have an exponentially increasing fraction of duplicates, then d must be of the same order as log(n). You can't represent 10,000 distinct numbers without at least 5 digits or ~log2(10)*5 = 15 bits. Suppose you are infact beating those bounds and d < log(n). Then at most (base^d/n) fraction of your array can be unique values by the pigeonhole principle. Concretely if you are beating it by 2 decimal digits or like 6.6 bits then at most 1% of your array is unique an the other 99% must be duplicates.
    Plus it makes it seem like log(n) is much faster growing then it is. In practice log(n) is strictly less then 64 on most machines. Its really not fair to make a "fixed word length" argument for radix sort and other comparision sorts because in reality you could never sort more then 2^64 elements on a machine with 64 bits of address space anyway.

    • @elliott8175
      @elliott8175 3 роки тому +20

      Hello, I've got to agree and disagree. I hope that Mr Creel will talk more about the complexity in later videos, but I'd like to point out that the time complexity of Radix is actually *O(log[base b](k) * [n + b])* , or if you prefer *O(log(k)/log(b)*[n + b])* , where *b* is the number of _bins_ in the counting array (10, in our case), and *k = 1 + max_element - min_element* . Note that *b=10* was used in the video for _simplicity_ but its value should be dependent on the array input.
      If we set *b=n* , then *O(log[base b](k)*[n + b])* becomes *O(n*log[base n](k))* . We usually abbreviate *log[base n](k)* to *d* , but as you can see, how we count the number of digits changes as the input size grows.
      Informally: As the input size grows, Radix becomes increasingly insensitive to *k* even if *k* grows polynomially with respect to the size of the array.
      Radix is a bad choice when *k* is high _and_ *n* is small; specifically when *k > n^log(n)*

    • @WhatsACreel
      @WhatsACreel  3 роки тому +32

      I’d say you are both right! The proper time complexity is O(nd). Keys are often fixed in size. Not always, of course, but often. We tend to use 256 as the radix, resulting in 4 iterations with 32 bit unsigned ints. So, it’s true that radix sort’s time complexity is more subtle than O(n), but it’s also true that in practice it tends to perform at about O(n).
      I’d add that the time complexity for many things is subtle. Addition, for instance, requires O(1), so long as you have a machine that has an Add instruction with an arbitrary number of bits. Otherwise, it’s O(n) with n being the number of bits. Measuring the performance of algorithms is deep and complicated.
      Thank you for the info, and thank you for watching :)

    • @SemiMono
      @SemiMono 3 роки тому +13

      And this is why I generally use big O notation for making quick estimates, but not as a final decision maker. It's a very coarse measurement.

    • @Alexander_Sannikov
      @Alexander_Sannikov 3 роки тому +3

      @@elliott8175 that is correct, i found your comment right after explaining the exact same thing in mine. In O((n+b) log k / log b) each value can become a bottleneck. Sure, most of the time N will bottleneck, but so can higher than optimal base and higher than optional range. Especially when sorting binaries, fixed point floats, strings, etc.

    • @guymella
      @guymella 3 роки тому

      The way he explains radix sort... yes his version is not linear. In real radix sorts you always go most significant bit first. This means that after the first iteration you have a mostly sorted array and boundaries for all unsorted portions so you can recurse and sort the sub arrays or switch to quick sort in the subarrays. Aka burstsort.

  • @Lyam695
    @Lyam695 3 роки тому +1

    This has become one of my favourite comp sci channel. And this is not a small achievement, given the number of great resources on youtube.

  • @sveinungchr
    @sveinungchr 3 роки тому

    Man.. The things youtube wants me to learn is amazing... Thank you for taking the time to make this topic clear, understandable and interesting.

  • @theMosen
    @theMosen 2 роки тому

    Ok, this just randomly turns up in my YT feed for no apparent reason, even though it's old and I haven't watched a coding video in literally years. But thanks, algorithm, for knowing me better than I know myself, because I loved it!

  • @vukpsodorov5446
    @vukpsodorov5446 3 роки тому +1

    awesome stuff! also you're really good at explaining all this, it's all so simple to understand compared to some other explanations out there, awesome work!

  • @AhmedKhaled-xp7dm
    @AhmedKhaled-xp7dm 3 місяці тому

    Beautiful content, Thanks for the amazing explanation and visuals, it's clear that you love what you are teaching and that makes the videos more than perfect

  • @urouroniwa
    @urouroniwa 2 роки тому +1

    Right after I graduated from university, I did some travelling and ended up doing odd jobs at a travel tour company. It happened to be the end of the fiscal year and given that this was more decades ago than I'd like to admit, they had a mountain of physical files that needed sorting. Usually they spent 2 whole weeks to sort the files. They asked me to sort it. I can't remember exactly how I set it up, but I took over several desks and made my "buckets". Bucket sort works *really* well with physical files because concatenating them back into the original pile is simple :-). I got it all done in an afternoon and after that they thought I was a genius :-D

    • @michaelwilkes0
      @michaelwilkes0 9 місяців тому

      seriously. when someone hands you several file cabinets of paper, the first step is to sit down and think.

  • @yashpandey9550
    @yashpandey9550 3 роки тому

    One of the best sorting videos I have seen so far. Great work!

  • @SC1240
    @SC1240 3 роки тому +33

    Best channel on youtube hands down

  • @chrisburke1672
    @chrisburke1672 3 роки тому +1

    Just watched the first one, nice job posting the second part so quickly

  • @Winnetou17
    @Winnetou17 3 роки тому +29

    10:41: "We've got the input list just here... same elements as before, I think..." "Well, you wrote it, mate!"
    =)) What's a Creel playing both the teacher and the student for our amusement.
    Question: for integers, if you know you're big-endian, isn't it easier to simply build the counter array to have power-of-two buckets (like 8 or 16) ? And then, instead of doing mod 10, simply read the relevant 3-4 bits, put in the relevant bucket, and so on. You also have to make sure to have the sign bit in it's own step. Also, would it help to construct all the count arrays at once, so you only traverse forward the array once ? It uses a bit more memory, but arrays of 16 integers... doesn't sound that bad. Worst case for normal integers would be to compare 64 bit signed integers, and that would amount to 64/4 + 1 = 17 count arrays (the extra one is for the sign count array).
    Cheers!

    • @WhatsACreel
      @WhatsACreel  3 роки тому +3

      Sry, just realized I replied to the wrong comment yesterday, haha! My response didn't make any sense. Anyway, thank you for watching :)

    • @Winnetou17
      @Winnetou17 3 роки тому

      @@WhatsACreel No, it made sense. Having ANDs instead of DIVs (well, mod by 10 I think would've been for taking the digits in base 10)

    • @deedewald1707
      @deedewald1707 2 роки тому +1

      @@WhatsACreel Performing AND on LS 4 bits, then AND on MS 4 bits with SHR to bucket count and sorting process used on byte size numbers ! If needed, Scale up by groups of 4 !

  • @rczeien
    @rczeien 3 роки тому

    It makes perfect sense as you explain it. It reminds me of when you sort by multiple fields, you do the most important last.

  • @rayredondo8160
    @rayredondo8160 3 роки тому +2

    Okay, this is awesome! I've been trying to figure out a smart way to implement Radix Sort for a while, and you just gave me a way! Thank you for the awesome videos, keep doing awesome!

    • @WhatsACreel
      @WhatsACreel  3 роки тому +1

      No worries mate! Links to the original sources as well as my own version of the code will be provided in the final video. I hope to upload it later today. Thank you for watching :)

  • @alialmans
    @alialmans 2 роки тому

    absolutely beautiful, human ingenuity at its finest

  • @dodogo777
    @dodogo777 2 роки тому

    superb explaination! by far the most intuitive explanation I watched on radix sort. Thank you!

  • @sbqp3
    @sbqp3 2 роки тому +1

    Awesome stuff.
    Around 15:30, when talking about how to apply the prefix sum, I was thinking of the interpretation that the prefix sum is the running total of numbers with lower digits. So in the first iteration for 721, which end with 1, you are looking up how many items end with 1 or lower. And for 779 you are looking up how many numbers end with 9 or lower, etc. For each number, that tells you how many elements that need to be placed before that number, which also tells you the index of where to place it.

  • @jfk_the_second
    @jfk_the_second 2 роки тому +1

    Very informative and easy to understand! I think it was well-paced for beginners, as well as for people to whom the particular topic is novel, but the concepts familiar.

  • @serenasamborski6856
    @serenasamborski6856 3 роки тому +1

    You did such a good job explaining this! I’m just a self taught programmer but i had no problem understanding this! And it’s really interesting too!

  • @pepe6666
    @pepe6666 10 місяців тому

    thanks mate i appreciate your approach to these videos. you are very human and i can really get a feel for the worth / importance of each thing you mention. thanks man

  • @JesusP7
    @JesusP7 3 роки тому

    Don't know why youtube recommended me this, but for once the algorithm got it right! Didn't know i wanted to know this.
    Perfectly explained, great step-by-step examples. Thank you for the content

  • @eugenematison5571
    @eugenematison5571 9 місяців тому

    Did not see other videos from this channel yet. But this one is enough to be subscribed! ))

  • @KetilDuna
    @KetilDuna 8 місяців тому

    That was a really neat explanation of a smart sorting method. Thank you for sharing.

  • @NeilRoy
    @NeilRoy 3 роки тому +1

    I was puzzled at first, but the final part of the video cleared it up for me. Brilliant algorithm.

    • @WhatsACreel
      @WhatsACreel  3 роки тому

      I know what you mean! It's such a clever trick! Cheers for watching brus :)

  • @tatianabasileus
    @tatianabasileus 3 роки тому +118

    Seems like radix-sorting strings would work too, as long as they are made from a defined alphabet?

    • @WhatsACreel
      @WhatsACreel  3 роки тому +65

      Indeed it does! A viewer from the last video mentioned he did a talk on implementing Radix Sort for strings at JuliaCon last year! His talk can be viewed at: ua-cam.com/video/C65vYWeN7-k/v-deo.html

    • @meneldal
      @meneldal 3 роки тому +52

      It's actually potentially much better with strings because comparisons can take a lot of time with strings, but accessing a single character is fast.
      The bad news is you probably can't make this work with unicode easily. A string comparison in unicode is already an unsolved problem so you may not care about that.

    • @vylbird8014
      @vylbird8014 3 роки тому +11

      @@meneldal You don't need your string comparison to be particularly meaningful to use it in a sort. You just need it to be consistent.

    • @meneldal
      @meneldal 3 роки тому +18

      @@vylbird8014 The problem in Unicode is two string can look identical when you render them but don't have the same representation. Even normalization doesn't deal with every subtle thing.
      So while it will be consistent, it may give you results you don't want.

    • @MatthewDempsky
      @MatthewDempsky 3 роки тому +8

      @@meneldal You just need to transform your Unicode strings into byte strings such that the desired ordering is preserved. For example, the C standard library includes strxfrm() and wcsxfrm() for exactly that purpose.

  • @szeptaczsprezarek
    @szeptaczsprezarek 3 роки тому +1

    Best 20 minutes I've spent today!

  • @Antiorganizer
    @Antiorganizer 8 місяців тому

    You're a natural! Nice and concise and clear! Kudos for that!
    Tell me you're a high school, college, or university teacher!

  • @CrystlizeWorld
    @CrystlizeWorld 3 роки тому

    Mate unreal content, love you from your beginners to C++ but this stuff is top!

  • @meanmole3212
    @meanmole3212 3 роки тому +4

    Hearing "Good stuff!" takes me back to 2014-2015 :D

  • @ChrisHalden007
    @ChrisHalden007 3 роки тому

    Excellent as always. I absolutely love your style. So fresh and educative 👍

  • @ferinzz
    @ferinzz 3 роки тому

    Watched the whole series, this stuff is amazing!

  • @Greedygoblingames
    @Greedygoblingames 3 роки тому +1

    An excellent explanation and demo of radix sort. Quality UA-cam content this is.

    • @bruceleenstra6181
      @bruceleenstra6181 3 роки тому

      I agree, very clearly explained. After watching this video, (plus the previous videos reference to a mask and right shift) I wrote a working 16 bucket radix sort in 10 minutes.

  • @ibrahimyosif
    @ibrahimyosif 2 роки тому

    love your videos man, just found you here great work!

  • @robertlittlejohn8666
    @robertlittlejohn8666 3 роки тому +3

    I;m old enough to remember how the old IBM punched card machines were used for sorting. It was a radix sort, and the "buckets" were actual buckets or slots that a card would fall into, if, say, column 35 were punched with a 3. You'd then gather the 10 buckets up in order, and run the deck through again, soring on column 36 (or whatever).

  • @linobigatti
    @linobigatti 3 роки тому +2

    Radix sort is plain magic, and youve explained it perfectly ö

  • @nathanmartinez2630
    @nathanmartinez2630 2 роки тому

    Beautiful; a work of art. Thank you Creel!

  • @winstonsmith8597
    @winstonsmith8597 2 роки тому

    I have a large array been waiting for this sort

  • @elliott8175
    @elliott8175 3 роки тому +3

    Great video series. Radix getting the attention it deserves!
    I would point out though that I don't think that Radix is a compromise between speed and memory (when compared to Counting Sort). If k is (1 + max_element - min_element), then counting sort has O(k) space complexity **and** O(n+k) time complexity (auxiliary array requires linear traversal: first to initialise to 0, then to load the solutions). This is just as much of a time problem as a memory problem, so Radix helps to handle both of these.

  • @MadhavaVishnubhatla
    @MadhavaVishnubhatla 3 роки тому +67

    I love you my guy

    • @WhatsACreel
      @WhatsACreel  3 роки тому +10

      Ha! You too

    • @kippenegg
      @kippenegg 3 роки тому +1

      Same, this series is so interesting

  • @RickeyBowers
    @RickeyBowers 3 роки тому +2

    Well done, loved the graphic work you put into your videos. Of course, some of the radix sorting can be done in parallel.

    • @WhatsACreel
      @WhatsACreel  3 роки тому

      Indeed it can, yes! Cheers for watching mate, have a good one :)

  • @hacked2123
    @hacked2123 3 роки тому +4

    Watched the first video and was going to propose what you called "counting sort"; my idea was to determine min/max and only use counts that fall in that range.

  • @Fanaro
    @Fanaro 11 місяців тому

    What an underrated channel!

  • @durimmiziraj4815
    @durimmiziraj4815 2 роки тому

    Great job at explaining this. I absolutely love it.

  • @ke9tv
    @ke9tv 11 місяців тому

    Back in the day, I encountered a radix-2 sort that was coded for a PDP-8 with two LincTapes (or DECtapes, which were just LINCtapes rebranded). Random access tapes - there was a timing track so that you could read and write anywhere, not just at the end of the tape. The buckets were accumulated in odd- and even-numbered sectors on the output tape. There was a weird trick where alternating passes through the tapes read the tapes backward. Nothing like sorting a megabyte of data on a machine with 16 kilobytes of core memory!
    When I jot a job as a mainframer, I encountered five-tape read-backward polyphase merge. Insane!

  • @furkanunsal5814
    @furkanunsal5814 3 роки тому

    This is absolutly genius. And a great video congrats

  • @amkhrjee
    @amkhrjee Рік тому

    Amazing mini-series! Thanks a ton for taking the time and effort to make the beautiful presentations. Much appreciated. And, on a different note, is that a cat holding a cricket bat? I'm talking about the picture behind you.

  • @arlynsneha5052
    @arlynsneha5052 3 роки тому

    You sorted it clearly in our brains !!!!!!!!

  • @Stephanbitterwolf
    @Stephanbitterwolf 3 роки тому

    I love your enthusiasm!

  • @JulianMakes
    @JulianMakes 3 роки тому

    Brilliantly explained thank you!

  • @AngrocSound
    @AngrocSound 2 роки тому +2

    Brilliant, and such an awesome explanation. Only improvement would be to mention to subtract 1 from the prefix sum for *each* time you move an input to the ouput, not only once (all the talk of moving from 0 to 1 base counting confused that part for me). Slow-mo'ing the part where you go through the rest of the items real fast helped me see what you where doing to make it work. Thanks for sharing!

    • @markt43
      @markt43 2 роки тому

      An alternative approach would be to shift all the counts to the right and set the count of 0 to zero. In this approach, you would iterate from left to right and increment the counts instead of decrementing them. You would not have to convert between base 0 and 1 in this approach.

  • @djnn22
    @djnn22 2 роки тому +1

    I would like to see a pinned comment about repeating digits when decreasing the prefix index... I did not realize that you do not reset the prefix index and "accumulate" the -1 so that identical digits don't get the same spot... I had to go through many comments before I found the answer to that Interrogation...
    The rest of the video is really informative, thank you!

  • @bakedbeings
    @bakedbeings 3 роки тому

    This is a man who loves it.

  • @SosetaFurioasaJr
    @SosetaFurioasaJr 2 роки тому

    G'day, matey! Thank you again, here's one for the algorithm ! Btw, loved the little joke between you and the presentation with the same different set of numbers, haha.

  • @clonger204
    @clonger204 3 роки тому

    You're a bloody legend mate, cheers.

  • @clock4883
    @clock4883 3 роки тому

    Your channel is amazing, great explanations and graphics! :D

    • @WhatsACreel
      @WhatsACreel  3 роки тому +1

      Thank you! Cheers for watching :)

  • @hs3881
    @hs3881 3 роки тому

    Excellent explanation!

  • @neverremindyou6172
    @neverremindyou6172 3 роки тому +56

    Right now I´m studying "Computer Science" and i am learning for something we call "Algorithms and Datastructures". These 3 videos were actually shorter and way better than the ones from university. I can´t find something for big O notation in general from you. Do you have Videos for that topic? Anyway i reallly love your vids! Keep on Doing these! And sorry for bad english.

    • @WhatsACreel
      @WhatsACreel  3 роки тому +26

      Your English is great! I don't have any vids on Big O, but that's a great idea! Thank for watching, and thank you for the suggestion :)

    • @TheMR-777
      @TheMR-777 3 роки тому +3

      Wait ... For Big 'O Notation, you can check the channel of : *CS Dojo* . When "What's Creel" said about Big 'O notations, I instantly jumped to his tutorial :), and got the concept. Then came here to understand this. By the way, Great explanation.

    • @sjainsjain-hj4oq
      @sjainsjain-hj4oq 3 роки тому

      @@WhatsACreel caaan you make big 0 video sir covering topics from CLRS bible..I am not able to understand that book.

    • @T3BFitnessTripleThreatBoss
      @T3BFitnessTripleThreatBoss 3 роки тому +2

      Download EDX app on your phone and do the CS50 Introduction to Computer Science from Havard.

    • @milkYw4iMC
      @milkYw4iMC 3 роки тому +1

      Aachen? x)

  • @technowey
    @technowey 3 роки тому

    Great video! Thank you for posting this.

  • @kidsforcode3052
    @kidsforcode3052 3 роки тому

    Nicely explained! Thanks so much!

  • @codewizard58
    @codewizard58 3 роки тому +50

    I didn't see you mention that when building the output array, you increment the index in the count array, to handle where the same digit is repeated. The prefix sum has already taken this into account.

    • @SergeyNeskhodovskiy
      @SergeyNeskhodovskiy 3 роки тому +17

      Also had to replay a couple of times to understand this, but I believe it's DEcrement rather then INcrement, right? He decrements the prefix sum and the next time the same digit occurs the prefix sum is already decremented and gets decremented once again

    • @peterhobo
      @peterhobo 2 роки тому +5

      @@SergeyNeskhodovskiy yes, and that's also why you move from the end of the array to the start. You move the higher numbers into position first, then decrement so that the next position in the prefix sum is next highest number

    • @disekjoumoer
      @disekjoumoer 2 роки тому +9

      This is actually pretty irritating. He decrements the index of each value once it is accessed so that repeat numbers don't land up in the same spot. It's a major omission that will cause people who don't know what a radix sort is.

    • @peterhobo
      @peterhobo 2 роки тому +10

      @@disekjoumoer he certain does mention that you decrement the values in the prefix sum. Do you mean he didn't take the additional step of explaining the second purpose of it?

    • @kcaz64
      @kcaz64 2 роки тому +1

      @@disekjoumoer He does mention that though. I agree he should have made it a bit more explicit, but he *does* say you need to decrement it after accessing it.

  • @xavierdupont5772
    @xavierdupont5772 2 роки тому

    Thank you man.
    I discovered radix sort in this crazy guy videos that make animated sorting algorithms with sound, and it's a lot of fun to watch, but not I finally understand how it works. It's a kind of magic ;).

  • @vvill-ga
    @vvill-ga 3 роки тому +6

    Please do a video on how Radix Sort performs with differently based numbering systems, like binary or hex. I'd assume larger based numbers rely more on storage and read/write speeds, and smaller based numbers like binary rely on processing speed instead. Thank you!
    EDIT: Sorry, didn't see the other video you posted. Watching it now!

  • @davidm9442
    @davidm9442 2 роки тому

    Great content! Thanks for explaining this in detail : )

  • @mandeepbhatia_air
    @mandeepbhatia_air 3 роки тому

    Thanks, very nice explanation

  • @polares8187
    @polares8187 3 роки тому

    This was really cool. Thanks for sharing.

  • @bradley1995
    @bradley1995 3 роки тому

    Wow, this is a great video!

  • @shirosurfer8864
    @shirosurfer8864 3 роки тому

    Fantastic fantastic this are the kind of things that are worth learning in life man ty

  • @axelkoster
    @axelkoster 3 роки тому

    very smart algorithm, i love this stuff

  • @xipheonj
    @xipheonj 2 роки тому

    Thank you youtube algorithm, it has decided that I needed to watch this today, and it was right.

  • @UTRG-UnderTheRain
    @UTRG-UnderTheRain 2 роки тому

    Worth a sub just for this video nice explanation

  • @mitri-dvp
    @mitri-dvp 3 роки тому

    Love this channel so much!

    • @WhatsACreel
      @WhatsACreel  3 роки тому

      Cheers mate! Thanks for watching :)

  • @willzin-da-esfiha
    @willzin-da-esfiha 7 місяців тому

    I was implementing radix sort by my own and I was surprised when my algorithm managed a total of 10GB RAM (not at same time, of course, but the sum of all allocating and deallocating operations).
    To improve it first I tried to do a better approach for bucket vector: instead of allocating 1 extra position by push operation, I would double the allocated size and use a second length prop to measure the vector. After that, I could reduce the 10GB total handled RAM to 400MB.
    Watching the video, an idea instantly clicked in my mind when I saw the digit counting array: "I CAN PREDICT THE BUCKET SIZE BY ITERATION!!!!" then I stopped video and did it. Reduced from 400MB to 100MB total handled memory.

  • @sekaita
    @sekaita 2 роки тому

    really wonderful explanation!

  • @mcspud
    @mcspud 3 роки тому

    This video was so good I just became a Patreon. Thanks mate!

    • @WhatsACreel
      @WhatsACreel  3 роки тому

      Legend! Cheers for watching mate, and cheers for the support :)

  • @timmurphy5541
    @timmurphy5541 2 роки тому

    This was very good. I wish that more had been put into explaining the prefix sum - some of the mechanics were quite obvious and didn't need as much explanation as that did. I know it's a lot of work to do these things so thank you and at least it has given me a question to find an answer for.

    • @timmurphy5541
      @timmurphy5541 2 роки тому

      ah, Ding! now I get it - after writing that...duh. :-)

  • @mp9508
    @mp9508 3 роки тому

    That was a fun watch.

  • @ssojyeti2
    @ssojyeti2 3 роки тому

    I love your channel man

  • @jesse2667
    @jesse2667 3 роки тому

    13:24 The moment I realize the GENIUS of this technique.
    This is AMAZING

    • @Darkev77
      @Darkev77 3 роки тому

      Could you elaborate your insight please?

    • @jesse2667
      @jesse2667 3 роки тому

      @@Darkev77 He was talking sbout the linked list approach, with the downside of the overhead. I was picturing how to layout the datastructure in an array, remembering how a heap is actually stored in an array. The problem is to know where to start each of the buckets. At this point is where I noticed the sums are the index of the pointers to each bucket 🤯. So he solves the allocation problem.