Day 4 of DSA Practice : Today I learned about Bubble Sort and understood how we can optimize it step by step. 🔹 Approaches Learned: Basic Bubble Sort: O(n²) Optimized Bubble Sort (Early Exit using a flag): Best Case O(n), Worst Case O(n²) ✅ Key Idea (Bubble Sort): We repeatedly compare adjacent elements and swap them if they’re in the wrong order. After each pass, the largest element “bubbles up” to the end of the array. 🚀 Optimization (Early Exit): If in any pass no swaps happen, the array is already sorted — so we stop early. ⚡ Complexity: Time: Worst O(n²), Best O(n) (already sorted with optimization) Space: O(1) This sorting method is great for learning sorting basics and understanding swapping-based sorting. #DSA #Programming #CompetitiveProgramming #Java #Cplusplus #Python #Learning
Bubble Sort Optimization: O(n) Best Case
More Relevant Posts
-
𝑴𝒚 𝒊𝒏𝒔𝒊𝒈𝒉𝒕𝒔 𝒘𝒉𝒊𝒍𝒆 𝒄𝒐𝒎𝒑𝒂𝒓𝒊𝒏𝒈 '𝑴𝒚 𝒄𝒐𝒅𝒆' 𝒕𝒐 𝒕𝒉𝒆 '𝑺𝒐𝒍𝒖𝒕𝒊𝒐𝒏 𝑪𝒐𝒅𝒆' 🙄 To be honest, I've only recently started using functions and using comments in my code... since I didn't know that they were so handy 😅 But when I look at the solution, it feels like: "Wow! You just have to look once to get what's happening in there 😮" And hence, I started using 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬 and 𝐂𝐨𝐦𝐦𝐞𝐧𝐭𝐬 in my code which made it look less messy and more understandable 😁 I guess, just 'making the code work and give the desired solution' is not the only step, but making it more READABLE and UNDERSTANDABLE is what makes the code more awesome 😆 (It helps to solve bugs easily too 👍) Suggestions and Insights are appreciated 🙌✨ #Python #Programming #CSE #StudentDeveloper #LearningWhileCoding
To view or add a comment, sign in
-
Python with DSA — Day 33 What I worked on: Prime checks: moved from naive divisibility to the √n optimization and the 6k±1 rule to cut unnecessary iterations. Time complexity intuition: compared O(n) vs O(√n) for primality tests; saw how early exits change best/worst cases. Clean loops & edge cases: handled n <= 1, negative inputs, and printed primes from 1–100 with a tight loop. Key snippet (conceptual): Idea: Only test divisors up to √n; if none divide, the number is prime. #Day33 #PythonWithDSA #DataStructures #DSAJourney #ProblemSolving #PythonProgramming #SoftwareEngineer
To view or add a comment, sign in
-
-
🗓 Day 66 / 100 – #100DaysOfLeetCode 📌 Problem 865: Smallest Subtree with All the Deepest Nodes Today’s problem focused on binary tree depth analysis. The goal was to find the smallest subtree that contains all the deepest nodes in the tree. 🧠 My Approach: Used Depth-First Search (DFS) to compute information bottom-up. For each node, tracked: the maximum depth reachable from that node, and the candidate subtree root that contains all deepest nodes. Compared depths of left and right subtrees: If both sides have the same depth → the current node is the answer. Otherwise, propagated the deeper side upward. Returned the node that satisfies the condition for all deepest nodes. This approach cleanly combines depth calculation with subtree selection in a single traversal. 💡 Key Learning: This problem reinforced: ✔ how returning multiple values from DFS simplifies logic ✔ thinking bottom-up for tree optimization problems ✔ identifying the exact node where depths converge Tree problems often become elegant once the right recursive structure is identified 🌳🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #BinaryTree #DFS #TreeTraversal #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
Problem: Print Elements of a Linked List Concepts: Linked List Traversal | Pointers | Iteration Difficulty: Easy Problem Summary: Given the head of a singly linked list, traverse the list and print the data of each node line by line. If the head is NULL, nothing should be printed. This problem focuses on understanding how to move through nodes using pointers and access data stored in each node. Key Learnings: A linked list is traversed using a temporary pointer that starts at the head Each node stores both data and a next pointer Traversal continues until the pointer becomes NULL Proper pointer movement is essential to avoid infinite loops GitHub Link:https://lnkd.in/dfxDCKdq #Day40 #DSA #LinkedList #ProblemSolving #DataStructures #Coding #Python #Cplusplus #LearningInPublic #50DaysChallenge #TechJourney
To view or add a comment, sign in
-
-
✅ Day 10 of 100 Days LeetCode Challenge Problem: 🔹 #1448 – Count Good Nodes in Binary Tree 🔗 https://lnkd.in/gDfr48AK Concepts Used: 🔹 Binary Tree 🔹 Depth-First Search (DFS) 🔹 Recursion 🔹 Path-based State Tracking Approach Summary: 🔹 Used DFS to traverse the tree from root to leaves. 🔹 Maintained the maximum value (maxi) seen so far along the path. 🔹 A node is considered good if its value is greater than or equal to maxi. 🔹 Updated maxi at each step and accumulated the count recursively. Key Insight: 🔹 “Good nodes” depend on the path from the root, not the entire tree. 🔹 Passing state (maximum so far) through recursion avoids extra storage. 🔹 This leads to a clean and efficient solution with optimal traversal. #LeetCode #100DaysOfLeetCode #Day10 #DSA #Daily #Programming #ProblemSolving #Python #CodingJourney #TechCareers
To view or add a comment, sign in
-
-
🚀 DSA Learning Challenge – Day 4 / 90 (Python) 🐍 Day 4 of my 3-month DSA journey was all about handling multiple values together instead of one by one. 📌 Day 4 Focus: Arrays (One box with many values) 🧠 What I learned today: ✔ What an array is 👉 Array = one box that stores many values 📦📦📦 ✔ Why arrays are useful (no need for many variables) ✔ Index concept 👉 Index always starts from 0 ✔ How to read an array using a loop ✔ Using arrays to print elements and find sum ✍ Algorithm Thinking (No code yet): Problem 1: Print all elements of an array [2, 4, 6] Start from index 0 Print the element at the current index Increase the index by 1 Repeat until the last index Problem 2: Find the sum of array [1, 2, 3, 4] Initialize sum as 0 Start from index 0 Add current element to sum Increase index by 1 Repeat until the last index Print the sum 💡 Today’s biggest learning: Array + loop = powerful combination 🎯 Goal: Build strong DSA fundamentals using Python, starting from absolute basics and improving step by step. 📅 Day 4 completed. Day 5 loading… 🚀🔥 #DSA #Python #Arrays #LearningInPublic #ProgrammingBasics #LogicBuilding #MCA #Consistency #FutureDeveloper
To view or add a comment, sign in
-
-
📘 GATE 2026 Preparation | Day 40 Update Day 40 was about practice, revision, and understanding internals, not just surface-level learning. 🔹 What I worked on yesterday: COA: Practiced Memory Mapping questions Operating Systems: Revised CPU Scheduling Revised Process States Aptitude: Solved a few practice questions Python Programming (Class 2): Studied Functions Understood the internal working of Python’s Global Dictionary Learned how Python manages names, scopes, and execution internally 🔹 Key learning: Strong preparation is not only about solving problems, but also about knowing how systems and languages work internally. Next focus: More PYQs, deeper revision, and consistent Python practice alongside GATE prep. #GATE2026 #COA #OperatingSystems #CPUScheduling #MemoryMapping #PythonInternals #Aptitude #DailyProgress #Consistency #GATEreadywithGfG
To view or add a comment, sign in
-
-
🚀 Day 19: Python Range Deep Dive Today is all about the power of the range() function! It’s not just for loops; it’s a memory-efficient sequence generator. Key takeaways: ✅ Custom Steps: Use range(start, stop, step) to skip numbers ✅ Smart Membership: Use in to instantly check if a number fits the sequence logic ✅ Efficient Length: len() tells you the count without expanding the list x = range(3, 10, 2) print(list(x)) # Output: [3, 5, 7, 9] r = range(0, 10, 2) print(6 in r) # Output: True print(7 in r) # Output: False print(len(r)) # Output: 5 Small steps every day lead to big results in 2026! 💻✨ Stay tuned for more!!! #Python #PythonJourney #Coding #LearnToCode #Programming #PythonCode #DataAnalyst #DataAnalytics #RangeFunction
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