getMin(self) needs to return the minimum value in the heap  _parent(self, index) it needs to return value of the parent of the element at the specific index _leftChild(self, index) and _right Child(self,index) return value of the left/right child of the element at the specific index insert(self, item) needs to insert an item into the heap while maintaining the minimum heap property. It must use the _parent method.  deleteMin(self) it needs to remove the minimum element of the heap and returns the value of the element that was just removed. The special cases where the heap is empty or contains only one element has been implemented for you already, your task is to implement the general case. According to the minimum heap property, the minimum element is the root node. When percolating down, if both children have the same value, swap with the left child. It must use the _leftChild and _rightChild methods.  heapSort(numList) It takes a list of numbers and uses the heap sort algorithm to return a list with the elements of numList sorted in ascending order. It does not modify the original list. Not allowed to use the sorted() method or the sort operator. It should use an instance of the MinBinaryHeap class to complete the sorting process. Starter Code

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

getMin(self) needs to return the minimum value in the heap

 _parent(self, index) it needs to return value of the parent of the element at the specific index

_leftChild(self, index) and _right Child(self,index) return value of the left/right child of the element at the specific index

insert(self, item) needs to insert an item into the heap while maintaining the minimum heap property. It must use the _parent method. 

deleteMin(self) it needs to remove the minimum element of the heap and returns the value of the element that was just removed. The special cases where the heap is empty or contains only one element has been implemented for you already, your task is to implement the general case. According to the minimum heap property, the minimum element is the root node. When percolating down, if both children have the same value, swap with the left child. It must use the _leftChild and _rightChild methods. 

heapSort(numList) It takes a list of numbers and uses the heap sort algorithm to return a list with the elements of numList sorted in ascending order. It does not modify the original list. Not allowed to use the sorted() method or the sort operator. It should use an instance of the MinBinaryHeap class to complete the sorting process.

Starter Code


class MinBinaryHeap:


    def __init__(self):   
        self._heap=[]
        
    def __str__(self):
        return f'{self._heap}'

    __repr__=__str__

    def __len__(self):
        return len(self._heap)

    @property
    def getMin(self):
        # YOUR CODE STARTS HERE
        pass
    
    
    def _parent(self,index):
        # YOUR CODE STARTS HERE
        pass

    def _leftChild(self,index):
        # YOUR CODE STARTS HERE
        pass


    def _rightChild(self,index):
        # YOUR CODE STARTS HERE
        pass


    def insert(self,item):
        # YOUR CODE STARTS HERE
        pass

    def deleteMin(self):
        # Remove from an empty heap or a heap of size 1
        if len(self)==0:
            return None        
        elif len(self)==1:
            deleted=self._heap[0]
            self._heap=[]
            return deleted
        else:
            # YOUR CODE STARTS HERE
            pass

 

     def heapSort(numList):
      '''
       >>> heapSort([9,1,7,4,1,2,4,8,7,0,-1,0])
       [-1, 0, 0, 1, 1, 2, 4, 4, 7, 7, 8, 9]
       >>> heapSort([-15, 1, 0, -15, -15, 8 , 4, 3.1, 2, 5])
       [-15, -15, -15, 0, 1, 2, 3.1, 4, 5, 8]
      '''
    # YOUR CODE STARTS HERE

The image is for a note.

It is a minimum binary heap. Main goal is to implement a minimum binary using a python list. Please help with the bold codes. All the not bold parts shouldn't be modified. Only the bold parts should be modified. Please help me with not adding the other methods(def) to the code, it needs to work only by modifying the code provided above... Also, I haven't learned the (pos) function in python, so can you help me without using that function? Not allowed to use index() method as well.

Expected output

>>> h = MinBinaryHeap()
        >>> h.insert(10)
        >>> h.insert(5)
        >>> h
        [5, 10]
        >>> h.insert(14)
        >>> h._heap
        [5, 10, 14]
        >>> h.insert(9)
        >>> h
        [5, 9, 14, 10]
        >>> h.insert(2)
        >>> h
        [2, 5, 14, 10, 9]
        >>> h.insert(11)
        >>> h
        [2, 5, 11, 10, 9, 14]
        >>> h.insert(14)
        >>> h
        [2, 5, 11, 10, 9, 14, 14]
        >>> h.insert(20)
        >>> h
        [2, 5, 11, 10, 9, 14, 14, 20]
        >>> h.insert(20)
        >>> h
        [2, 5, 11, 10, 9, 14, 14, 20, 20]
        >>> h.getMin
        2
        >>> h._leftChild(1)
        5
        >>> h._rightChild(1)
        11
        >>> h._parent(1)
        >>> h._parent(6)
        11
        >>> h._leftChild(6)
        >>> h._rightChild(9)
        >>> h.deleteMin()
        2
        >>> h._heap
        [5, 9, 11, 10, 20, 14, 14, 20]
        >>> h.deleteMin()
        5
        >>> h
        [9, 10, 11, 20, 20, 14, 14]
        >>> len(h)
        7
        >>> h.getMin
        9
    '''

Heap index: 1
Python List Index: 0
Heap index: 2
Python List Index: 1
Неаp index 3
Python List Index: 2
14
11
Heap index: 4
Python List Index: 3
54
MinBinaryHeap ()
[5, 14, 11, 54]
>>> x =
>>> x._heap
# force load a minimum heap
>>> x._parent(4) # Heap index 4 (value: 54) has a parent at index
# 4//2 =2, which is list index 1 (x._heap[1])
# Heap index 2 (value: 14) has a left child at index
# 2 * 2 = 4, which is list index 3 (x._heap[3])
14
·_leftChild(2)
54
>>> x._rightChild(1) # Heap index 1 (value: 5) has a right child at index
3, which is list index 2 (x._heap[2])
11
# 2 * 1 + 1 =
Transcribed Image Text:Heap index: 1 Python List Index: 0 Heap index: 2 Python List Index: 1 Неаp index 3 Python List Index: 2 14 11 Heap index: 4 Python List Index: 3 54 MinBinaryHeap () [5, 14, 11, 54] >>> x = >>> x._heap # force load a minimum heap >>> x._parent(4) # Heap index 4 (value: 54) has a parent at index # 4//2 =2, which is list index 1 (x._heap[1]) # Heap index 2 (value: 14) has a left child at index # 2 * 2 = 4, which is list index 3 (x._heap[3]) 14 ·_leftChild(2) 54 >>> x._rightChild(1) # Heap index 1 (value: 5) has a right child at index 3, which is list index 2 (x._heap[2]) 11 # 2 * 1 + 1 =
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Stack
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
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