• Iron Lynx@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    14 hours ago

    If you want to zipper two sorted lists, you compare the first element of each list, pick that first, take the next element of that list, rinse & repeat until one list runs out and then just chuck the entire rest of the other list in the remaining space, even if that’s just one element. Since your two initial lists are already sorted, you can trust the combined list to also be sorted.

    • Eheran@lemmy.world
      link
      fedilink
      English
      arrow-up
      2
      ·
      7 hours ago

      So the point is that always only exactly 2 elements are compared and so you first have to split everything into groups of 2. Seems very inefficient for larger datasets, since you need to handle every single item over and over again and compare so so often. But not a sorting and comparison expert, so no idea if human sorting logic applies at all.

      • Iron Lynx@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        4 hours ago

        Tbf, Merge Sort has a Big O of n log (n) in all cases, so it’s a pretty mid sorting algorithm in general, but it’s conceptually straightforward and easy to explain to newbies.