Write pseudocode for a binary min-heap that lets you add integer values and fetch the smallest value. Here, fetching removes the value from the heap.
MinHeap()
void add(int value)
value into the heap.int fetchFirst()
List<Integer> to store the binary heap. Each parent's value must be no greater than its children's values.O(log n) amortized time per operation and O(n) space, where n is the heap size.-1,000,000,000 ≤ value ≤ 1,000,000,000100,000 total calls to add and fetchFirst.Calls run in order on the same heap within each example.
MinHeap() creates an empty heap.add(value = 14) returns no value.add(value = 6) returns no value.add(value = 10) returns no value.fetchFirst() returns 6.add(value = 3) returns no value.fetchFirst() returns 3.fetchFirst() returns 10.fetchFirst() returns 14.MinHeap() creates an empty heap.add(value = -5) returns no value.add(value = -5) returns no value.add(value = 0) returns no value.fetchFirst() returns -5.fetchFirst() returns -5.fetchFirst() returns 0.Both copies of -5 are removed before 0.