594 views
2 votes
2 votes

what is the time complexity of various problems such as:

1) Creating the heap

2) Getting maximum element in the max heap

3) Getting minimum element in the max heap

4) Getting maximum element in min heap

5) Getting minimum element in min heap

6) Heapify the element

7)Build heap

8) Deletion of an element in min heap

9) Deletion of an element in the max heap

10) Insertion of an element in the max heap

11) Insertion of an element in min heap

 

 

1 Answer

2 votes
2 votes

1) Creating the heap   - $O(n)$

2) Getting maximum element in the max heap    -  $O(1)$

3) Getting minimum element in the max heap     -  $O(n)$ as the minimum element will be in last level

4) Getting maximum element in min heap     -  $O(n)$ as the maximum element will be in last level

5) Getting minimum element in min heap  - $O(1)$

6) Heapify the element - $O(log(n))$

7)Build heap -  $O(n)$

8) Deletion of an element in min heap - $O(log(n))$ for maintaining min heap property after deletion.

9) Deletion of an element in the max heap - $O(log(n))$

10) Insertion of an element in the max heap - insertion take $O(1)$ but $O(log(n))$ for maintaining max heap property after insertion.

11) Insertion of an element in min heap  - $O(log(n))$

Related questions

1 votes
1 votes
0 answers
1
Anjana Babu asked Jan 10, 2017
1,275 views
Please explain using images how to convert BST into max/min heap in-place .Please explain the complexity of doing so.
0 votes
0 votes
1 answer
2
saurav raghaw asked Dec 22, 2018
686 views
The time complexity of the most efficient algorithm to determine whether an arbitrary array of size ‘n’, is min-heap or not?(A) O(log n)(B) O(n)(C) O(n logn)(D) O(1)
1 votes
1 votes
1 answer
3
gmrishikumar asked Dec 1, 2018
2,295 views
What is the time complexity to find the Kth largest element in a Min-Heap? Or equivalently, What is the time complexity to find Kth smallest element in Max-Heap?