2)A heap is a binary tree. What operations does a heap add to the BinaryTree interface?
3) When does a 2-node become a 3-node?
4) Is every tree a graph? Is every graph a tree? Explain
2. A heap can be called a Binary Tree which satisfies the heap ordering properties.
We can insert new items at the end of the tree. If the new items are greater than its parent, then we need not to do anything. Otherwise, we need to traverse through the parent to fix the violated heap property.
3. In case of a two node tree, it has one data element and it should have two child nodes. But in case of 3 nodes, it should have two data elements and should have three child nodes.
So, when we insert new key at the lowest internal nodes, then it becomes a 2-3 tree. Thus a B-tree of order 3 is termed as a 2-3 tree. Nodes on the outside of that tree should not have any children and one or two data elements.
4. Yes, every tree is a graph but every graph is not a tree.
Let maximum number of edges present in a graph:
E(G) = n(n-1)/2; where G represents graph
And the max no. of edges in a tree:
E(T) = (n-1); where T is the tree
By comparing the above equations, we can convey that Every tree is a graph but every graph is not a tree. Moreover, graph can have cycles and loops and can have many paths to the vertices. But in case of tree the vertices should have one path connecting between them.
2)A heap is a binary tree. What operations does a heap add to the BinaryTree interface?...
Trees-related questionsBeginning with an empty binary search tree, what binary search tree is formed when you add the following letters in the order given? J, N, B, A, W, E, TRepresent the following binary tree with an array What is the result of adding 3 and 4 to the 2-3 tree shown below?Why does a node in a red-black tree require less memory than a node in a 2-3-4 tree?Why can’t a Red-Black Tree have a black child node with exactly...
In the lectures, we studied binary heaps. A min-Heap can be visualized as a binary tree of height with each node having at most two children with the property that value of a node is at most the value of its children. Such heap containing n elements can be represented (stored) as an array with the property Suppose that you would like to construct a & min Heap: each node has at most& children and the value of a node...
What is the difference between the binary-search-tree property and the min-heap property (see page 129)? Can the min-heap property be used to print out the keys of an n-node tree in sorted order in O(n) time? Explain how or why not.
A heap can be encoded either as an array, or as a full binary tree. For this question, write a function that takes the array representation of a heap and outputs its binary tree representation. More specifically, you should write a function with the specifications given below. Specifications for the function: # def arrayToTree(A, j): # input: array A representing a heap, an index j in [0:len(A)] # output: a Node object storing the heap with root j in the...
Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of height h is 2h+1 − 1. 2. A full node is a node with two children. Prove that the number of full nodes plus one is equal to the number of leaves in a nonempty binary tree. 3. What is the minimum number of nodes in an AVL tree of height 15? 4. Show the result of inserting 14, 12, 18, 20, 27, 16,...
Draw the Binary Tree that is constructed by calling the following methods. BinaryTree T1; T1.addRoot(5); addLeft(T1.root(), 10); addRight(T1.root(), 15); BinaryTree T2; T2.addRoot(20); addLeft(T2.root(), 18); addRight(T2.root(), 26); BinaryTree T; T.addRoot(8); attach(T.root, T1, T2); Upload an image showing the tree diagram or show it as following, make sure your result is clear enough to tell the left child or right child or parent node relation. Details regarding the used method can be found under content->others->binary tree code->linkedBinaryTree 1 2 3 5
3. (8 points) Using the implementation of binary search tree operations we discussed in class, draw the trees that result from the following operations: (a) Inserting 142, 400, 205, 127, 100, 320, 160, 141, and 110 into an initially-empty tree (in that order). (b) Deleting 142 from the tree you drew for part (a). 4. (8 points) Draw the unique binary tree that has a preorder traversal of 4, 1, 6, 3, 7, 5, 9, 2, 8 and an inorder...
Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers keys in post-order - Retrieve the integers keys in pre-order - Draw a binary search tree after node 58 is deleted b) Create a Hash Table using the methods described below. Show the final array after all integer keys are inserted. Assumes that...
JAVA (Heap operations) A. Add a node with value 3 to the following min heap. Show the upheap swap process needed to restore the heap-order property. You will need at least three diagrams. B. Remove the root node from the following heap. You will need to downheap swap to restore the heap-order property. Use diagrams to show the state of the heap at each step. You will need at least three diagrams.
C++ Binary Search trees Depth first traversal is the same as _____ order traversal. When we add a new node to an existing binary search tree, it will always become a ______. When we delete a node with 2 children from a binary search tree, we replace the node with ______.