DSA with Java.... Today I learnt about BINARY SEARCH.. Binary search refers to finding the position of an element in a sorted array. Half of the array is disregarded during each step. This search works on datasets that are sorted first. It works more efficiently with large data sets with a runtime complexity of O(log n) i.e the larger the dataset, the more efficient it becomes. There is an in built binary search function in Java and I tried creating a function to understand how the logic works. Next up: interpolation search... cheers 🥂 #dsa #softwareengineer #java #binarysearch
Java Binary Search Algorithm Explained
More Relevant Posts
-
DSA with Java... Today I learnt about INTERPOLATION SEARCH.... Remember how binary search breaks the datasets into halves to reduce where to search for the target value? This is an improvement on it. It is best for uniformly distributed data. It guesses where the value might be in a calculated probe result. If the probe result is incorrect, we narrow the search and try again. The average case runtime is O(log(logn)) The worst case runtime is O(n) when the value increases exponentially. in what software engineering practices or features do we need to apply interpolation search instead? cheers 🥂 #dsa #java #softwareengineering #interpolationsearch
To view or add a comment, sign in
-
-
🚀 DSA in Java — Day 78 📌 Problem Solved: Binary Tree Level Order Traversal Today I solved the Binary Tree Level Order Traversal problem on LeetCode using Breadth First Search (BFS) with a Queue. In this problem, we traverse the binary tree level by level from left to right. 🔹 Approach Used: Used a Queue data structure Added the root node to the queue Processed nodes level by level Stored each level's values inside a list Added the list to the final result 🔹 Key Concepts Practiced: ✔ Binary Trees ✔ Breadth First Search (BFS) ✔ Queue in Java ✔ Level-wise traversal This problem helped me understand how queues are used to process nodes level-wise in trees, which is very useful in many tree problems. Consistent practice is making tree problems much clearer day by day. 💻 Language: Java 📚 Platform: LeetCode #DSA #Java #BinaryTree #LeetCode #CodingJourney #WomenInTech #100DaysOfCode
To view or add a comment, sign in
-
-
Day 42 of #100DaysOfLeetCode 💻✅ Solved #704. Binary Search problem in Java. Approach: • Since the array is already sorted, applied the Binary Search algorithm • Initialized two pointers: left at the start and right at the end of the array • Calculated the middle index using (left + right) / 2 • If the middle element equals the target, returned the index • If the middle element is smaller than the target, moved the left pointer to mid + 1 • If the middle element is greater than the target, moved the right pointer to mid - 1 • Continued until the target was found or the search space became empty Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 48.32 MB (Beats 68.26% submissions) Key Learning: ✓ Practiced Binary Search with O(log n) time complexity ✓ Learned how pointer adjustments reduce the search space efficiently ✓ Strengthened understanding of searching algorithms in sorted arrays Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 47 of #100DaysOfLeetCode 💻✅ Solved #101. Symmetric Tree problem in Java. Approach: • Used recursion to compare the left and right subtrees of the root • If both nodes are null, the tree is symmetric at that level • If one node is null and the other is not, the tree is not symmetric • Compared the values of both nodes • Recursively checked left.left with right.right and left.right with right.left to verify mirror structure Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 43.62 MB (Beats 48.60% submissions) Key Learning: ✓ Practiced mirror comparison in binary trees ✓ Learned how recursion can verify symmetry between two subtrees ✓ Strengthened understanding of tree traversal and structural comparison Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTrees #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 7/50 | #50DaysOfCode 📍 Platform: LeetCode 💻 Language: Java ✅ 167. Two Sum II - Input Array Is Sorted (Medium) Today’s problem focused on finding two numbers in a sorted array that sum up to a target. It helped reinforce the two-pointer technique and efficient array traversal. 🔎 Approach: Use two pointers: one at the start (left) and one at the end (right) of the array Calculate the sum of numbers at both pointers If sum equals target, return the 1-indexed positions [left+1, right+1] If sum < target, move left pointer forward If sum > target, move right pointer backward Continue until the solution is found 📌 Example: Input: numbers = [2,7,11,15], target = 9 Output: [1,2] Explanation: 2 + 7 = 9 → indices 1 and 2 This problem strengthened my understanding of two-pointer techniques, sorted arrays, and constant space solutions in Java. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Consistency #LearningJourney #50DaysOfCode #LinkedIn
To view or add a comment, sign in
-
-
Day 41 of #100DaysOfLeetCode 💻✅ Solved #242. Valid Anagram problem in Java. Approach: • Converted both strings to lowercase to ensure case-insensitive comparison • Converted the strings into character arrays • Sorted both arrays using Arrays.sort() • Compared the sorted arrays using Arrays.equals() • If both arrays match, the strings are anagrams Performance: ✓ Runtime: 11 ms (Beats 28.32% submissions) ✓ Memory: 46.83 MB (Beats 8.28% submissions) Key Learning: ✓ Practiced string manipulation and character array handling in Java ✓ Understood how sorting helps in comparing character frequencies ✓ Strengthened problem-solving skills for string-based problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 43 of #100DaysOfLeetCode 💻✅ Solved #100. Same Tree problem in Java. Approach: • Used recursion to compare both binary trees simultaneously • If both nodes are null, returned true • If one node is null and the other is not, returned false • Checked whether the values of both nodes are equal • Recursively compared the left subtrees and right subtrees Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 43.10 MB (Beats 30.15% submissions) Key Learning: ✓ Practiced recursive traversal of binary trees ✓ Learned how to compare two trees node by node ✓ Strengthened understanding of tree recursion logic Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTrees #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
----Continuing my DSA practice using Java.---- Today I solved “Isomorphic Strings.” Two strings are isomorphic if characters in one string can be replaced to get the other, while maintaining a consistent one-to-one mapping. Instead of using HashMaps, I used two fixed-size arrays to track character mappings in both directions. If the mapping didn’t match at any index, the strings were not isomorphic. Key takeaway: When character constraints are small (like ASCII), arrays can be faster and cleaner than HashMaps. #DSA #Java #Strings #ProblemSolving #LearningJourney
To view or add a comment, sign in
-
-
Day 5/50 | #50DaysOfCode 📍 Platform: LeetCode 💻 Language: Java ✅ 290. Word Pattern (Easy) Today’s problem focused on mapping relationships between characters and words. It helped strengthen my understanding of hash-based data structures and bijection logic. 🔎 Approach: Split the string s into individual words Check if the length of the pattern matches the number of words Use a HashMap to map each character in the pattern to a word Ensure that each character maps to only one unique word Also verify that no two characters map to the same word Return true if the mapping follows the pattern, otherwise false 📌 Example: Input: pattern = "abba", s = "dog cat cat dog" Output: true Explanation: 'a' → "dog" 'b' → "cat" This problem improved my understanding of HashMap usage, string splitting, and bijection mapping logic in Java. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Consistency #LearningJourney #50DaysOfCode #LinkedIn
To view or add a comment, sign in
-
-
✨ DSA in Java – Day 83 🚀 Today I solved an interesting problem on Binary Trees: 👉 Sum of Root to Leaf Binary Numbers 🌱 What I Learned: How to traverse a binary tree using DFS (Depth First Search) Building numbers along the path using: ➤ current = current * 2 + node.val Identifying leaf nodes and calculating final values Improving recursion understanding in tree problems 💡 Approach: Start from root with value 0 At each node, update the current number If it's a leaf node → add it to the final sum Traverse left and right recursively 📌 Key Insight: Binary tree problems become easier when you think of them as path-based problems rather than node-based problems. 💻 Consistency is the key! Day by day, step by step, getting stronger in DSA 💪 #DSA #Java #BinaryTree #CodingJourney #LeetCode #100DaysOfCode #WomenInTech #Consistency
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