Question

Recall from Assignment 2 the definition of a binary tree data structure: either an empty tree, or a node with two children th

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

(a)  Let us consider all the possible binary search trees with each element at the root. If there are n nodes, then for each choice of root node, there must be n – 1 non-root nodes and these non-root nodes must be partitioned into those that are less than a chosen root and those that are greater than the chosen root.

Let us assume, node i is chosen to be the root. Then there must be i – 1 nodes smaller than i and n – i nodes (derived from: (n-1)-(i-1)) bigger than i. For each of these two sets of nodes, there is a certain number of possible sub-trees.

Let T(n) be the total number of binary trees with n nodes. The total number of trees with i at the root is T(i – 1) × T(n – i). The two terms are multiplied together because the arrangements in the left and right sub-trees are independent. That is, for each arrangement in the left tree and for each arrangement in the right tree, you get one tree with i at the root.

Summing over i gives the total number of binary search trees with n nodes.

T(n) = \sum_{i=1}^{n}T(i-1)T(n-i)

The base case is T(0) = 1 and T(1) = 1, because there is one empty tree and there is one tree with one node.

(b) This can be proven using the style of induction proof where we reduce from an arbitrary instance of size n, to an instance of size n−1 that meets the induction hypothesis.

i. Base Cases: The non-empty tree with zero internal nodes has one leaf node. A full binary tree with one internal node has two leaf nodes. Thus, the base cases for n=0 and n=1 conform to the theorem.

ii. Induction Hypothesis: Assume that any full binary tree T containing n−1 internal nodes has n leaves.

iii. Induction Step: Given tree T with n internal nodes, select an internal node I whose children are both leaf nodes. Remove both of I's children, making II a leaf node. Lets call the new tree T′. So, T′ has n−1 internal nodes. From the induction hypothesis, T′ has n leaves. Now, restore I's two children. We once again have tree T with n internal nodes. Because T′ has n leaves, adding the two children yields n+2. However, node I counted as one of the leaves in T′ and has now become an internal node. Thus, tree T has n+1 leaf nodes and n internal nodes and the total number of nodes is 2n+1.

By mathematical induction the theorem holds for all values of n>0. Therefore, the total number of nodes in a full binary tree will always be odd.

(c) T(n) is the number of binary trees with n nodes, and also therefore the number of full trees with 2n`+1 nodes. The number of full binary trees with n nodes is therefore T((n-1)/2).

We can say that,

T(n`) = T((n-1)/2).   [Where n` \leq n ]

Since you can't have half a node, the answer is 0 when n is even.

Add a comment
Know the answer?
Add Answer to:
Recall from Assignment 2 the definition of a binary tree data structure: either an empty tree,...
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
  • Refer to the definition of Full Binary Tree from the notes. For a Full Binary Tree...

    Refer to the definition of Full Binary Tree from the notes. For a Full Binary Tree T, we use n(T), h(T), i(T) and l(T) to refer to number of nodes, height, number of internal nodes (non-leaf nodes) and number of leaves respectively. Note that the height of a tree with single node is 1 (not zero). Using structural induction, prove the following: (a) For every Full Binary Tree T, n(T) greaterthanorequalto h(T). (b) For every Full Binary Tree T, i(T)...

  • ///Program needs to write in prolog/// 6. A binary tree is either empty or it is...

    ///Program needs to write in prolog/// 6. A binary tree is either empty or it is composed of a root element and two successors, which are binary trees themselves. In Prolog we represent the empty tree by the atom 'nil' and the non-empty tree by the term t(X,L,R), where X denotes the root node and L and R denote the left and right subtree, respectively. The following Prolog term represents the given binary tree below. T1 = t(a,t(b,t(d,nil,nil),t(e,nil,nil)),t(c,nil,t(f,t(g,nil, nil),nil))) d...

  • Binary Trees Problem 4. Binary Trees. [15 marks total Recall that a binary tree is defined...

    Binary Trees Problem 4. Binary Trees. [15 marks total Recall that a binary tree is defined as a fintie set of nodes that is either empty or consists of a root and two disjoint binary trees T and TR, respectively, the left and right subtree of the root. Since the definition itself divides a binary tree into two smaller structures of the same type, the left and the right subtree, many problems about binary trees can be solved by applying...

  • 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...

  • Problem 2 (8 pts): Structural Induction In a binary tree, a full node is a node...

    Problem 2 (8 pts): Structural Induction In a binary tree, a full node is a node with two children. Using structural induction, prove that the number of full nodes plus one is equal to the number of leaves in a binary tree (even if the tree itself is not necessarily full, i.e. some nodes may not be full)

  • Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of...

    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,...

  • 2. A complete binary tree is defined inductively as follows. A complete binary tree of height...

    2. A complete binary tree is defined inductively as follows. A complete binary tree of height 0 consists of 1 node which is the root. A complete binary tree of height h +1 consists of two complete binary trees of height h whose roots are connected to a new root. Let T be a complete binary tree of height h. Prove that the number of leaves of the tree is 2" and the size of the tree (number of nodes...

  • 2. A regular binary tree is a binary tree whose internal nodes all have two subtrees...

    2. A regular binary tree is a binary tree whose internal nodes all have two subtrees (left and right). In other words, all their nodes have either zero subtrees (in which case they are leaves) or two subtrees (in which case they are internal nodes). Suppose that you have a boolean function that tells you, for each node of the tree, whether it is a leaf or not (call it: leaf(n), for node n). a) Write a recursive function that...

  • Beginning with an empty binary search tree, what binary search tree is formed when you add the following letters in the order given?

    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...

  • The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition...

    The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition and post-condition. Please use these question to solve problem 8,the last photo. 2-3 Trees: Definition Suppose that E is an ordered type, that is, a nonempty set of values that have a total order. A 2-3-tree, for type E, is a finite rooted tree T (like a binary search tree or a red-black tree) that satisfies the following 2-3 Tree Properties: (a) Every leaf...

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
ADVERTISEMENT