Question: We wish to implement a data structure D that maintains the k smallest elements of an array A. The data structure should allow the following

We wish to implement a data structure D that maintains the k smallest elements of an array A. The data structure should allow the following procedures: . D -INITIALIZE(A, n, k) that initializes D for a given array A of n elem ents. TRAVERSE(D), that returns the k smallest elements of A in sorted order. PS 4, Page 1 . INSERT(D,x), that updates D when an element r is inserted in the array A We can implement D using one of the following data structures: (i) an unsorted array of size k; (ii) a sorted array of size k; (iii) a max-heap of size k. (a) (4 points) For each of the choices (i)-(iii), show that the INITIALIZE procedure can be per- formed in time O(nklogn procedure you can think of. (In particular, tell your procedure.) procedure you can think of. (In particular, tell your procedure.) b) (3 points) For each of the choices)ii), compute the best running time for the TRAVERSE c (5 points) For each of the choices (i)-(ii), compute the best running time for the INSERT
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
