A binary tree is full if all of its vertices have either zero or two children. Let Bndenote the number of full binary trees with n vertices. (a)By drawing out all full binary trees with 3, 5, or 7 vertices, determine the exact values of B3, B5, and B7. Why have we left out even numbers of vertices, like B4?

(b) For general n, derive a recurrence relation for Bn.

(c) Show by induction that Bnis Ω(2n).

Short Answer

Expert verified

(a) Exact value of B3=1

Exact value of B5=2

Exact value of B7=5

(b) Required recurrence relation: Bn=i=1n-2BiBn-i-1

(c) By induction, it is proved that Bn=Ω2n

Step by step solution

01

Solution of part (a)

All binary trees having 3, 5, and 7 nodes are shown in following diagrams:

The following is a binary tree with three verticesB3:

From either the multiple endpoints, only one full binary tree can be drawn.

As a result, the precise value ofB3is 1.

B3=1

The binary tree with five verticesB5is shown below:

Here, two binary trees can be drawn from the five vertices. Therefore, the exact value ofB5is 2 .

The binary tree with five verticesB7is shown below:

From of the seven edges, five binary trees may be drawn. As a result, the precise value ofB7is 5.

The number of edges in a complete binary tree must be odd.

As a result, there is no requirement forB4or B6etc.

02

Solution of part (b)

Recurrence relation for Bnis given below:

The number of entire binary trees is equal to the total of the products of something like the series of binary trees from the child trees.

Bn=i=1n-2BiBn-i-1

That number of sensor nodes inside the left sub-tree is I while the number of nodes in the right sub-tree is n-i-1.

When n=5 is the number of vertices in a binary tree, the precise value of B5is given as follows:

B5=i=15-2BiB5-i-1=B1B3+B2B2+B3B1=1+0+1=2

As a result, there are two binary trees produced for every five vertices.

As a result, the recurrence relation is shown to be valid Bn=i=1n-2BiBn-i-1

03

Solution to part (c)

The proof is as follows:

Display that,Bn2n-32

Base case:

n=1B1=12-1B3=12°

Inductive steps:

For n3odd:

Bn+2=i=1n+1BiBn-i-1n+22×2n-5222n-52=2n-12

Thus, it is proved that Bn would be Ω(n2).

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

You are given two sorted lists of size mandn. Give an O(logm+logn)time algorithm for computing the k th smallest element in the union of the two lists.

An array A [1...n] is said to have a majority element if more than half of its entries are the same. Given an array, the task is to design an efficient algorithm to tell whether the array has a majority element, and, if so, to find that element. The elements of the array are not necessarily from some ordered domain like the integers, a A2 nd so there can be no comparisons of the form “is A[i]>A[j]?”. (Think of the array elements as GIF files, say.) However you can answer questions of the form: “is ..?” in constant time.

(a) Show how to solve this problem in O(nlog n) time. (Hint: Split the array A into two arrays A1 and of half the size. Does knowing the majority elements of A1 and A2 help you figure out the majority element of A? If so, you can use a divide-and-conquer approach.)

(b) Can you give a linear-time algorithm? (Hint: Here’s another divide-and-conquer approach:

  • Pair up the elements of A arbitrarily, to get n/2 pairs
  • Look at each pair: if the two elements are different, discard both of them; if they are the same, keep just one of them
    Show that after this procedure there are at most n/2 elements left, and that they have a majority element if A does.)

Section 2.2 describes a method for solving recurrence relations which is based on analyzing the recursion tree and deriving a formula for the work done at each level. Another (closely related) method is to expand out the recurrence a few times, until a pattern emerges. For instance, let’s start with the familiar T(n)=2T(n/2)+o(n). Think of o(n) as being role="math" localid="1658920245976" <cnfor some constant , so: T(n)<2T(n/2)+cn. By repeatedly applying this rule, we can bound T(n) in terms of T(n/2), then T(n/4), then T(n/8), and so on, at each step getting closer to the value of T(.) we do know, namely .

T(1)=0(1).

T(n)2T(n/2)+cn2[2Tn/4+cn/2]+cn=4T(n/4)+2cn4[2Tn/8+cn/4]+2cn=8T(n/8)+3cn8[2Tn/16+cn/8]+3cn=16T(n/16)+4cn

.

.

.

A pattern is emerging... the general term is

T(n)2kT(n/2k)+kcn

Plugging in k=log2n, we get T(n)nT(1)+cnlog2n=0(nlogn).

(a)Do the same thing for the recurrence T(n)=3T(n/2)+0(n). What is the general kth term in this case? And what value of should be plugged in to get the answer?(b) Now try the recurrence T(n)=T(n-1)+0(1), a case which is not covered by the master theorem. Can you solve this too?

How many lines, as a function of n (in (.)form), does the following program print? Write a recurrence and solve it. You may assume is a power of . function f (n) if n > 1:

print_line (‘‘still going’’)

f (n/2)

f (n/2)

You are given an array of nelements, and you notice that some of the elements are duplicates; that is, they appear more than once in the array. Show how to remove all duplicates from the array in time O(nlogn) .

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free