Skip to content
Advertisement

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

Serialize and Deserialize Binary Tree

I am working on the LeetCode problem 297. Serialize and Deserialize Binary Tree: Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment. Design

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 the instance variable. Hence, the new nodes you

Advertisement