Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CSCA48 Week 6: Worksheet Before you answer the questions, draw a heap tree with the given numbers below in order that they arrive from left
CSCA48 Week 6: Worksheet Before you answer the questions, draw a heap tree with the given numbers below in order that they arrive from left to right. When you finished inserting the nodes, travers it using BFS and compare your result with the person next to you to make sure both of you got it right 10, 5, 25, 3, 16, 8, 9, 4 Now, remove a node from the heap 4 times. You probably know that when you remove a node, you remove it from the root of the tree. Now again traverse the tree using BFS and compare the result with the person next to you. If you got it right start answering the following questions Question 1: At the lecture, you saw how a heap is implemented using a list ADT. With this implementation, finding the last node was not a challenge. Now, assume that we have implemented the Heap ADT using a binary tree. i.e class Heap (BTree): '''This class implements the Heap ADT''' def-init-(self, root-data): ' ' "(Heap, BTNode) > NoneType constructs a heap by creating its root and last node'' BTree. init (self, root data) self._last_node -BTree.get_root (self) Every time that you decide to insert a node, first you should find the position of the new last node. Write an algorithm that takes in the pointer to the current last node and returns the pointer to the parent of the new last node, and a constant Lor R to show which child (i.e. left or right) the new last node will be def find lastnode on insert (self): ''' (Heap) -> (BTNode, str) Returns the pointer to the new last node and L in case the new last node is the left child or R in case it is the right child of its parent.''' Hint: All BTree and BTNode methods such as get_root (), is_left ), is_right ), get_parent ), get_left ), get_right ), get_root, etc are available in order to solve this
Step 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