CLRS icon indicating copy to clipboard operation
CLRS copied to clipboard

CLRS/C02-Getting-Started/exercise_code/merge-sort.py

Open amymayadi opened this issue 6 years ago • 1 comments

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.

amymayadi avatar Mar 12 '18 15:03 amymayadi

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]

ghostbody avatar Mar 12 '18 15:03 ghostbody