In place algorithms:
Reversing a sorted list in-place.
a = [1,2,3,4,5]
n = len(a)
temp = 0
for i in range(n/2):
temp = a[n-1-i]
a[n-1-i] = a[i]
a[i] = temp
In-place sorting algorithms:
- focus on space efficiency
- uses no auxiliary data structures and uses very small extra space
- have O(1) space complexity (strict definition) to O(log n) space complexity (broad definition)
- usually overwrites the original data to create the modified output
- may need more time in some cases
Reversing a sorted list in-place.
a = [1,2,3,4,5]
n = len(a)
temp = 0
for i in range(n/2):
temp = a[n-1-i]
a[n-1-i] = a[i]
a[i] = temp
In-place sorting algorithms:
No comments:
Post a Comment