DSA with Java.... Today I learnt about insertion sort algorithm. This algorithm starts at index 1, compares elements to the left and shifts elements to the right to insert a value. It has a complexity of 0(n^2) which is quite decent for small datasets but terrible for large datasets. It has less steps than bubble sort and it's best case scenario is 0(n) compared to selection sort, 0(n^2). I implemented insertion sort with Java to understand how the computer operates with such algorithm. Out of all these algorithms, which do you consider best to use in business applications? Cheers 🥂 #dsa #java #insertionsort #softwareengineering
Java Insertion Sort Algorithm Overview
More Relevant Posts
-
🔍 Linear Search in Java | DSA Practice Implemented Linear Search algorithm in Java as part of my DSA learning journey. 📌 What it does: Searches for a target element in an array by checking each element one by one. Returns the index if found, otherwise prints “Element not found”. 🧠 Concepts used: ∙ Array traversal using for loop ∙ Index tracking with a flag variable (index = -1) ∙ Early exit using break for efficiency #java #dsa #problem #solution #datastructure #algorithm #linearsearch
To view or add a comment, sign in
-
-
Leveling up my searching algorithms! Today’s Java DSA topic: Binary Search. After exploring the brute-force nature of Linear Search, moving to Binary Search. Instead of checking every single element one by one O(n), Binary Search slashes the time complexity to O(log n). The catch? The array must be sorted first! (Good thing I just covered sorting algorithms). The logic is brilliant and incredibly efficient: 1. Find the middle element. 2. If it matches the target, you're done! 3. If the target is smaller, discard the right half. If larger, discard the left. 4. Repeat. #DSA #Java #BinarySearch
To view or add a comment, sign in
-
-
🚀 Day 37 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Squares of a Sorted Array Problem: Given a sorted array of integers (including negatives), return a new array of the squares of each number, also sorted in non-decreasing order. Approach: Used a two-pointer approach from both ends of the array. Compared squares of elements and filled the result array from the end to maintain sorted order efficiently. Key Learning: ✔️ Handling negative values in sorted arrays ✔️ Using two-pointer technique for optimal solutions ✔️ Avoiding extra sorting to achieve O(n) time complexity If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
𝗥𝗲𝗰𝗨𝗿𝘀𝗶𝗼𝗻 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 You need to find the factorial of a number using recursion. For example, 5! is 5 × 4 × 3 × 2 × 1 = 120. To solve this problem, you can use a recursive function in Java. Here's how it works: - The function calls itself with a smaller input until it reaches the base case. - The base case is when the input is 1, at which point the function returns 1. - The function then returns the product of the current number and the result of the recursive call. You can use debug prints to see how the function works. Here's an example of what the debug output might look like: - Calling fact(5) - Base case reached: fact(1) = 1 - Returning from fact(2) = 2 - Returning from fact(3) = 6 - Returning from fact(4) =
To view or add a comment, sign in
-
Mastering Java & DSA Through LeetCode Day 34 Today I solved a Medium-level Tree problem that strengthened my understanding of Prefix Sum + DFS — a powerful pattern used in many interview questions. LeetCode Problem: 437. Path Sum III Problem Summary: Given a binary tree and a target sum, we need to find the number of paths where the sum of node values equals the target. The path must go downward (parent → child), but it doesn’t need to start from the root. Key Insight: Instead of checking all possible paths (which is inefficient), we use: Prefix Sum HashMap to store frequencies DFS traversal This helps reduce time complexity from O(n²) → O(n) ⚡ Approach: Maintain a running sum while traversing the tree Check if (currentSum - target) exists in the map Use backtracking to maintain correct state What I Learned: How prefix sum works in trees (not just arrays!) Optimizing brute-force solutions Importance of hashmap in reducing complexity Consistency Update: Day 34 of solving DSA problems daily 💪 Small steps every day = big results over time #LeetCode #Java #DSA #CodingJourney #100DaysOfCode #SoftwareEngineering #PlacementPreparation #CodingInterview
To view or add a comment, sign in
-
-
🚀 Day 16/105 – Java + DSA Journey Today I explored the fundamentals of Sorting Algorithms in Java. 📌 Topics Covered: • What is Sorting • Bubble Sort • Selection Sort • Insertion Sort Understanding these basic sorting techniques helped me build a strong foundation in data organization and algorithm thinking. Each algorithm has its own approach and efficiency, which makes problem-solving more interesting. Consistently improving my DSA skills step by step 💻 #Java #DSA #105DaysChallenge #PlacementPreparation #LearningInPublic #Consistency #DSABasicFundamentals #ApnaCollege #RajTech #Day16
To view or add a comment, sign in
-
🚀 Day 36 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search (Peak Finding) 🧩 Problem Solved: Find Peak Element Problem: Given an array, find a peak element (an element greater than its neighbors) and return its index. Approach: Used Binary Search by comparing the middle element with its neighbors. Based on the increasing or decreasing slope, moved towards the side where a peak must exist, reducing the search space efficiently. Key Learning: ✔️ Applying binary search on unsorted arrays using patterns ✔️ Understanding how slope direction guides decisions ✔️ Solving peak problems in O(log n) time If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Shifting from Sorting to Searching in Java DSA! After learning sorting algorithm from basics to complex like recursion of Quick and Merge sort, today I started searching algorithm like Linear Search. It is as straightforward as it gets: 1. Start at the beginning of the array. 2.Check every single element one by one. 3. Stop when you find the target. With a time complexity of O(n), it isn't the most efficient algorithm for massive datasets. However, it doesn't require the array to be sorted first, which makes it a great reminder that sometimes a simple, brute-force approach is exactly what you need for small, unsorted data. #DSA #Java #LinearSearch
To view or add a comment, sign in
-
-
Leetcode Practice - 16. 3Sum Closest The problem is solved using JAVA Given an integer array nums of length n and an integer target, find three integers at distinct indices in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Example 1: Input: nums = [-1,2,1,-4], target = 1 Output: 2 Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). Example 2: Input: nums = [0,0,0], target = 1 Output: 0 Explanation: The sum that is closest to the target is 0. (0 + 0 + 0 = 0). Constraints: 3 <= nums.length <= 500 -1000 <= nums[i] <= 1000 -104 <= target <= 104 #LeetCode #Java #CodingPractice #ProblemSolving #DSA #Array #DeveloperJourney #TechLearning
To view or add a comment, sign in
-
-
Day 66 of #100DaysOfLeetCode 💻✅ Solved #3427. Sum of Variable Length Subarrays problem in Java. Approach: • Iterated through each index of the array • Determined the starting index using i - nums[i] • Ensured the start index does not go below 0 • Calculated sum of elements from start to current index i • Added each subarray sum to the total Performance: ✓ Runtime: 1 ms (Beats 99.90% submissions) ✓ Memory: 45.22 MB (Beats 56.30% submissions) Key Learning: ✓ Practiced handling variable-length subarrays ✓ Improved understanding of index-based range calculations ✓ Strengthened nested loop logic for array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #PrefixSum #ProblemSolving #CodingJourney #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
Optimizing algorithms is vital. Insertion sort shines with its simplicity.