Skip to content

Instantly share code, notes, and snippets.

@Matthcw
Created February 26, 2021 23:39
Show Gist options
  • Save Matthcw/19fed9af079ea88362cc2c5fde2ec26c to your computer and use it in GitHub Desktop.
Save Matthcw/19fed9af079ea88362cc2c5fde2ec26c to your computer and use it in GitHub Desktop.
'''
O(n) sorting algorithm for sorting distinct positive integers
'''
array = [3,7,2,8,5,1,0]
#O(array) Time
n = max(array)
sortedArray = [None] * (n + 1)
#O(array) Time
for i in array:
sortedArray[i] = i
condensedSortedArray = []
#O(n) Time
for i in sortedArray:
if i is not None:
condensedSortedArray.append(i)
print(condensedSortedArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment