Hi – To post code, use the </> icon in the middle of the menu bar that appears at the top of the text box you are typing in.
self.heap_list[self.parent_idx(idx)] = self.heap_list[idx]
Since it’s a min-heap, you want parent value to be less than child value, so, yes if parent value is greater than child value, you need to swap the two.
Since in the heap, the parent - child relationship is defined by the indexing system, what you need to do is swap the values stored at those two indices.
The line above accomplishes part of that swap; it overwrites the value stored at the parent index with that stored at the child index. You also need a temp variable step to store the overwritten value so it can be re-written into the child index.