Question

2. A regular binary tree is a binary tree whose internal nodes all have two subtrees (left and right). In other words, all th

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution (a):

depth(n){

if(leaf(n)) return 0;

int leftdepth = depth(node -> left);

int rightdepth = depth(node -> right);

return max(leftdepth, rightdepth) + 1;

}

Solution (b):

For node A:

depth(A) => depth (B) , depth(C)

depth(B) => max(depth (D)=0, depth(E)=0) +1 =1

Thus depth(B) = 1

depth(C) => depth(F)=0, depth(G)

depth(G) => depth(H) , depth(I)=0

depth(H) => max(depth (J)=0, depth(K)=0) +1 =1

Thus depth(H) = 1

Thus depth(G) = 2

Thus depth(C) = 3

Thus depth(A) = 4

Add a comment
Know the answer?
Add Answer to:
2. A regular binary tree is a binary tree whose internal nodes all have two subtrees...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A balanced binary tree is a binary tree structure in which the left and right subtrees of every node differ

    Data structures C++1- A balanced binary tree is a binary tree structure in which the left and right subtrees of every node differ in height by no more than 1 Out of the following choices, which is the minimum set of nodes, if removed, will make the BST balanced?2- Which of the following is true for Red-Black Trees ? Select all choices that apply! Select one or more: a. For each node in the tree, all paths from that node to any leaf nodes contain...

  • (2 points) A full binary tree has a start node, internal nodes, and leaf nodes. The...

    (2 points) A full binary tree has a start node, internal nodes, and leaf nodes. The number of leaf nodes of this binary tree is 256. a) What is the height of the tree? b) How many internal nodes are in this tree?

  • In a binary tree, the balance ratio of node v, bal(v), is the number of nodes...

    In a binary tree, the balance ratio of node v, bal(v), is the number of nodes in the left subtree of node v divided by the sum of the number of nodes in the right and left subtrees of node v. bal(a leaf node) = ½. A tree T is said to be ε-balanced if, for all nodes v in T, ½ - ε < bal(v) < ½ + ε. Design an efficient recursive algorithm that determines whether a binary...

  • Design a recursive algorithm that determines whether the number of leaf nodes of a Binary Search...

    Design a recursive algorithm that determines whether the number of leaf nodes of a Binary Search Tree (BST) is even or odd. An empty tree has an even number of leaves. A tree consisting of just a root has an odd number of leaves. Your function should return true for an even number of leaves, and false for an odd number of leaves. Analyze the execution time of your algorithm. Giving only the execution time without explanation will not be...

  • Design a recursive algorithm that determines whether the number of leaf nodes of a Binary Search...

    Design a recursive algorithm that determines whether the number of leaf nodes of a Binary Search Tree (BST) is even or odd. An empty tree has an even number of leaves. A tree consisting of just a root has an odd number of leaves. Your function should return true for an even number of leaves, and false for an odd number of leaves. Analyze the execution time of your algorithm. Giving only the execution time without explanation will not be...

  • Recall from Assignment 2 the definition of a binary tree data structure: either an empty tree,...

    Recall from Assignment 2 the definition of a binary tree data structure: either an empty tree, or a node with two children that are trees. Let T(n) denote the number of binary trees with n nodes. For example T(3) 5 because there are five binary trees with three nodes: (a) Using the recursive definition of a binary tree structure, or otherwise, derive a recurrence equation for T(n). (8 marks) A full binary tree is a non-empty binary tree where every...

  • A binary tree is a complete binary tree if all the internal nodes (including the root...

    A binary tree is a complete binary tree if all the internal nodes (including the root node) have exactly two child nodes and all the leaf nodes are at level 'h' corresponding to the height of the tree. Consider the code for the binary tree given to you for this question. Add code in the blank space provided for the member function checkCompleteBinaryTree( ) in the BinaryTree class. This member function should check whether the binary tree input by the...

  • In general, assuming a balanced BST with n nodes (A balanced binary tree has roughly the...

    In general, assuming a balanced BST with n nodes (A balanced binary tree has roughly the same number of nodes in the left and right subtrees of the root), what is the maximum number of operations required to search for a key? Please notice that the tree in this exercise is not balanced. Trace the algorithm for creating a parse tree for the expression (((4 x 8)/6)–3 Please help me understand :(

  • a. How can I show that any node of a binary search tree of n nodes...

    a. How can I show that any node of a binary search tree of n nodes can be made the root in at most n − 1 rotations? b. using a, how can I show that any binary search tree can be balanced with at most O(n log n) rotations (“balanced” here means that the lengths of any two paths from root to leaf differ by at most 1)?

  • Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary...

    Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary tree. Add this function to the class binaryTreeType and create a program to test this function. #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType { elemType info; nodeType<elemType> *lLink; nodeType<elemType> *rLink; }; //Definition of the class template <class elemType> class binaryTreeType { public: //Overload the assignment operator. const binaryTreeType<elemType>& operator=(const binaryTreeType<elemType>&) { if (this != &otherTree) //avoid self-copy...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT