Update assignment
This commit is contained in:
parent
afda211746
commit
3778e0fd9e
|
@ -34,6 +34,6 @@ def _inversions(xs):
|
||||||
total += left + right
|
total += left + right
|
||||||
return (count + lcount + rcount), total
|
return (count + lcount + rcount), total
|
||||||
|
|
||||||
def inversions(xs):
|
def num_inversions(xs):
|
||||||
count, _ = _inversions(xs)
|
count, _ = _inversions(xs)
|
||||||
return count
|
return count
|
||||||
|
|
6
msort.py
6
msort.py
|
@ -1,9 +1,9 @@
|
||||||
def msort(xs):
|
def mergesort(xs):
|
||||||
if len(xs) < 2: return xs
|
if len(xs) < 2: return xs
|
||||||
|
|
||||||
leng = len(xs) // 2
|
leng = len(xs) // 2
|
||||||
left = msort(xs[:leng])
|
left = mergesort(xs[:leng])
|
||||||
right = msort(xs[leng:])
|
right = mergesort(xs[leng:])
|
||||||
|
|
||||||
# Reversing is O(n), but so is copying, so
|
# Reversing is O(n), but so is copying, so
|
||||||
# this does not worsen complexity.
|
# this does not worsen complexity.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user