Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions