0 X
Insert X in the heap.
1
Print the minimum element from the heap and remove it.
The first line will contain the integer 'T', denoting the number of test cases.
For each test case, the first line will contain a single integer 'N', the number of queries.
Then, each of the next ‘N’ lines contains two types of query either 0 ‘X’ or 1.
For each test case, output the answer for query of type 1.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10^5
1 <= X <= 50
Time Limit: 1 sec
The heap property is satisfied by the heap data structure. And follows the properties of a complete binary tree. Heap property is as follows, which we have used all over the approach:-
The complete binary tree, as we all know, is a tree with every level filled and all nodes as far left as feasible. It's possible that the last level of the binary tree is empty and unfilled.
Every node of the tree is given a key value or weight in the heap data structure.
Now, the key value of the root node is compared with the values of children's nodes, and then the tree is arranged into two categories, respectively i.e., max Heap or min-heap. This data structure is used as a sorting algorithm to sort the elements in a list and an array. This sorting algorithm can be used in data structures like order statistics, priority queues, Dijkstra's algorithm, or Prim's algo. Heapify refers to creating a heap data structure using a binary tree. To create the Min-Heap, the heapify process is used. For complete binary tree the left child in an array is 2*i+1 and the right child is 2*i+2 if the current node index is ‘i’ in the array. For the index ‘i’ the parent of it is (i-1)/2.
Now to create min-heap following steps are used:-
left ( k )