Log in from a computer to take this course

You'll need to log in from a computer to start Learn Data Structures and Algorithms with Python. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store

Great job reaching the end of this lesson and implementing a heapsort algorithm in Python.

Let’s go over what we learned about heapsort:

  • A heapsort algorithm uses the heap data structure to organize data.
  • The first step to implement heapsort is to place the data inside a heap.
  • While the heap has more than one element, extract the largest value in the heap by swapping it with the right-most child and then removing it.
  • After we swap the root value and the last value, we must restructure the heap until every parent has a larger value than their children again.


Take a look at the completed code. Feel free to edit the program to get a better understanding of heaps and heapsort.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?