What does the -1, -1 in range(n, -1, -1) do, I have encountered this same pattern and implementation with various sorting algo, and it’s confusing me so much. Any answers would be appreciated! thank you in advance – NewCoder
n = len(A) for i in range(n, -1,-1): max_heapify(A,n, i) for i in range(n-1,0,-1): A,A[i]=A[i],A max_heapify(A,i,0)
The signature for
range(start, stop[, step]).
range function in
range(n, -1, -1) accept 3 argument:
‘n’ as the start index of the range object
the first ‘-1’ as the end index of the range object
the second ‘-1’ as the move step of the range object
range(n, -1, -1) basic means construct a sequence of [n, n-1, …, 1, 0].
For more you can refer to Python Doc
Answered By – Foolhardy Hardy
Answer Checked By – David Goodson (AngularFixing Volunteer)