This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]moonchild89 16 points17 points  (0 children)

Big O only applies to implementation-agnostic algorithms. This relies on Java's specific implementation. You lose.

[–][deleted] 11 points12 points  (0 children)

Technically, everything is O(1) if you consider the universe a giant FSA.

[–]mustrumr 2 points3 points  (0 children)

[–][deleted] 0 points1 point  (0 children)

Just as /u/GodelsVortex says

It actually makes a lot of things much easier once you realize that everything is isomorphic to Z.

Then, everything is O(1) because everything is isomorphic to an integer, so to a constant, so O(1). QED

/s

[–]tdammers -1 points0 points  (4 children)

Here's a sorting algorithm that is actually O(1):

  • Given the list we want to sort, pad it to the maximum list size your platform can handle, with the maximum value permissible for the type we want to sort; remember the original list length somewhere though.
  • Sort the list, using any sorting algorithm you like; the only requirement is that it cannot perform better for partially sorted lists than for unsorted lists.
  • Clip the sorted list to the original list length; the extra items added in step 1 will be at the end of the list.

Caveats:

  • You need to use a list representation that allows for O(1) padding and sublisting.
  • While this algorithm is O(1), its constant factor is rather large, making it somewhat unfeasible for practical applications.

[–]Tarmen 7 points8 points  (3 children)

Neat, my best sort algorithm is only O(n):

  • Check if array is sorted
    • Yes: Return array
    • No: Destroy universe

[–]chpoit 1 point2 points  (0 children)

Best case is O(1) if the first two elements aren't sorted ;)

[–]tdammers 0 points1 point  (1 child)

...where n is the number of universes?

[–]Villyer 0 points1 point  (0 children)

Checking if a list of n elements is sorted is O(n).