# How Debuggers Work

Recently one of my colleagues asked me this question on the way back to home from office – “How do you design a debugger?”. We had some interesting discussions, made some assumptions on the support from OS, thoughts on what would happen in different approaches. I got this question at the back of mind and tried to find an answer and came across this site which has 3 parts that explains “How Debuggers work”. Though I haven’t read the articles completely [looks really geeky :)], I felt its worth sharing. In case if some one is curious like me to know about the topic, the below links might help

http://eli.thegreenplace.net/2011/01/23/how-debuggers-work-part-1/

http://eli.thegreenplace.net/2011/01/27/how-debuggers-work-part-2-breakpoints/

http://eli.thegreenplace.net/2011/02/07/how-debuggers-work-part-3-debugging-information/

In case if any one finds anything simpler or good guides on the topic do let me know.

Next thing to know is “How does a code profiler work?”

Thanks!

# Find nodes in a binary tree which are at a distance K from a given node

You are given a binary tree and a node in the tree, your task is to find all the nodes in the binary tree which are at a distance K from that node. These nodes can be downwards [descendants of the node] or upwards.

For example: In this image

http://www.cs.mcgill.ca/~jeromew/comp252/images/Binary_tree.png

The nodes that are at a distance 2 from 7 are 5 (6’s left child), 11, 5 (2’s right child).

This is a coding question.

Function prototype:

void PrintKDistanceNode(Node *root, Node *node, int K)

{

}