Redirected
recategorized by
4,139 views
10 votes
10 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 _______ ?
recategorized by

5 Answers

11 votes
11 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 votes
1 votes
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 votes
1 votes

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

Related questions

2 votes
2 votes
3 answers
1
0 votes
0 votes
0 answers
2
0 votes
0 votes
1 answer
3
Sandeep Singh asked Dec 27, 2015
492 views
Consider the below code which run on any tree.In-order traversalPost-order traversalPre-order traversalNone of these
1 votes
1 votes
2 answers
4
CHïntän ÞäTël asked Dec 10, 2018
1,011 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!