if it is binary tree then to print the downward node...
we can search for start node and then do level-order traversal or BFS from
start node till distance K recursively.

no as we want nodes to be printed in sorted order..what we do is crated a
linked-list and insert nodes (found in above method) in sorted way.
then print the linked list.

for upward nodes......... thinking...........

On Wed, Feb 1, 2012 at 9:52 AM, atul anand <[email protected]> wrote:

> are you sure given tree is binary tree and not BST.
> if it is BST then we can search start node and then do inorder traversal
> from there.
> before thinking printing abt upward node...please confirm if it a binary
> tree or BST.
>
>
> On Tue, Jan 31, 2012 at 9:27 PM, Dhirendra Singh <[email protected]> wrote:
>
>>
>> You are given a function printKDistanceNodes which takes in a root node
>> of a binary tree, a start node and an integer K. Complete the function to
>> print the value of all the nodes (one-per-line) which are a K distance from
>> the given start node in sorted order. Distance can be upwards or downwards.
>>
>>
>> anyone any idea ?? how to print nodes above the specified node,
>>
>> Note : we do not have a reference to parent
>>
>>
>>
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to