Question: Write a Python function findChildren that takes as input a list heapList, representing a heap, and a positive integer position. Your function should return False

Write a Python function findChildren that takes as input a list heapList, representing a heap, and a positive integer position.

Your function should return False if the item at position position in heapList has no children, or if position is not a valid position in the heap, otherwise your function should print the item at position and its children, and then return True.

For example: If heapList = [8, 4, 7, 2, 3, 1] and position = 0, then the function returns True and prints: Parent: 8 Left Child: 4 Right Child: 7

For example: If heapList = [8, 4, 7, 2, 3, 1] and position = 2, then the function returns True and prints: Parent: 7 Left Child: 1 For example: If heapList = [8, 4, 7, 2, 3, 1] and position = 3, then the function returns False.

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!