CLRS
CLRS copied to clipboard
CLRS/C02-Getting-Started/exercise_code/merge-sort.py
L = items[p:q+1] <----why use q+1
R = items[q+1:r+1] <----why use r+1
the problem asks not to use sentinels. Why use q+1 and r+1? Will there be more items than initial times? q+1 -p +1, r+1 -(q+1) +1 are more than q-p+1, r-(q+1)+1.
Because they are python array slices. For instance:
arr = [1, 2, 3, 4, 5, 6]
arr[0:3] # [1, 2, 3]
arr[3:6] # [4, 5, 6]