in Programming in C
306 views
–1 vote
–1 vote

HOW TO SOLVE IT?

in Programming in C
306 views

3 Comments

cant we zoom in the pic ?
0
0
answer will be B)n-p (first node will be root in tree)

mention that p nodes in right subtree then n-p-1 element should be present in left subtree and position of root will be n-p-1+1 = n-p.
0
0

This is a gate Q i think..

Is the answer B?

In BST, the first number that is inserted decides where the other nodes will go. So the first node is the root node.

All the nodes in the left subtree is less than the root and right subtree nodes are all greater than the root.

It says that p nodes are there in the right subtree meaning the root is lesser than all the p nodes in the right subtree.

Let l1l2.......lx ROOT r1r2.....rp be the in-order travsersal of BST.

[li indicates a node in the left subtree of root and ri is a node in the right subtree.]

count(l1l2.......lx ROOT r1r2.....rp) =n

means that the total no. of nodes starting from l1 to rp is n and rp's rank is n.

count(l1l2.......lx ROOT) = n-count(r1r2.....rp)=n-p

means that the total no. of nodes starting from l1 to  ROOT is n and ROOT's rank is (n-p).

Shortcut:

Let inorder traversal be 3,4,5,6,7,8,9 and p=2(let).

So root comes at after 2 elements from right i.e. 7 is the root. What is it's rank(index in inorder traversal)? (7-2)=5.

2
2

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
4