Comments on: Programming Interview Questions 7: Binary Search Tree Check /2011/10/10/programming-interview-questions-7-binary-search-tree-check/?utm_source=rss&utm_medium=rss&utm_campaign=programming-interview-questions-7-binary-search-tree-check Information Retrieval and Machine Learning Thu, 16 Feb 2012 16:19:09 +0000 hourly 1 http://wordpress.org/?v=3.3 By: Arden /2011/10/10/programming-interview-questions-7-binary-search-tree-check/#comment-651 Arden Thu, 01 Dec 2011 19:07:59 +0000 /?p=569#comment-651 You're right, changed it. Thanks for the comment.. You’re right, changed it. Thanks for the comment..

]]>
By: Anonymous /2011/10/10/programming-interview-questions-7-binary-search-tree-check/#comment-648 Anonymous Thu, 01 Dec 2011 04:54:58 +0000 /?p=569#comment-648 There's no reason to build a list of all node values in isBST2. You only need the value of the last node visited so far. Rename nodes to maxValBox and update it like this: maxValBox[0] = tree.val There’s no reason to build a list of all node values in isBST2. You only need the value of the last node visited so far. Rename nodes to maxValBox and update it like this:

maxValBox[0] = tree.val

]]>
By: Arden /2011/10/10/programming-interview-questions-7-binary-search-tree-check/#comment-254 Arden Tue, 11 Oct 2011 17:32:03 +0000 /?p=569#comment-254 Hi Igor, thanks for the comment. You're right about recursion and stack space. I didn't mention that because both of the algorithms are recursive. If we would like to code it iteratively, than we have to maintain a queue, which will use the heap space. But as you said, it's definitely useful to first step back and thoroughly analyze all the possible solutions with their real world implications, and then start coding the actual algorithm. Hi Igor, thanks for the comment. You’re right about recursion and stack space. I didn’t mention that because both of the algorithms are recursive. If we would like to code it iteratively, than we have to maintain a queue, which will use the heap space. But as you said, it’s definitely useful to first step back and thoroughly analyze all the possible solutions with their real world implications, and then start coding the actual algorithm.

]]>
By: Igor Yagolnitser /2011/10/10/programming-interview-questions-7-binary-search-tree-check/#comment-253 Igor Yagolnitser Tue, 11 Oct 2011 17:11:33 +0000 /?p=569#comment-253 Hey Arden, Didn't know you had this blog, but that's a great idea! I'd like to contribute to it when I get some time. As for the in order traversal above: where are you adding to the node list? A special note about these types of problems when interviewing at Microsoft: while algorithmically your solution should be recursive, your implementation should be prefixed by: "the problem with the recursive implementation is that it's only good when you know the depth, otherwise you can easily blow the stack". This shows you understand the practical difference between writing code in a classroom and in a production environment. If the interviewer then says: "let's say you don't need to worry about that", you proceed with your solution, but twice in my own experience the problem was precisely about whether I would just rush to implement the obvious and well known book solution, or stop to consider the real world implications. Just a thought. Good luck. P.S. Could not post a comment. Hey Arden,

Didn’t know you had this blog, but that’s a great idea!
I’d like to contribute to it when I get some time.
As for the in order traversal above: where are you adding to the node list?
A special note about these types of problems when interviewing at Microsoft: while algorithmically your solution should be recursive, your implementation should be prefixed by: “the problem with the recursive implementation is that it’s only good when you know the depth, otherwise you can easily blow the stack”. This shows you understand the practical difference between writing code in a classroom and in a production environment. If the interviewer then says: “let’s say you don’t need to worry about that”, you proceed with your solution, but twice in my own experience the problem was precisely about whether I would just rush to implement the obvious and well known book solution, or stop to consider the real world implications.
Just a thought.
Good luck.

P.S. Could not post a comment.

]]>