Question: def transform (self, f) which takes as input a function f that takes as input an integer and returns an integer. The function transform applies

 def transform (self, f) which takes as input a function f

def transform (self, f) which takes as input a function f that takes as input an integer and returns an integer. The function transform applies f to all elements of the heap (the one represented by self) and re-arranges the resulting elements so that self remains a heap. For example, if the heap h is represented as [52,50,42,12,6,9,5,1,4,6,5,8] and foo is the function that on input n returns n%10 (i.e. the remainder of division by 10), then h.transform(foo) can change h to the heap [9,6,8,2,5,6,5,1,2,0,4,2]. Note that the resulting heap is not uniquely specified, i.e. there are more than one ways to arrange the resulting elements to a heap (it does not matter which one you choose). [5 marks]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!