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. 19 22 5 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 7 6 13 8 22 8 19 4 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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 21SA
icon
Related questions
Question

Python code

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.
19
22
57
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
8
6
3
13 822 8 19
4
$
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, 191, 9)) None
Transcribed Image Text: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. 19 22 57 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 8 6 3 13 822 8 19 4 $ 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, 191, 9)) None
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Quicksort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning