Back to course home
0% completed
Vote For New Content
why is len(list) > i + 1, and not len(list) > i?
Jonathan
Jul 5, 2022
why is len(list) > i + 1, and not len(list) > i?
0
0
Comments
Comments
T
Taimur 3 years ago
Take for example list is [1, 2, 3]. If we just finished processing the 3, then 'i' in this case would be 2. If we did the check for len(list) > 2, we would see that 3>2 so we would attempt to add onto the heap with index i+1 = 3 which would throw an error.
On this page