Data Structures & Algorithms in Swift · Heap | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/977854-data-structures-algorithms-in-swift/lessons/15

Thanks for the great course, I finally found a high quality production for DSA.
Regarding the Heap video. At the time 5:02, while implementing getParentIndex(ofChildAt:) -> Int, Jessy mentioned:

For the child indices on the left, which are all odd, the .5 you’d get from splitting them in a half will be thrown out due to integer division.

I think this is not true. Since the implementation subtract 1 from the child indices, this will change the odd to even (for all the left child), and will change the even to odd (for all the right child). So, to correct that, I’d say:

“For the child indices on the right, which are all even, after you subtract 1, the .5 you’d get from splitting them in a half will be thrown out due to integer division.”

Please correct me if I’m wrong. Thanks!

1 Like

The way I was thinking of this is that the right children were “taking on” the indices the left children originally had, before the division. But that needs better wording and a better diagram. Thanks for calling it to attention; we’ll improve that in the next update!

1 Like