Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 6
    \$\begingroup\$ I think you are not lazy if you do it in this way \$\endgroup\$ Commented Jun 15, 2017 at 19:55
  • 4
    \$\begingroup\$ @JörgHülsermann well some integers are too heavy...not exactly in the mood to carry such a weight, better to take off just the top stuff out \$\endgroup\$ Commented Jun 15, 2017 at 20:25
  • 21
    \$\begingroup\$ <sarcasm>This sorting algorithm actually still clocks in at O(N^2) time complexity because you have to go through all previously-accessed items on the list to decrement them. I recommend going through the list backwards instead and decrement only one number per step as necessary. This will give you true O(N) complexity!</sarcasm> \$\endgroup\$ Commented Jun 15, 2017 at 22:04
  • 1
    \$\begingroup\$ @ValueInk O(n^2) in terms of memory accesses, but isn't it O(n) for comparisons? \$\endgroup\$ Commented Jun 16, 2017 at 2:31
  • 7
    \$\begingroup\$ @ColeJohnson technically yes, but time complexity needs to take all the steps of the algorithm into consideration. You still have to iterate through all previous indices on every iteration, so it still comes out O(N^2). \$\endgroup\$ Commented Jun 16, 2017 at 2:38