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 7608289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:52:38+00:00 2026-05-31T00:52:38+00:00

What is the difference between Percolate-down/Shift-down and Heapify operation? This is my Shift-down function

  • 0

What is the difference between Percolate-down/Shift-down and Heapify operation?

This is my Shift-down function in C. And, I have already implemented Heapsort using this code.

void IterativeShiftDown(int i)
{   
    int leftOrRightChildIndex = EMPTY;
    int currentIndex = i;
    int currentElement = EMPTY;
    int childElement = EMPTY;

    while(HasAnyChild(currentIndex))
    {
        if(HasBothChild(currentIndex))
        {
            if(GetLeftChildElement(currentIndex) > GetRightChildElement(currentIndex))
            {
                leftOrRightChildIndex = GetLeftChildIndex(currentIndex);
            }
            else
            {
                leftOrRightChildIndex = GetRightChildIndex(currentIndex);
            }
        }
        else if(HasLeftChild(currentIndex))
        {
            leftOrRightChildIndex = GetLeftChildIndex(currentIndex);
        }

        currentElement = GetElement(currentIndex);
        childElement = GetElement(leftOrRightChildIndex);

        if(currentElement < childElement)
        {
            SwapElements(currentIndex, leftOrRightChildIndex);
        }

        currentIndex = leftOrRightChildIndex;
    }
}

Can I create a Heapify() – function using this code?

If yes, how?

Moreover, what is the algorithm to implement Heapsort using Heapify?

  • 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-05-31T00:52:40+00:00Added an answer on May 31, 2026 at 12:52 am

    Shift down is typically an operation performed to insert an item into an existing heap.

    heapify is typically an operation to create a heap from unordered data.

    To expand on the function perreal supplied…

    It starts in the middle because of the properties of a heap as implemented in an array. Each child element from index N in a heap is N*2 or N*2+1, so you know the last 1/2 of the elements have no children. Additionally, the children of a node in a heap have a relationship to the parent (consistently larger or smaller or whatever), but no relationship to each other – so the leaf children never need to be swapped.

    So it starts at the middle bubbling/sifting each element down as far as needed.

    There are times when heaps are great. Specifically, if you are receiving the input in a manner where you can do some CPU work for free while retrieving the data (async disk reads/db gets), you can build the heap incrementally almost for free.

    Along those same lines, once you have the data, if you want to populate some UI or can feed back the results in some piecemeal fashion, you have the initial results immediately and with low cost for retrieving each element.

    It’s not the fastest to have sorted data in the world; but it (as far as I’m concerned) the best way to amortize the cost of the sort across the input=>output phases as well as the processing phase of an algorithm. This can frequently be useful.

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

Sidebar

Related Questions

//Difference between 2 dates This function works well but display wrong time format. Pls
I want to know difference between recursive function and using a stack in terms
Any difference between these two statements? $(document).ready(function() { // Code }); $(function() { //
Is there any difference between int on_exit(void (*function)(int , void *), void *arg); and
Difference between Map and Properties as both have key-value pair.
Whats difference between library EXT-JS , EXT-CORE , EXT-GWT as i have worked on
What is difference between the below ThreadPool.QueueUserWorkItem vs Task.Factory.StartNew If the above code is
What is the difference between the code (i) and (ii) written below ? (i)
difference between web services clients results in one error in one success I have
What is the big difference between launching Equinox via java -jar plugins/org.eclipse.osgi_3.6.0.v20100517.jar and using

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.