In the code for the add method in the implementation of a heap, what is the missing code?
def add(self, item): self.size += 1 self.heap.append(item) curPos = len(self.heap) - 1 while curPos > 0: parent = (curPos - 1) // 2 parentItem = self.heap[parent] if parentItem <= item: else: self.heap[curPos] = self.heap[parent] self.heap[parent] = item curPos = parent

A. curPos += 1
B. break
C. self.heap[curPos] = item
D. parent = curpos


Answer: B

Computer Science & Information Technology

You might also like to view...

You can use __________ to create files under the UNIX/Linux graphical user interface.

a. vi b. text c. Kwrite d. none of the above

Computer Science & Information Technology

Which of the following represents a reading lock of the flock() function?

a. LOCK_SH b. LOCK_EX c. LOCK_UN d. LOCK_NB

Computer Science & Information Technology

________ is determined according to evenness or oddness of a sum of bits.

a) ECC b) XOR c) Parity d) None of the above

Computer Science & Information Technology

The simplest form of addressing is __________ addressing.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology