Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:51:23+00:00 2026-06-07T16:51:23+00:00

In a max heap (assuming it’s represented by an array), the top of the

  • 0

In a max heap (assuming it’s represented by an array), the top of the heap (ie. the largest value in the heap) swaps with the last element in the array (ie. one of the smallest values in the heap), the last element is removed, and then the new top-of-the-heap element swaps with other values to settle back into its proper place.

Instead, why isn’t the top element just removed and then other elements can “fill in” for the the heap?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:51:24+00:00Added an answer on June 7, 2026 at 4:51 pm

    One of the key properties of a heap is that the underlying binary tree is a complete binary tree (i.e. every level except the last one has to be completely “filled”). This is so that the heap has O(lg N) operations because we only have to modify one element at each of the O(lg N) levels. Let’s take a look at an example

        10
       /  \
      8    7
     / \  / \
    5  6  4  3
    

    If we follow your method and “fill in” the heap we get

         8
       /   \
      6     7
     / \   / \
    5  ?   4  3
    

    The tree is no longer a complete binary tree as there is a “hole” at the ?. Since we don’t know that the tree is complete, we don’t know anything about the height of the tree and so we can’t guarantee O(lg N) operations.

    This is why we take the last element in the heap, put it on top and then shuffle it down – to maintain the complete binary tree property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a binary max heap (largest element at the top), and I need
What i usually do concerning the jvm heap size is setting the max value
The JVM -Xmx argument lets one set the max heap size for the JVM
I know how to sort-in-place an array using heapsort and max-heap property. But I
I've read the max heap size on 32bit Windows is ~1.5GB which is due
I know you can set max heap size at startup using -Xmx but is
I have set my java min/max heap size to be the same as outlined
SELECT MAX(some_field) FROM table_A GROUP BY another_field This only gets the max value of
I understand how to delete the root node from a max heap but is
For creating a Min heap or a Max Heap of n elements, time taken

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.