/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q13E A binary tree is full if all of ... [FREE SOLUTION] | 91影视

91影视

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+222n-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 91影视!

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

Thesquare of a matrix A is its product with itself, AA.

(a) Show that five multiplications are sufficient to compute the square of a 2 x 2 matrix.

(b) What is wrong with the following algorithm for computing the square of an n x n matrix?

鈥淯se a divide-and-conquer approach as in Strassen鈥檚 algorithm, except that instead of getting 7 subproblems of size n2, we now get 5 subproblems of size n2 thanks to part (a). Using the same analysis as in Strassen鈥檚 algorithm, we can conclude that the algorithm runs in time O (nc) .鈥

(c) In fact, squaring matrices is no easier than matrix multiplication. In this part, you will show that if n x n matrices can be squared in time S(n) = O(nc), then any two n x n matrices can be multiplied in time O(nc) .

  1. Given two n x n matrices A and B, show that the matrix AB + BA can be computed in time 3S(n) + O(n2 ) .
  2. Given two n x n matrices X and Y, define the 2n x 2n matrices A and B,L as follows:
    A=X000andB=0Y00
    What is AB + BA, in terms of X and Y?
  3. Using (i) and (ii), argue that the product XY can be computed in time 3S(2n) + O(n2 ). Conclude that matrix multiplication takes time O(nc ).

In Section 2.1 we described an algorithm that multiplies two n-bit binary integers x and y in time na, where a=log23. Call this procedure fast multiply (x,y).

(a) We want to convert the decimal integer 10n(a 1 followed by n zeros) into binary. Here is the algorithm (assume n is a power of 2):

function pwr2bin(n)

if n = 1: return10102

else:

z= ???

return fastmultiply(z,z)

Fill in the missing details. Then give a recurrence relation for the running time of the algorithm, and solve the recurrence.

(b) Next, we want to convert any decimal integer x with n digits (where n is a power of 2) into binary. The algorithm is the following:

function dec2bin(x)

if n=1: return binary [ x ]

else:

split x into two decimal numbers xt,xRwith n/2 digits each

return ???

Here binary [.] is a vector that contains the binary representation of all one-digit integers. That is, binary role="math" localid="1659333641173" [0]=02, binary [1]=12, up to binary [9]=10012. Assume that a lookup in binary takes 0(1) time. Fill in the missing details. Once again, give a recurrence for the running time of the algorithm, and solve it.

Given a sorted array of distinct integersA[1,...,n] , you want to find out whether there is an indexi for which A[i]=i. Give a divide-and-conquer algorithm that runs in time O(logn).

Suppose you are choosing between the following three algorithms: 鈥 Algorithm A solves problems by dividing them into five sub-problems of half the size, recursively solving each sub-problem, and then combining the solutions in linear time. 鈥

Algorithm B solves problems of size n by recursively solving two sub-problems of size n-1and then combining the solutions in constant time. 鈥 Algorithm C solves problems of size n by dividing them into nine sub-problems of size n/3, recursively solving each sub-problem, and then combining the solutions in O(n2)time.

What are the running times of each of these algorithms (in big- O notation), and which would you choose?

In Section 1.2.3, we studied Euclid鈥檚 algorithm for computing the greatest common divisor (gcd) of two positive integers: the largest integer which divides them both. Here we will look at an alternative algorithm based on divide-and-conquer.

(a) Show that the following rule is true.

gcd(a,b)={2gcd(a2,b2)ifa,bareevengcd(ab2)ifaisodd,bisevengcd(a-b2,b)ifa,bareodd

(b) Give an efficient divide-and-conquer algorithm for greatest common divisor.

(c) How does the efficiency of your algorithm compare to Euclid鈥檚 algorithm if a and b are n-bit -bit integers? (In particular, since n might be large you cannot assume that basic arithmetic operations like addition take constant time.)

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.