Page 1 of 1

A binary heap is a complete binary tree which satisfies the heap ordering property. The diagram below illustrates how we

Posted: Thu Jun 02, 2022 7:37 am
by answerhappygod
A Binary Heap Is A Complete Binary Tree Which Satisfies The Heap Ordering Property The Diagram Below Illustrates How We 1
A Binary Heap Is A Complete Binary Tree Which Satisfies The Heap Ordering Property The Diagram Below Illustrates How We 1 (150.46 KiB) Viewed 13 times
PYTHON PLZ
A binary heap is a complete binary tree which satisfies the heap ordering property. The diagram below illustrates how we would think of the binary min-heap (like a tree). Additionally, the diagram shows the actual Python list which stores the values. The root is stored at index 1 For a node at index position p: left child at index 2p • • right child at index 2p+1 13 19 5 7 6 13 8 22 8 19 0 2 3 4 5 6 7 B Define a function called get_sibling (a_list, index) which takes a binary min-heap represented by a Python list and an integer as parameters. The function should return the value of the sibling of the element specified by the parameter index. The function should return None if the index is not in the valid range. Note: you can assume that the parameter list is not empty. For example: Test Result print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 1)) None print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 4)) 8 print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 8)) None print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 9)) None