🔥 #100DaysOfDSA — Day 29/100 Topic: Binary Search in Java ⚡ 💡 What I Did Today: Today, I implemented one of the most powerful and efficient searching algorithms — Binary Search 🔍 Instead of checking every element one by one like Linear Search, Binary Search smartly divides the array in half each time — reducing the time complexity drastically! 🧠 Logic Used: Works only on sorted arrays ✅ Find the mid index: mid = (start + end) / 2 If key == numbers[mid] → found the element 🎯 If key > numbers[mid] → search in right half Else → search in left half Continue until the element is found or the range is empty 📊 Example: Input → {4, 5, 6, 10, 18, 61, 122} Key → 61 ✅ Output → index for key is: 5 ⚙️ Time Complexity: O(log n) — super fast compared to O(n) of Linear Search 💨 ✨ Takeaway: Binary Search is a fundamental algorithm that teaches the power of divide and conquer. Mastering this concept builds the foundation for more advanced topics like search trees, sorting, and algorithm optimization 🚀 #100DaysOfCode #Day29 #Java #DSA #BinarySearch #ProblemSolving #CodingJourney #LearnInPublic #DeveloperLife #CodeNewbie
Implemented Binary Search in Java for #100DaysOfDSA
More Relevant Posts
-
🚀 #100DaysOfDSA — Day 27/100 Topic: Linear Search in Java 💻 💡 What I Did Today: Today I learned and implemented the Linear Search algorithm — one of the simplest and most fundamental searching techniques in DSA. It’s all about checking each element in an array one by one until the key is found (or not found). 🧠 Logic Used: Traverse the entire array. Compare each element with the key. If it matches → return the index. If no match is found → return -1. 📊 Output Example: Array → {2, 4, 6, 8, 10, 12, 50, 16} Key → 50 ✅ Output → Key is at index: 6 ✨ Takeaway: Linear Search may not be the most efficient algorithm, but it’s the foundation of all searching logic. Understanding it helps in learning more advanced techniques like Binary Search later 🔍 #100DaysOfCode #Day27 #Java #DSA #LinearSearch #ProblemSolving #CodingJourney #LearnInPublic #CodeNewbie #DeveloperLife
To view or add a comment, sign in
-
-
Day 37/100 ✅ Binary Tree Postorder Traversal Today I solved the Binary Tree Postorder Traversal problem using a simple recursive approach in Java. In postorder traversal, we visit nodes in the order Left → Right → Root. This helps in many real-world tree-based algorithms like expression tree evaluations or file system traversal. 💡 Approach: I used recursion — first visiting the left child, then the right child, and finally adding the node’s value to the result list. It’s clean, elegant, and easy to understand! ✅ Key Learning: Understanding traversal patterns (Preorder, Inorder, Postorder) is essential for mastering tree-based problems. Each pattern teaches how to process data at different stages of recursion. #LeetCode #Java #CodingJourney #DSA #BinaryTree #Recursion #PostorderTraversal #100DaysOfCode
To view or add a comment, sign in
-
-
☕ Day 7 – Java 2025: Smart, Stable, and Still the Future 💡 🔹 Topic: ASCII Value in Java 🧩 What is ASCII Value? ASCII stands for American Standard Code for Information Interchange. It is a numerical representation of characters — where every letter, number, or symbol is assigned a specific numeric value between 0 and 127. For example, 'A' → 65, 'a' → 97, '0' → 48. --- ⚙️ How We Can Use ASCII Values in Java In Java, each character (char) has an internal ASCII code. You can easily get this value by type casting a character to an integer. This helps programmers perform character comparisons, sorting, encryption, and pattern logic. --- 🎯 Purpose of ASCII Values 1️⃣ Character Comparison: To check which character comes first or is greater based on ASCII order. Example: 'A' < 'a' because 65 < 97. 2️⃣ Encoding & Data Transmission: When sending text over systems or networks, ASCII ensures characters are universally understood. 3️⃣ Sorting and Logic Building: Used in string sorting algorithms or validation logic (e.g., checking if a character is uppercase, lowercase, or a number). 4️⃣ Mathematical Operations on Characters: You can perform arithmetic operations like converting uppercase to lowercase using ASCII difference. --- 💻 Simple Example char ch = 'A'; int ascii = (int) ch; // Type casting char to int System.out.println("ASCII value of " + ch + " is: " + ascii); Output: ASCII value of A is: 65 --- 🧠 Extra Insight 'A' to 'Z' → 65 to 90 'a' to 'z' → 97 to 122 '0' to '9' → 48 to 57 ASCII makes Java programs language-neutral and machine-readable for text processing tasks. --- ✨ #Day7OfJava #Java2025 #LearnJava #ASCIICode #JavaBasics #JavaCharacters #JavaForBeginners #CodeWithSneha #ProgrammingConcepts #100DaysOfJava #TechLearning #DeveloperJourney
To view or add a comment, sign in
-
-
💻 DSA – Day 13 : Strings & StringBuilder Today I explored Strings in Java, a core concept used in almost every application — from input handling to algorithms, data processing, and problem-solving. Strings look simple, but there's a lot happening under the hood. 🌈 What I learned today 🔹 ❓ What are Strings? A sequence of characters stored as an object in Java. Strings are immutable, which means once created, they cannot be changed. 🔹 ⌨️ Input & Output Took string inputs using Scanner and printed them with basic operations. 🔹 📏 String Length Used .length() to find the number of characters. 🔹 ➕ String Concatenation Joined strings using +, concat(), and StringBuilder. 🔹 🔡 charAt() Method Accessed characters using index values. 🔹 🔄 Check if a String is Palindrome Compared characters from both ends to verify if the string reads the same backwards. 🔹 🧭 Shortest Path Problem Calculated the shortest path (N/E/W/S directions) using coordinate logic. 🔹 ⚖️ String compare() Compared strings lexicographically using .compareTo(). 🔹 ✂️ substring() Function Extracted specific parts of the string. 🔹 🏆 Print Largest String Compared strings alphabetically to find the largest one. 🔹 🔒 Why Strings Are Immutable? Because they are stored in the String Pool and designed for security, caching, and thread-safety. 🧵 StringBuilder – Faster & Mutable 🔹 Unlike Strings, StringBuilder is mutable 🔹 Perfect for modifying strings repeatedly (loops, concatenation, dynamic strings) ✨ Extra Concepts Learned 🔹 🔤 Convert Letters to Uppercase Converted the first letter of each word to uppercase (title case-style logic). 🔹 📦 String Compression Implemented character frequency compression like: aaabbccc → a3b2c3 🚀 Loving the learning curve Strings are everywhere — mastering them builds a strong foundation for upcoming DSA topics. #DSA #Strings #Java #StringBuilder #CodingJourney #100DaysOfCode #LearningInPublic #ProblemSolving #Day13
To view or add a comment, sign in
-
Day 85 of #100DaysOfCode Solved Range Sum Query - Immutable (NumArray) in Java ➕ Approach Today's problem was a classic that demonstrates the power of pre-computation: finding the sum of a range in an array many times. The optimal solution is the Prefix Sum technique. Pre-computation: In the constructor, I built a prefixSum array where prefixSum[i] holds the sum of all elements from index 0 up to index $i-1$ in the original array. This takes $O(N)$ time. $O(1)$ Query: The magic happens in the sumRange(left, right) method. The sum of any range $[left, right]$ is found instantly by calculating prefixSum[right + 1] - prefixSum[left]. The cost of a single $O(N)$ setup is outweighed by the ability to perform every subsequent query in $O(1)$ time! #Java #100DaysOfCode #LeetCode #CodingChallenge #Algorithms #Arrays #PrefixSum #Optimization #ProblemSolving
To view or add a comment, sign in
-
-
👉 Why should a Functional Interface contain only one abstract method? 📌 Ex - interface Interf { public void m1(int i) } Interf I = i -> System.out.println(i * i); I.m1(10); I.m2(20); 👉 A functional interface must have exactly one abstract method because a lambda expression is meant to represent a single functionality or behavior. When you write a lambda expression, it needs to map to one specific abstract method in the interface. If the interface had multiple abstract methods, the compiler wouldn’t know which method the lambda is referring to — leading to ambiguity. That’s why a functional interface can have only one abstract method, and it is the only type of interface that can be used with lambda expressions in Java. 👉 Why can’t a Functional Interface have two abstract methods? 📌 Ex - interface Interf { public void m1(int i); public void m2(int i); } Interf I = i -> System.out.println(i * i); 💡Compile Time Error - Interf is not a Functional Interface - Multiple non-overriding abstract method in interface Interf 👉 If an interface contains two abstract methods, a lambda expression won’t know which method to map to, because there are multiple choices. That’s why a Functional Interface must contain exactly one abstract method this ensures that the lambda expression can clearly represent that single method. #OOP #Abstraction #CleanCode #LearningJava #Programming #Developers #String #CodingTips #CoreJava #Learning #JavaDeveloper #CodingPractice #Interface #JavaInterviewPreparation #LearnToCode #JavaInterviewPreparation #JavaFresher #Java #Java8 #FunctionalInterface #LambdaExpressions
To view or add a comment, sign in
-
Day 9 of my #JavaWithDSAChallenge Today’s topic: Java Exception Handling Problem: Given two integers a and b, find the minimum value of a $ b where $ can be any arithmetic operation (+, -, *, /). We also need to handle division by zero using Exception Handling in Java. Key Concepts: try-catch block to handle runtime errors gracefully Arithmetic operations and Math.min() for comparisons Handling invalid division cases safely Code Snippet: class Solution { public int findMin(int a, int b) { int add = a + b; int sub = a - b; int mul = a * b; int div = Integer.MAX_VALUE; try { div = a / b; } catch (ArithmeticException e) { // Division by zero handled } int min1 = Math.min(add, sub); int min2 = Math.min(mul, div); return Math.min(min1, min2); } } Example: Input: a = 5, b = -5 Output: -25 Explanation: Among (0, 10, -25, -1), the minimum is -25. Learning: Exception Handling is not just about catching errors - it’s about writing safe and reliable code that doesn’t break in unexpected situations. #Java #CodingChallenge #DSA #LearningInPublic #100DaysOfCode #WomenInTech #JavaDeveloper
To view or add a comment, sign in
-
-
🔢 Today I worked on a classic matrix problem in Java — Diagonal Sum. The goal was simple: Calculate the sum of both the primary and secondary diagonals of a square matrix. Initially, I used a nested loop approach with O(n²) complexity. But then I optimized it to a clean O(n) solution by directly accessing diagonal indexes. While optimizing, I made an interesting mistake: ❌ I wrote if (i != matrix[i][matrix.length - 1 - i]) Here I accidentally compared an index with an element value. ✔ Correct approach: if (i != matrix.length - 1 - i) This ensures the center element in odd-sized matrices isn’t counted twice. 🧠 Key Learning: Indexes and values may look similar, but mixing them can break logic silently. Optimization is not just about speed — it’s about accuracy. #Java #leetcode #Coding #DSA #ProblemSolving #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Jump Search Implementation (Data Structures And Algorithms) This Java code demonstrates the jump search algorithm. It works by jumping ahead by a fixed step and then performing a linear search within that block. The jump size is typically the square root of the array size. Jump search is more efficient than linear search but less efficient than binary search. It's particularly useful when accessing elements is expensive (e.g., reading from a disk). #Algorithms #DataStructures #CodingInterview #ProblemSolving #professional #career #development
To view or add a comment, sign in
-
-
🚀 Day 4 of My DSA with Java Journey 📘 Problem: Square of a Sorted Array 🧩 Topic: Two Pointers 💻 Language: Java ⚙️ Approach: Two Pointer Technique (O(n)) 🔍 What I Learned: Handling both negative and positive numbers while keeping the array sorted after squaring — optimized using two pointers instead of sorting after squaring. ✨ Key Takeaway: Think in terms of pointers and comparisons, not just brute force — that’s how optimization begins. #Java #DSA #LeetCode #TwoPointers #CodingJourney #100DaysOfCode #PlacementPrep #LearnInPublic #CodingCommunity #JavaDeveloper
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