Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  What is the time complexity of Build Heap ope... Start Learning for Free
What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.
  • a)
    O(nLogn)
  • b)
    O(n^2)
  • c)
    O(Logn)
  • d)
    O(n)
Correct answer is option 'D'. Can you explain this answer?
Verified Answer
What is the time complexity of Build Heap operation. Build Heap is use...
Following is algorithm for building a Heap of an input array A.
BUILD-HEAP(A)
         heapsize := size(A);
         for i := floor(heapsize/2) downto 1
              do HEAPIFY(A, i);
         end for
END
Although the worst case complexity looks like O(nLogn), upper bound of time complexity is O(n).
View all questions of this test
Most Upvoted Answer
What is the time complexity of Build Heap operation. Build Heap is use...
Explanation:

Build Heap operation is used to build a max or min binary heap from a given array. The time complexity of this operation is O(n), where n is the number of elements in the array.

1. Building a binary tree from an array:
- The first step in building a binary heap from an array is to create a binary tree from the array.
- This step requires visiting each element in the array once and adding it to the binary tree.
- The time complexity of this step is O(n).

2. Heapifying the binary tree:
- Once the binary tree is created, the next step is to heapify it.
- Heapifying a binary tree involves ensuring that the root node of each subtree is the maximum(or minimum) value within that subtree.
- This step requires visiting each node in the binary tree once and swapping values to ensure that the heap property is maintained.
- The time complexity of this step is O(n).

3. Conclusion:
- The time complexity of building a max(or min) binary heap from an array is the sum of the time complexities of the two steps above.
- Therefore, the time complexity of build heap operation is O(n).

Therefore, the correct answer is option 'D', O(n).
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Question Description
What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer?.
Solutions for What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer?, a detailed solution for What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.a)O(nLogn)b)O(n^2)c)O(Logn)d)O(n)Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev