Search in a Binary Search Tree using BST property

🚀Day 113 of #LeetCode Challenge! Problem: Search in a Binary Search Tree 🌳 My Approach: Since this is a Binary Search Tree (BST), we can use the BST property: If the value we are searching is less than the current node’s value → search in the left subtree. If it is greater → search in the right subtree. Continue until we either find the node or reach a NULL pointer. ✨ Example: Input: root = [4,2,7,1,3], val = 2 Output: [2,1,3] Explanation: The subtree rooted at value 2 is returned. ⏱ Time Complexity: O(h) — where h is the height of the tree 📦 Space Complexity: O(h) — recursive call stack 📌 Key Insight: BST property helps us efficiently go left or right — no need to search the entire tree! 👨💻 GitHub Link: https://lnkd.in/gz6UmG6y #LeetCode #BinarySearchTree #TreeTraversal #Recursion #ProblemSolving #DSA #CodingChallenge #C++ #Day113

  • text

To view or add a comment, sign in

Explore content categories