FAQ: Heapsort: Python - Heapify Down III

This community-built FAQ covers the “Heapify Down III” exercise from the lesson “Heapsort: Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

FAQs on the exercise Heapify Down III

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

For the fourth task, the lesson didn’t let me use parallel assignment to do this:

if parent < child:
  self.heap_list[idx] = child
  self.heap_list[larger_child_idx] = parent

I copied the code and then deleted it to pass.

1 Like

Why in description of general shape of method in pseudocode we get the smallest child and compare it with parent?

Blockquote
starting with our first element…
while there’s at least one child present:
get the smallest child’s index
compare the smallest child with our element
if our element is larger, swap with child
set our element index to be the child

In “Instructions” we get larger child and compare it with child and this is has more logic, as for me

2 Likes

I was confused about this myself, so I had a conversation with ChatGPT, which is where I learned that CC likely does it like this to reinforce the concept, because other languages don’t have an elegant tuple unpacking solution like parallel assignment. You have to hard code it like they had you do here. The idea is that you will be able to heapify in any language

It looks like the pseudocode has it backwards. I wonder if CC will fix this.

1 Like

Right. They wrote code to get the largest child but then in the pseudo-code, they mention the smallest child.

1 Like

My understanding is that the pseudo-code needs to be amended as in bold below.

starting with our first element…
while there’s at least one child present:
get the largest child’s index
compare the largest child with our element
if our element is smaller swap with child
set our element index to be the child