Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. Marge sort

Marge sort

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
5 Posts 5 Posters 2 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • hiddenlayer555@lemmy.mlH This user is from outside of this forum
    hiddenlayer555@lemmy.mlH This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #1
    This post did not contain any content.
    C 1 Reply Last reply
    1
    442
    • System shared this topic on
    • hiddenlayer555@lemmy.mlH [email protected]
      This post did not contain any content.
      C This user is from outside of this forum
      C This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #2

      I was with you until the last step. How did it all get sorted, instead of having two "peaks"?

      shnizmuffin@lemmy.inbutts.lolS 1 Reply Last reply
      4
      • C [email protected]

        I was with you until the last step. How did it all get sorted, instead of having two "peaks"?

        shnizmuffin@lemmy.inbutts.lolS This user is from outside of this forum
        shnizmuffin@lemmy.inbutts.lolS This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #3

        I'm pretty sure it's because the sort comparison is between the indexes of each array, and happens at every step.

        D 1 Reply Last reply
        2
        • shnizmuffin@lemmy.inbutts.lolS [email protected]

          I'm pretty sure it's because the sort comparison is between the indexes of each array, and happens at every step.

          D This user is from outside of this forum
          D This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #4

          Then what is the purpose of the middle steps?
          Second to last also has this problem.

          The image has big "Draw the rest of owl" energy.

          H 1 Reply Last reply
          1
          • D [email protected]

            Then what is the purpose of the middle steps?
            Second to last also has this problem.

            The image has big "Draw the rest of owl" energy.

            H This user is from outside of this forum
            H This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #5

            I think the image assumes that the viewer is familiar with merge sort, which is something you will learn in basically every undegraduate CS program, then never use.

            To answer your first question, it helps to have something to compare it against. I think the most obvious way of sorting a list would be "insertion sort", where you look through the unsorted list, find the smallest element, put that in the sorted list, then repeat for the second smallest element. If the list has N elements, this requires you to loop through it N times. Since every loop involves looking at N elements, this means you end up taking N * N time to sort the list.

            With merge sort, the critical observation is that if you have 2 sublists that are sorted you know the smallest element is at the start of one of the two input lists, so you can skip the inner loop where you would search for the smallest element. The means that each layer in merge sort takes only about N operations. However, each layer halves the number of lists, so you only need about log_2(N) layers, so the entire sort can be done in around N * log(N) time.

            Since NlogN is smaller then N^2, this makes merge sort theoretically better.

            1 Reply Last reply
            1
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups