Question: Let's see an application of ( binary ) heap. You are given an array A with n integers, and another integer k , 1 k
Let's see an application of binary heap. You are given an array A with integers, and
another integer The numbers in A are either or a positive integer, and you may
assume that all positive integers are distinct but there could be multiple s You are asked to
design data structures and algorithm to produce an output array Your algorithm should process
the numbers in A one by one: when a positive number is met, you put it to the end of ; if a is
met, you need to remove the th smallest number in You may also assume that, you will never
meet a if the size of the current is smaller than For example, if
and the output should be
Design an algorithm to complete this task and analyze its running time. Your algorithm should run
in time. Hint: consider using two binaryheaps, one maxheap and one minheap; the
maxheap maintains the smallest numbers in and the minheap maintains rest of the numbers.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
