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

Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as ā€œ****ā€.

0 Answers  


If an old women's age is the same as her three grand daughters i,mean the number of days old child=the no of weeks old child=no of months old child .The total yrs of all these ppl is 114 yrs...then how old is the old woman? the yr has 365 days..and 30 days each month.

1 Answers   TCS,


Here is a good puzzle: how do you write a program which produces its own source code as output?

0 Answers  


What is #error and use of it?

0 Answers  


my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

0 Answers  






how to swap 2 numbers within a single statement?

4 Answers  


I came across some code that puts a (void) cast before each call to printf. Why?

0 Answers  


How many types of operator or there in c?

0 Answers  


Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(ā€œ%cā€, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command.

1 Answers   BladeLogic, Infosys,


Why header file is used in c?

0 Answers  


The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference

0 Answers  


Which is better pointer or array?

0 Answers  


Categories