1.) The minimum of no.of elements in a tree is 2h where h is the height of the tree.
This can be seen with an example. If only root node exits in tree , h=0, and it is true.
When h=1, root and one more element at the deepest level, i.e., 21=2.
2.) The word successor means 'a person who comes just after the current holder', and thus a node that comes after the node 'y' will be
(a) greater than 'y',
(b) thus it will reside in right subtree of 'y';
Now, the first 2 options in question are wrong as they conflict with (a) statement given above and third is also wrong as if it resides in the rightmost node on the right subtree of 'y' it will not be the immediate node after 'y', it should be the leftmost node in the right subtree.
4th option is correct as if 'y' will not have a right subtree then the successor will be the lowest ancestor of 'y' and 'y' will reside in left subtree of it's successor.
3.) Similarly, the word predecessor means 'a person who comes just before the current holder', and thus a node that comes before the node 'x' will be
(a) smaller than 'x',
(b) thus it will reside in left subtree of 'x';
Now, the 2nd and 4th option in question are wrong as they conflict with (a) statement given above and first option is also wrong as if predecessor is the leftmost node on the left subtree of 'x' it will not be the immediate node before 'x', it should be the rightmost node in the left subtree.
3rd option is correct as if 'x' will not have a left subtree then the predecessor will be the lowest ancestor of 'x' and 'x' will reside in right subtree of it's predecessor.
ich of the following describes the minimum amount of elements in a heap if *?the deepest...
Think about the DELETE(x) operation for a Binary Search Tree with no duplicate elements. Define the predecessor of a node x as the node whose value immediately precedes x if you sort all the node values in the tree smallest to largest. Define the successor of a node x similarly -- the one "just after" x. If x has a left child, is the predecessor of x always in x's left sub-tree? If x has a right child, is the...
Answer the following question(s) concerning implementing recursive functions to perform operations on linked lists of nodes arranged as binary trees. For these questions, use the following struct definition for the nodes of the tree (we will not templatize the node here, so you do not have to write template functions for these questions, just assume trees of <int> values): struct BinaryTreeNode { int item; BinaryTreeNode* left; BinaryTreeNode* right; }; ---------------------------------------------- Given a node for a Binary Tree and an (integer)...
Can someone help with these two problems?
The following binary tree contains the characters 'A' through 'G' in its nodes. List the nodes in the order that they are visited by: A preorder traversal. An inorder traversal. A postorder traversal. The binary tree in Problem 2 is a Binary Search Tree since for every node, all elements stored in the left subtree of the node are smaller than the element in the node and all elements stored in the right...
Hello, I need help implementing the c++ code for successor and
predecessor of a BST following the pseudocode below, thank you for
your help in advance.
struct treeNode
{
int data;
treeNode *left;
treeNode *right;
};
treeNode* FindMin(treeNode *node) /* find the minumum node
*/
{
while (node->left != NULL)
{
node = node->left;
}
return node;
}
treeNode* FindMax(treeNode *node) /* find the maximum node
*/
{
while (node->left != NULL)
{
node = node->right;
}
return node;
}...
C++
Question 5 5 pts In a min-heap of N elements, if we want to find the max element, we have to search all the leaves. What is the big-o running time of findMax? O(N^2) Oſlog N) O(N) OIN log N) Question 6 5 pts An AVL tree is a Binary Search Tree that has the following additional property for every node in the tree, the height of the left and right subtrees is the same none of the above...
Scenario We need to write a method that, given a key as an argument, returns the next in order key found in the binary search tree. If the key given as an argument is not found, the method should still return the next in order key. If the binary tree is empty or all the stored keys are smaller than the argument, then the return value should be empty. For example, using a collection of {10,13,52,67,68,83} stored in the binary...
Binary Search Tree Part A: The code attached in this document is a sample code to demonstrate insert operation in binary search tree. Please fill in the missing part for the insert method to make the program work. The expected output should be as follows. 20 30 40 50 60 70 80 Part B: Find Lowest Common Ancestor (LCA) of a Binary Search Tree. According to WikiPedia definition , The lowest common ancestor is defined between two nodes v and...
C++, data structure using :binarySearchTree Deleting an element from a binary search tree is far more complicated than inserting an element in a binary search tree. An analysis of binary search tree deletion finds 4 cases: Case 1: The node to be deleted has no left and right subtrees Case 2: The node to be deleted has no left subtree but does have a right subtree. Case 3: The node to be deleted has no right subtee but does have...
Recall that in a binary search tree, at every node, all elements to the left of the node have a smaller key, and all elements to the right of a node have a larger key. Write a program called that takes two parameters: a pointer to a binary search tree node, and an int parameter called min which will print all the elements bigger than the specified value, min. Your program should allow the user to enter data (integer) from...
A Binary Search Tree is a binary tree where nodes are ordered in the following way: each node contains one key (also known as data) the keys in the left subtree are less than the key in its parent node the keys in the right subtree are greater than the key in its parent node duplicate keys are not allowed Create a Binary Search Tree inserting the following list of numbers in order from left to right. 10, 6, 4, 8, 18, 15, 21 Please type...