Check if Tree is a Balanced Tree

Problem Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in distance from the root by more than one Solution Method 1 - Difference of height at each node should not be greater than 1 Here is the code : public boolean isBalanced(Node root){ if(root==null){ return true; //tree is empty } else{ int lh = root. [Read More]

IsBST : Check whether the tree provided is BST or not

Problem This background is used by the next two problems: Given a plain binary tree, examine the tree to determine if it meets the requirement to be a binary search tree. To be a binary search tree, for every node, all of the nodes in its left tree must be <= the node, and all of the nodes in its right subtree must be > the node. Consider the following four examples… [Read More]

Check whether binary tree are same or not?

Problem Given two binary trees, return true if they are structurally identical – they are made of nodes with the same values arranged in the same way. Solution 11\. sameTree() Solution (C/C++) /\* Given two trees, return true if they are structurally identical. \*/ int isIdentical(struct node\* a, struct node\* b) { // 1. both empty -> true if (a==NULL && b==NULL) return(true); // 2. both non-empty -> compare them else if (a! [Read More]