Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using PYTHON & Heap Using Python & heap Lab Exercise: 1. Class Node that includes the following instance variables: Node data Node name Your class
Using PYTHON & Heap
Using Python & heap
Lab Exercise: 1. Class Node that includes the following instance variables: Node data Node name Your class should have the following: A constructor that initializes the instance variables. Setter and getter methods for the instance variables. data name 2. Class MaxHeap that includes the instance variables: heaplist + Heap List currentSize + number of Nodes in heapArray Your class should have the following: constructor that set the current size of the heap to and creates the heap list isempty) checks whether the heap is empty or not. insert (key, name) inserts a value at the end of the heap then calls method reheapup to apply the actual changes to the heap. reheapup (index) applies the actual changes to the heap after insertion. Make sure that a child node is always less than its parent. It starts at the end of the heap and moves up. remove() removes and returns the first node (root) from the heap. It calls method reheapDown to apply the actual changes to the heap for removal. The method returns None if the heap is empty. reheapDown (index) applies the actual changes to the heap after remove. Make sure that a parent node is always greater than its children. It starts at the end of the root of the heap and moves down. printHeap () prints the contents of the heap as shown in the sample output. Write the expected time and space complexity as a comment at the beginning of each method of your class. 3. Write a test program named Lab Test. Do the following: Create a heap object Display a menu to the user asking for a choice to be entered as follows: Please, choose a number from the following list: 1- Insert Node 2- Remove a Node 3. Check if Empty 4- Print Heap 5- Exit Your choice is: The program will perform the action selected by the user and display a proper message when necessary. The program will repeat these actions until the user terminates the program (Hint: Use a loop). Sample Output Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3- Check ir Empty 4 - Print Heap Your choice is: 2 The Heap is Empty! Please choose a number from the following list: 1- Insert Node 2 - Remove a Node 3. Check it Empty 4. Print Heap 5 - Exit Your choice is: 3 The Heapis Empty Please choose a number from the following list: 1- Insert Node 2 - Remove Node 3. Check it Empty 4 - Print Heap Your choice is: 4 The Heap is not Empty! Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Hesp 5 - Exit Your choice is: 1 Enter the node's details or -1 or stop Enter a node's Key: 10 Enter a name: Mona Enter a node's Key: 6 Enter a name: Dell Enter a node's Key: 15 Enter a name: Ali Enter a node's Key 12 Enter a name: Dans Enter a node's Key: 13 Enter a name: Khaled Enter anode's Key: 8 Enter a name: Salem Enter a node's Key: 17 Enter a name: Mohammad Enter a node's Key: 16 Enter a name: Huda Enter a node's Key: 5 Enter a name: Reem Enter a node's Key: 7 Enter a name: Nasser Enter a node's Key: -1 Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3. Check if Empty 4. Print Hesp 3 - Exit Your choice is: 4 [0]= 17 : Mohammad [1] = 16 : Huda [2] 15 : All [31= 13 : Khaled [4] = 12: Dans [31= 8 : Salem [6] = 10 : Mona [7] = 6: Dalai [8] = 3 : Reem [91= 7: Nasser Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Heap 5 - Exit Your choice is: 3 The Heap is not Empty! Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Heap 5 - Exit Your choice is: 2 (17. Mohammad) was removed from the heap. Plesse, choose a number from the following list: 1- Insert Node 2 - Remove a Node 3. Check if Empty 4 - Print Heap 5 - Exit Your choice is: 2 (16 , Huda] was removed from the heap. Please choose a number from the following list: 1- Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Hesp 3 - Exit Your choice is: 2 (15. Ali) was removed from the heap. Please choose a number from the following list: 1- Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Heap 5 - Exit Your choice is: 2 (13, Khaled was removed from the heap. Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Heap 3- Exit Your choice is: 2 (12, Dana) was removed from the heap. Please choose a number from the following list: 1- Insert Node 2 - Remove a Node 3. Check if Empty 4 - Print Heap 5 - Exit Your choice is: 2 (10. Mona was removed from the heap. Please choose a number from the following list: 1- Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Hesp 9 - Exit Your choice is: 2 (s. Salem was removed from the heap Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Hesp Your choice is: 2 17, Nasser was removed from the heap. Please choose a number from the following list: 1- Insert Node 2 - Remove a Node 3. Check it Empty 4 - Print Heap 9 - Exit Your choice is: 2 (5. Dis was removed from the heap. Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3. Check if Empty 4 - Print Hesp 5- Exit Your choice is: 2 (5, Reem was removed from the heap Please choose a number from the following list: 1. Insert Node 2 - Remove a Node 3. Check if Empty 4 - Print Heap 9. Exit Your choice is: 2 The Heapis Empty Please choose a number from the following list: 1- Insert Node 2 - Remove a Node 3 - Check it Empty 4 - Print Heap 5 - Exit Your choice is: 3 Exiting the program Process finished with exit code 0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started