🚀 Day 60 of DSA consistency Today I practiced a Binary Search Tree (BST) problem: Search in a Binary Search Tree. In this problem, we need to find a node with a given value in a BST and return the subtree rooted at that node. 🔹 Key Idea: A BST has the property: Left subtree values < root Right subtree values > root Using this property, we can efficiently search by moving left or right instead of traversing the entire tree. 📊 Complexity Analysis Time Complexity: O(h) → where h is the height of the BST Space Complexity: O(h) due to recursion stack If the tree is balanced, the complexity becomes O(log n). #DSA #Java #BinarySearchTree #CodingJourney #Consistency #LeetCode #100DaysOfCode
Binary Search Tree Search Problem Solution in Java
More Relevant Posts
-
📘 DSA Journey — Day 27 Today’s focus: Binary Search on modified arrays. Problem solved: • Search in Rotated Sorted Array (LeetCode 33) Concepts used: • Binary Search • Identifying sorted halves • Conditional search space reduction Key takeaway: This problem extends binary search to a rotated sorted array, where the array is not fully sorted but divided into two sorted parts. At each step, we: • Find the mid element • Check which half (left or right) is sorted • Decide whether the target lies in the sorted half • Eliminate the other half This allows us to still achieve O(log n) time complexity. Continuing to strengthen fundamentals and problem-solving consistency. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 62 of DSA consistency Today I solved Lowest Common Ancestor in a Binary Search Tree. 🔹 Key Idea: In a Binary Search Tree (BST): Left subtree → values smaller than root Right subtree → values greater than root Using this property: If both nodes are greater than root, move right. If both nodes are smaller than root, move left. Otherwise, the current node is the Lowest Common Ancestor. 💡 This allows us to solve the problem efficiently without storing paths. 🧠 Time Complexity: O(H) (H = height of the tree) 💾 Space Complexity: O(H) due to recursion stack. #DSA #Java #BinarySearchTree #LeetCode #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 47 🔍 Solved: Find Minimum in Rotated Sorted Array Today I explored another interesting variation of Binary Search. Instead of searching for a target, the goal was to find the minimum element in a rotated sorted array. 💡 Key Insight: By comparing the middle element with the last element, we can determine which half contains the minimum value. Approach: ✔ Used Binary Search to achieve O(log n) time complexity ✔ Compared mid with end to identify the unsorted portion ✔ Narrowed down the search space efficiently What I Learned: This problem helped me understand how binary search can be applied beyond simple searching—especially in rotated and partially sorted arrays. #Java #DSA #LeetCode #BinarySearch #CodingJourney #ProblemSolving #TechSkills
To view or add a comment, sign in
-
-
🧠 Problem Statement: Given two sorted arrays nums1 and nums2, return the median of the two sorted arrays after combining them. ⚙️ Approach: ✔️ Combine both arrays into a single array ✔️ Sort the merged array ✔️ If the length is odd → return the middle element ✔️ If the length is even → return the average of the two middle elements ⏱ Time Complexity: O((m+n) log(m+n)) 📦 Space Complexity: O(m+n) 📌 Learning: This problem helped me understand array merging and median calculation concepts. 🔥 Consistency in solving problems daily helps improve problem-solving skills and algorithmic thinking. #Day9 #DSA #LeetCode #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 6 – DSA Practice Solved Remove Duplicates from Sorted Array today. 📌 Problem: Given a sorted array, remove duplicates in-place such that each element appears only once and return the new length. 💡 Insight: Use the two-pointer approach — one pointer tracks unique elements, while the other scans the array to update values in-place. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Strengthening my understanding of in-place array manipulation and pointer techniques. #Java #DSA #LeetCode #TwoPointers #CodingInterview
To view or add a comment, sign in
-
-
#Day76 of my second #100DaysOfCode Binary search continues to surprise me with how many variations it has. DSA • Solved Find Peak Element (LeetCode 162) – Brute: check every element → O(n) – Optimal: binary search based on slope comparison → O(log n) • Key idea: if the next element is greater, move right; else move left — a peak is guaranteed • Didn’t need to check all elements, just follow the increasing/decreasing trend Interesting how this doesn’t require a fully sorted array, yet binary search still works. #DSA #BinarySearch #LeetCode #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
Day 68 of My DSA Journey Today’s problem: Symmetric Tree 🌳 Problem Statement Given a binary tree, check whether it is a mirror of itself (symmetric around its center). Key Insight A tree is symmetric if: Left subtree is a mirror of the right subtree Compare nodes in a cross manner: Left → Left with Right → Right Left → Right with Right → Left 🧠 Approach Use recursion to compare two nodes at a time Base cases: If both nodes are null → symmetric If one is null → not symmetric Check: Values are equal Outer and inner pairs match ⚡ Complexity Time: O(n) Space: O(h) (recursion stack) ✨ What I Learned This problem improved my understanding of recursion and how to think in terms of mirror structures instead of normal traversal. Consistency is the key 🔑 — one problem at a time! #DSA #Java #BinaryTree #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 22/100 Days of Code Challenge Today’s problem: Find Square Root of a Number (Binary Search Approach) 🔍 What I learned: How to efficiently compute the square root using Binary Search instead of brute force Understanding the concept of floor value of sqrt(n) Avoiding overflow using mid = low + (high - low) / 2 Time complexity improved to O(log n) 💡 🧠 Key Idea: Instead of checking every number, we narrow down the answer by dividing the search space in half — classic binary search optimization ✅ Example: Input: 28 Output: 5 (floor value of √28) Consistency is key 🔑 — showing up every day and improving step by step! #Day22 #100DaysOfCode #DSA #BinarySearch #Java #CodingJourney #ProblemSolving #TechSkills #KeepLearning
To view or add a comment, sign in
-
-
🚀 Day 47/60 - DSA Challenge Today’s problem focused on finding a Peak Element using an optimized approach! 💡 🔍 Key Insight: A peak element is one that is greater than its neighbors. Instead of checking every element, I used Binary Search to efficiently locate a peak. ⚡ Approach: Compare the middle element with its next element If the next element is greater, the peak lies on the right side Otherwise, the peak lies on the left side (including the current element) Continue narrowing the search space until the peak is found 📈 Time Complexity: O(log n) 📦 Space Complexity: O(1) 🔥 This problem reinforced how powerful pattern recognition can be—turning a simple idea into an optimized solution using binary search. #Day47 #DSA #BinarySearch #CodingJourney #Java #ProblemSolving #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development