how to find out the inorder successor of a node in a tree??

Answers were Sorted based on User's Feedback



how to find out the inorder successor of a node in a tree??..

Answer / atul kabra

Suppose we want to fint the inorder successor of N. Then
traverse one time right from N. And then traverse a left
subtree until u will get left pointer null node.

s=n->right;
while(s->left!=NULL)
s=s->left;

printf("\nInoder Successor is %d",s->info);

Is This Answer Correct ?    27 Yes 42 No

how to find out the inorder successor of a node in a tree??..

Answer / shruti

inorder trraversal is
left - vertex - right.

hence to find the successor of a node.

consider N node . we have to find the inorder successor of
N.
then,

if(n -> right != NULL)
n = n -> right. /* this is the successor of n.
else
{
n = pop();
(/* we have to pop the address of the node above n, which
we have pushed earlier while traversing leftwards*/)
/*n will be hte successor node.
}


in inorder traversal we have number in ascending order in a
binary search tree.
hence the successor always is to the right, if exists,
or one level above.

**Go through the inorder traversal program to get a better
picture.

Is This Answer Correct ?    11 Yes 27 No

Post New Answer

More C Interview Questions

What are the disadvantages of external storage class?

0 Answers  


What is the stack in c?

0 Answers  


What does == mean in texting?

0 Answers  


What does struct node * mean?

0 Answers  


A program to allow an input operand and operator from the operator and read on the display and output operand.

0 Answers  






find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2

0 Answers   TCS,


Write a program with dynamically allocation of variable.

0 Answers   Atos Origin,


given post order,in order construct the corresponding binary tree

0 Answers   S-Cube, Wipro,


What is "Hungarian Notation"?

0 Answers   Celstream,


How pointers are declared?

0 Answers  


What is a file descriptor in c?

0 Answers  


Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?

0 Answers   Infosys,


Categories