# How to delete first half or second half of the tree?

75 views

Your program should make N node tree into N/2 node.

Input
Ex: Tree with 15 nodes.

Output
Ex: Tree should have only 7 nodes w/o any memory leak.

Option : You can delete either first half or second half of tree.

posted Oct 23, 2013
Looking for an answer?  Promote on:

first half means left part or upper part of tree.
ok. Anyway you have to traverse the tree with any of this in/post/pre order right such that you will be able to find middle node then delete the entire tree after middle [this can be a clue].  Is it clear now ?
So my two lines ??
and you got the answer :)
You asked So you should clear :)
I did not get you vikas.
In case of preorder , inorder and post order middle node will be different.
So in all case result will be different.
then what is the means of "first half or second half" ??
If you know the answer why did you asked the question ???

Based on the traversal the middle node will be different, so i sakd to choose any one. fine. Let  take this sample

http://mathworld.wolfram.com/CompleteBinaryTree.html

delete the node from 13 o 25 as level based.
First you give  suggestion for pre/in/post order traversal.
Now you want to delete second half using level order traversal.
I clearly mentioned in my first post itself that we can choose our own way/traversal as it will be a difficulty program.
Lets make it very easy.
delete any n/2 nodes from tree having n nodes.
now we end up with question. let we try for answer
Similar Questions
+1 vote

Suppose you are given a tree and asked to find out the first node at nth level. How can it be done? C code would be helpful?