My Dear friend , For Getting the Path above the source node here is the simple step .. The below table illustrates it :-
During traversing the in BFS way from the root until we find the source node . Current Node = a | b c | d e Distance from Root = 0 | 1 1 | 2 2 PrevNode = -- | a a | b b After u reach the source node e backtrack to it's previous node taking a counter to record the distance from the source node backward until root node is reached or else K is reached . For K=1 , source node e we can get the node b (6) ..... Now do u see the process to traceback .. Here are two case either the value of k is reached on or before hitting the root node .. Let's take on the cases :- For case 1 :- When value k is reached on or before reaching the root node . Here we get the path.. For case 2 :- When the value of k of not reached .. suppose we get a distance (d) from the source node to the root. Now to need to find the distance of (k-d) from the root node , which is the same as the BFS approach . Hopefully Mr Ankuj , this will clear the air ... -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.