DSA
    intermediate

    Heap (Priority Queue)

    Heap (Max-Heap)

    O(log n)
    Ready

    Max-Heap Structure

    Ready to perform heap operations

    Empty Heap
    Root
    Active
    Parent
    Child
    Normal
    Size
    0
    Root
    null
    Height
    0
    Type
    MAX

    What does it cost?

    Sort

    Sort each binary-heap operation by its time complexity.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    O(1)

    Drop items here

    O(log n)

    Drop items here

    O(n)

    Drop items here
    6 pieces left to place

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

    Where is the maximum element always located in a Max Heap?

    The short version

    Think of an emergency room triage. Patients are not treated in order of arrival (FIFO), but by severity. The most critical case (highest priority) is always handled next, regardless of wait time.

    In more depth

    The Priority Struct

    A Heap is a specialized Tree-based data structure that satisfies the Heap Property. It is the most efficient way to repeatedly access the Highest or Lowest priority element.

    Array Representation:

    Heaps are typically implemented as arrays!

    Left Child: 2*i + 1
    Right Child: 2*i + 2
    Parent: floor((i-1)/2)

    When to reach for this

    • Find the **Top K** elements
    • Find the **Median** of a stream
    • Schedule tasks by Priority

    Interview Questions

    Facebook
    Amazon
    LinkedIn
    Google
    Uber
    Apple
    Microsoft
    Bloomberg
    Facebook
    Amazon
    Airbnb
    Microsoft

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required