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
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
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7ab8ad85-4431-4322-a2b3-dfe25d764408%2F23dede70-5346-4a84-b6f6-5b294b446d5f%2F0ndb5r_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning