Easy To Understand Clean Java Code in 2 ways ㄟ( ▔, ▔ )ㄏ
BINARY SEARCH TREE (BST) is a node-based binary tree data structure which has the properties:\n\n The left subtree of a node contains only nodes with keys lesse
***BINARY SEARCH TREE (BST)*** is a node-based binary tree data structure which has the properties:\n\n* The left subtree of a node contains only nodes with keys lesser than the node\u2019s key.\n* The right subtree of a node contains only nodes with keys greater than the node\u2019s key.\n* The left and right subtree each must also be a binary search tree.\n\n![image](https://assets.leetcode.com/users/images/49874e49-a0fa-40d0-a18e-3c5ff98d0aab_1649905553.0092869.gif)\n\n\n\n***APPROCH 1 : RECURSION METHOD***\n```\nclass Solution {\n    public TreeNode searchBST(TreeNode root, int val) {\n        if(root == null || root.val == val) return root;// Base Cases: root is null or val is present at root\n\t\tif(root.val > val) return searchBST(root.left, val); // Value is greater than root\'s val then search in right side of the root\n\t\treturn searchBST(root.right, val);//Value is smaller than root\'s val then search in left side of the root\n    }\n}\n```\n<hr>\n<hr>\n\n***Time Complexity : O(N)***\n***Space Complexity :O(N)***\nWhere `N` is height of the tree.\n\n<hr>\n<hr>\n\n****APPROACH 2 : ITERATIVE METHOD**\n```\nclass Solution {\n    public TreeNode searchBST(TreeNode root, int val) {\n   \n        if(root == null)return null;//Base Condition(If tree is empty )\n        while (root != null && root.val !=val){//Tree is not empty and root value is not equals to val\n            root = val <root.val?root.left :root.right;//terminatory condition if val smaller than root value then search in left side else on right side\n        }\n        return root;  \n    }\n}\n```\n<hr>\n<hr>\n\n***Time Complexity : O(N)***\n***Space Complexity :O(1)***\nWhere `N` is height of the tree.\n\n<hr>\n<hr>
['Recursion', 'Java']