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

  • Home
  • SEARCH
  • 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 7978899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:37:04+00:00 2026-06-04T09:37:04+00:00

For creating a Min heap or a Max Heap of n elements, time taken

  • 0

For creating a Min heap or a Max Heap of n elements, time taken would be O(nlogn) for creating a heap. Because, every insertion takes O(logn) time and hence n elements would take O(nlogn) time

But in many places it is written that the creation of a heap can be optimized to O(n) time i.e. a linear time?But it is not clearly explained how?

  • 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-04T09:37:05+00:00Added an answer on June 4, 2026 at 9:37 am

    The optimal method doesn’t need logn time for inserting a node.

    The optimal method starts by arbitrarily putting the elements on a
    binary tree, respecting the shape property (as the tree could be
    represented by an array). Then starting from the lowest level and
    moving upwards, shift the root of each subtree downward as in the
    deletion algorithm until the heap property is restored. More
    specifically if all the subtrees starting at some height h (measured
    from the bottom) have already been “heapified”, the trees at height
    h+1 can be heapified by sending their root down along the path of
    maximum valued children when building a max-heap, or minimum valued
    children when building a min-heap. This process takes O(h) swap
    operations per node. In this method most of the heapification takes
    place in the lower levels. Since the height of the heap is logn ,
    the number of nodes at height is h. Therefore, the cost of
    heapifying all subtrees is:

    h=0∑logn n/2h+1 = O(n *
    h=0∑lognh/2h ) which is less than

    O(n * h=0∑∞h/2h )

    since h / 2h converges to 2 as it is an infinite series
    

    it is equal to O(n)

    Source: http://en.wikipedia.org/wiki/Binary_heap#Building_a_heap

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

Sidebar

Related Questions

I'm creating a fluid website design and am specifying min-width and max-width values, however,
When creating new annotation public @interface Invariant { String min(); String max(); String Default();
I have a form where i enter min price and max price when creating
I am creating an android app myself (min sdk version 7 or 2.1 and
I am creating a simple splash page with the following sequence: Fade in elements
I am creating a plot with names on x axis and time values(minutes) on
Possible Duplicate: jquery-min version? These two files are already included while creating a new
When creating lots of DOM elements, document.createElement and friends can add lots of bytes
I'm in the process of creating a coverflow view for android, but I'm running
I'm in the process of creating a metasearch engine and I'm stuck! Using php

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.