☕  Search in a BST | JAVA | Recursive & Iterative & Stack | Clean & Simple ☕
1. Recursive approach:\n\n\n    // Time Complexity: O(log n), worst case O(h)\n    // Space Complexity: O(h)\n    // n -> number of nodes in the tree\n    // h 
**1. Recursive approach:**\n\n```\n    // Time Complexity: O(log n), worst case O(h)\n    // Space Complexity: O(h)\n    // n -> number of nodes in the tree\n    // h -> height of the tree\n    public TreeNode recursiveUsingSearchBST(TreeNode root, int val) {\n        if (root == null) return root;\n        if (val < root.val) return recursiveUsingSearchBST(root.left, val);\n        if (val > root.val) return recursiveUsingSearchBST(root.right, val);\n        return root;\n    }\n```\n\n**2. Iterative approach:**\n\n```\n    // Time Complexity: O(log n)\n    // Space Complexity: O(1)\n    public TreeNode iterativeUsingSearchBST(TreeNode root, int val) {\n        while (root != null && root.val != val) {\n            root = val < root.val ? root.left : root.right;\n        }\n\n        return root;\n    }\n```\n**3. Stack approach:**\n\n```\n    // Time Complexity: O(log n) or O(h)\n    // Space Complexity: O(h)\n    // n -> number of nodes in the tree\n    // h -> height of the tree\n    public TreeNode stackUsingSearchBST(TreeNode root, int val) {\n        if (root == null || root.val == val) {\n            return root;\n        }\n        Stack<TreeNode> stack = new Stack<>();\n        if (root.val > val) {\n            stack.push(root.left);\n        } else {\n            stack.push(root.right);\n        }\n        while (!stack.isEmpty()) {\n            TreeNode currentNode = stack.pop();\n            if (currentNode != null) {\n                if (currentNode.val == val) {\n                    return currentNode;\n                }\n                if (currentNode.val > val) {\n                    stack.push(currentNode.left);\n                } else {\n                    stack.push(currentNode.right);\n                }\n            }\n        }\n        return null;\n    }\n```
['Stack', 'Recursion', 'Binary Tree', 'Iterator', 'Java']