• recategorized by
7,966 views
12 12 votes
The number of ways we can insert elements { 1, 2, 3, .... 7 } to make an AVL tree, so that it does not have any rotation are _______ ?

5 Answers

12 12 votes

with 3 as root we can insert in 8 different combinations of avls as {3} {2,6}{1,5,7}{4} ;

{3}{1,6}{2,5,7}{4};

{3}{2,5}{1,4,6}{7} ;

{3}{1,5}{2,4,6}{7};

{3}{2,6}{1,4,7}{5};

{3}{1,6}{2,4,7}{5};

{3}{2,5}{1,4,7}{6};

{3}{1,5}{2,4,7}{6};

where each of the combination permute in 2!*3! =12 ways

this gives total of 12*8 i.e. 96 insertion sequences with 3 as root

with 4 as root, balanced avl only kind of AVL is created and sequences is {4}{2,6}{1,3,5,7} which gives 48 permutations

with 5 as root we have 8 insertion sequence with 12 permutations in each {same as 3 as root} i.e. total of 12*8 i.e 96 sequence.

So total ways to insert keys in AVL without rotation is 48+2*96 i.e 48+ 192 i.e. 240..................

1 1 vote
with 3 as root we are able to create 8 trees which are balanced BST. With 4 as root we can create just one balanced BST and with 5 as root we can create again 8 BST. Hence 17 BST should be the answer
1 1 vote

THERE WILL BE ONLY 2!4! WAYS TO DO THIS

REASON- You should insert in the order 4; 2; 6; 1; 3; 5; 7 to make an AVL tree.
The ordering of 2; 6and the ordering of 1; 3; 5; 7 do not matter. One can see the
resulting binary search tree is perfectly balance therefore an AVL tree

• edited by
0 0 votes
48 POSSIBILITIES. THE ORDER SHOULD BE(4261357) AND U CAN INTERCHANGE (2,6) AND (1357) IN BETWEEN THEM (2,6) CAN BE ARRANGED IN 2 WAYS AND (1,3,5,7)IN 24 WAYS THIS LEADS TO A TOTAL OF 48(2*24) WAYS
0 0 votes

Ans wiil be 16 ways

Here it is told

an AVL tree be formed without any rotation required

Means, the nodes will put in such a way, where no rotation required

So, I found these permutations

4,2,6,1,3,5,7

4,2,6,3,1,5,7

4,2,6,1,3,7,5

4,2,6,3,1,7,5

4,6,2,1,3,5,7

4,6,2,3,1,5,7

4,6,2,1,3,7,5

4,6,2,3,1,7,5

----------------------------------------------------------------------

4,2,6,1,7,3,5

4,2,6,3,5,1,7

4,2,6,3,7,1,5

4,2,6,1,5,3,7

4,6,2,1,7,3,5

4,6,2,3,5,1,7

4,6,2,3,7,1,5

4,6,2,1,5,3,7

• edited by
Position:
Show:

Related questions

2 2 votes
3 3 answers
1.6k
1.6k views
1 1 vote
2 2 answers
2.0k
2.0k views
CHïntän ÞäTël asked Dec 10, 2018
2,029 views
four vertices {A,B,C,D} is given which has only vertex D as a leaf total number of binary tree are possible when every binary tree has four node!
0 0 votes
0 0 answers
745
745 views
sunaina rawat asked Nov 7, 2017
745 views
Consider programint foo(struct node *tree){if(tree==0)return 0;int lh=ht(tree->left);int rh=ht(tree->right);int ld=foo(tree->left);int rd=foo(tree->right);return max(lh+r...
0 0 votes
1 1 answer
638
638 views