DSA with Java... Today I learnt about LINEAR SEARCH... just like the name, the search is really done in a linear format. In this search, iteration goes through a collection of elements, one at a time. To find the index of an element, it checks for that element from the beginning of that array. The disadvantage is that it reduces performance for large data sets. Imagine trying to find your show in a big container of shoes and you have to go through one at a time. It's runtime complexity is O(n). The advantage also is that it's fast for small to medium data sets, doesn't need to be sorted, and useful for data structures that don't have random access like LinkedList. what are the real life situations of linear search in building softwares? drop your answers in the comments. cheers 🥂. #softwareengineering #dsa #java #linearsearch
Linear Search in Java: Advantages and Disadvantages
More Relevant Posts
-
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
To view or add a comment, sign in
-
-
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
-
-
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 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
-
-
🧠 Practicing Java, SQL & Logical Thinking in One Session Yesterday’s focused practice included three areas: 🟢 Java – Loop + Condition Simulated a loop from 1 to 5 and calculated the sum of even numbers using % 2 == 0. Even numbers: 2 and 4 → Sum = 6. Small reminder: always simulate loops step by step instead of guessing the output. 🟢 SQL – Filtering + Sorting Wrote a query to find employees from the IT department with salary > 40000 and sorted the result in descending order: WHERE filters rows, ORDER BY controls result order. 🟢 Logical Reasoning Solved a classic age problem involving ratios and future conditions. These types of questions really sharpen equation-building skills. I’m realizing that strong fundamentals across coding, databases, and logic create better problem-solving confidence overall. Building clarity across layers — not just syntax. #Java #SQL #ProblemSolving #DSA #LearningInPublic #DeveloperGrowth
To view or add a comment, sign in
-
Day 52 — LeetCode Progress (Java) Problem: Random Pick with Weight Required: Given an array of weights, randomly pick an index such that the probability of picking an index is proportional to its weight. Idea: Convert weights into a prefix sum array and use binary search on a random value to simulate weighted probability. Approach: Build a prefix sum array: prefix[i] stores cumulative weight up to index i Generate a random number: target = totalSum * Math.random() Use binary search to find the first index where: prefix[index] > target Return that index as the result. Time Complexity: Preprocessing: O(n) Query (pickIndex): O(log n) Space Complexity: O(n) #LeetCode #DSA #Java #BinarySearch #PrefixSum #Probability #Algorithms #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🧠 Revision Day – Strengthening the Basics Again Yesterday was focused on strengthening fundamentals. ✔️ Java – Datatypes, Variables, If/else, Loops, 1D Arrays ✔️ SQL – SELECT, WHERE, AND/OR, BETWEEN, ORDER BY Instead of just reading, I rewrote examples and queries from memory. Real confidence comes from revisiting basics calmly and consistently. #Java #SQL #Consistency #LearningInPublic #BackendJourney
To view or add a comment, sign in
-
💡 A Quick & Powerful Look at Number Systems Ever wondered how your Java code actually stores numbers? 🤔 🖥️ Computers Think in Binary (Base 2) Only 0s and 1s. While humans use: 🔢 Decimal (Base 10) 🔡 Hexadecimal (Base 16) ⸻ 🔄 Let’s Convert 20 (Decimal) to Binary 20 → 10100 Now verify: 1×2⁴ + 0×2³ + 1×2² + 0×2¹ + 0×2⁰ = 16 + 4 = 20 ✅ Binary is just positional math. ⸻ 🧠 How Java Stores Integers In Java: • int = 32 bits • MSB (leftmost bit) = Sign bit Negative numbers use Two’s Complement: 1. Reverse all bits 2. Add 1 This allows subtraction to be performed using addition internally ⚡ ⸻ ⚙️ Bitwise Operators & → AND | → OR ^ → XOR ~ → NOT << → Left Shift → Signed Right Shift → Unsigned Right Shift ⸻ 🚀 Useful Bit Tricks ✔ Even/Odd → n & 1 ✔ Power of 2 → (n & (n-1)) == 0 ✔ Remove rightmost set bit → n & (n-1) ✔ Isolate rightmost set bit → n & (-n) ⸻ 🔥 Understanding bits improves: • Algorithm efficiency • Memory optimization • System-level thinking #Java #BitManipulation #Programming #BackendDevelopment
To view or add a comment, sign in
-
Day 50 — LeetCode Progress (Java) Problem: Range Sum Query – Immutable Required: Design a data structure that can return the sum of elements between indices left and right (inclusive) efficiently for multiple queries. Idea: Precompute a prefix sum array so each query can be answered in O(1) time instead of recalculating sums repeatedly. Approach: Build a prefix array where: prefix[i] = sum of elements from index 0 to i During initialization: Traverse the array once Keep a running sum and store it in prefix For each query sumRange(left, right): If left == 0 → return prefix[right] Else → return prefix[right] - prefix[left - 1] Time Complexity: Preprocessing: O(n) Query: O(1) Space Complexity: O(n) #LeetCode #DSA #Java #PrefixSum #Algorithms #CodingJourney #100DaysOfCode
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
-
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