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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python please 

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
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. 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
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of trees
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education