Skip to content

Tag: binary-search-tree

Checking a tree to be a BST

Here is my attempt to check whether a tree is a BST or not: Code works fine as tested with multiple test cases. But I am not sure if this is a good, clean approach. Recursive method is big it seems. I am dealing with scenarios like null left node, null right node, node itself null, both child nodes null

Binary Search Tree’s add method in Java

I have a piece of code for inserting a node to Binary Search Tree in Java like: Why doesn’t my information print when I run the program? Thank you for answering my question!! Answer You don’t update the left/right pointers when the recursion returns. Also, the local variable head is different from…