Created
February 26, 2021 23:39
-
-
Save Matthcw/19fed9af079ea88362cc2c5fde2ec26c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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