🚀 #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
Implementing Linear Search in Java for DSA
More Relevant Posts
-
🔥 #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
To view or add a comment, sign in
-
-
💻 Day 7 of My DSA in Java — Find Duplicates in an Array. Today’s challenge focused on detecting duplicate elements in an array — but with a twist 👉 only using nested for loops (no HashSet, no Collections, just logic and iteration). 🔍 Problem Given an array, identify all elements that appear more than once. 📘 Example: Input → [11, 22, 33, 44, 33, 55] Output → Duplicate elements: 33 ⏱ Time Complexity: O(n²) 💾 Space Complexity: O(1) 💬 Key Takeaway: Even though this is a basic brute-force approach, it strengthens your understanding of nested loops, element comparison, and control flow. Before diving into optimized solutions, mastering these fundamentals helps you build logical clarity and confidence in problem-solving. 🚀 #Day7 #DSA #Java #CodingJourney #KeepLearning #CodeDaily #IntelliJ
To view or add a comment, sign in
-
-
Hii Connections 👋 I recently solved an interesting problem in Java: Problem: Count the number of pairs in an array that have a specific difference d. My Approach: I used the two-pointer technique for an optimized solution: Start with two pointers, left and right. Compare the difference between the elements at these pointers. If the difference < d, move right forward. If the difference == d, increment the count and move both pointers. If the difference > d, move left forward. This avoids unnecessary comparisons and runs in O(n) for a sorted array, unlike the brute-force O(n²) approach. What I Learned: ✅ Two-pointer technique is super powerful for array problems. ✅ Thinking in terms of patterns rather than brute force makes code efficient. ✅ Small optimizations can drastically improve performance. Sharing my journey and progress on DSA practice! #Java #DSA #Coding #ProblemSolving #TwoPointers #LeetCode #LearningEveryday #CodeNewbie
To view or add a comment, sign in
-
-
✅ #PostLog28 Search in Rotated Sorted Array (Problem #33) Problem tested my understanding of binary search in modified arrays — where the array is rotated at an unknown pivot. 🧠 Concept learned: Even though the array is rotated, one half of it is always sorted. By identifying which half is sorted, we can efficiently narrow down our search range — still achieving O(log n) complexity! ⚙️ Approach Summary: Use binary search. Check if the left or right half is sorted. Move search boundaries accordingly based on the target’s range. 💻 Language: Java 📈 Result: Accepted ✅ — 0 ms runtime (beats 100%) #LeetCode #Java #CodingChallenge #DSA #BinarySearch
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
-
-
Today’s session focused on understanding Time Complexity (TC) and Space Complexity (SC) — essential concepts for writing optimized code. To apply these concepts, I practiced several Java programs and analyzed their efficiency: ✔ Programs Practiced • Reverse an array TC: O(n) (single loop) SC: O(1) (in-place) • Find the maximum of two numbers TC: O(1) SC: O(1) • Linear Search TC: O(n) SC: O(1) • Binary Search TC: O(log n) (halve the search space) SC: O(1) Understanding TC and SC helped me evaluate how efficient my solutions are and how to choose the best approach depending on the problem. Karthikeyan A Learning to think not just about correctness, but performance, is a major step in problem-solving and DSA. Excited to keep improving every day! 🚀 #Java #TimeComplexity #SpaceComplexity #DSA #ProblemSolving #CodingJourney #LearningInPublic #SparkTribe #SoftwareDevelopment #ContinuousLearning
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
-
-
Day 3 - Extending Frequency Logic to Handle Negative Integers Hello Connections, Continuing my DSA with Java journey, today I took yesterday’s concept of frequency mapping and applied it to a more flexible scenario - counting integer frequencies even when the numbers include negatives. Problem I Solved: Count the frequency of integers within a given range including negative values. Example: Range → max = 5, min = -5 Numbers → 1, -1, -3, -1, 4, 2 Output should show frequency for every number from -5 to +5 My Approach: Yesterday, I used ASCII values to map letters into array indexes. Today, I applied the exact same idea to integers. Step 1: Finding the Range: To store frequencies from min to max, I need an array that has enough slots for every integer in between. So the range is calculated using: range = max - min + 1; Step 2: Mapping Any Number to an Array Index: Since Java array indexes start from 0, we shift each number relative to min, index = number - min; This creates a direct-access table where every integer has its own slot. Understanding how to calculate the range and map numbers to indexes made this problem simple and elegant. It’s amazing how the same idea from Day 2 can scale to more complex scenarios and I think that’s the real beauty of DSA. Excited for day 4! #dsawithjava #dsa #java
To view or add a comment, sign in
-
-
#Day_28 Today’s problem was quite an interesting one — “Reach a Target Number” using minimal moves. 💡 Problem Summary: Starting from 0, on each move i, you can go either left or right by i steps. The goal is to find the minimum number of moves required to reach a given target. At first glance, it looked like a simple math problem, but the trick was to notice the parity condition — once the cumulative sum goes beyond the target, the difference (sum - target) must be even to allow flipping directions and still land exactly on target. Here’s the optimized logic I implemented in Java Key Takeaway: Sometimes, problems that look complex are just about observing patterns in numbers rather than brute force. A touch of math can simplify the entire logic! #100DaysOfCode #LeetCode #CodingChallenge #Java #ProblemSolving #DSA #LearnEveryday #CodingJourney
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
-
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