Today I learned about Recursion in Java, a powerful concept that helps solve complex problems by breaking them into smaller ones. A recursive method calls itself until a base condition stops it. Understanding recursion improved my logical thinking and problem-solving skills, especially for DSA topics like trees, backtracking, and divide-and-conquer algorithms. Implementing examples like factorial and Fibonacci made the concept clear and practical. Recursion is a technique where a method calls itself to solve a problem. It helps in breaking complex problems into smaller, manageable subproblems. 📌 What is Recursion? A recursive method has: 1️⃣ Base Case – Condition to stop recursion 2️⃣ Recursive Case – Method calling itself Without a base case, it leads to infinite recursion and StackOverflowError. #Java #Recursion #DSA #CodingJourney #Learning #ComputerScience
Java Recursion Explained: Breaking Down Complex Problems
More Relevant Posts
-
🚀 DSA in Java — Day 79 📌 Problem Solved: Sum Root to Leaf Numbers Today I solved the Sum Root to Leaf Numbers problem on LeetCode using Depth First Search (DFS) and Recursion. In this problem, each root-to-leaf path in a binary tree forms a number. The goal is to calculate the sum of all these numbers. 🔹 Approach Used: Used recursive DFS traversal Maintained a running number while moving from root to leaf At each step, updated the number using current = current * 10 + node.val When a leaf node is reached, added the number to the final sum 🔹 Key Concepts Practiced: ✔ Binary Trees ✔ Depth First Search (DFS) ✔ Recursion ✔ Tree Path Problems This problem improved my understanding of how recursion can be used to build values while traversing tree paths. Consistent practice is helping me become more comfortable with tree-based problems in DSA. #DSA #Java #BinaryTree #Recursion #LeetCode #CodingJourney #WomenInTech #100DaysOfCode
To view or add a comment, sign in
-
-
Day 43 of #100DaysOfLeetCode 💻✅ Solved #100. Same Tree problem in Java. Approach: • Used recursion to compare both binary trees simultaneously • If both nodes are null, returned true • If one node is null and the other is not, returned false • Checked whether the values of both nodes are equal • Recursively compared the left subtrees and right subtrees Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 43.10 MB (Beats 30.15% submissions) Key Learning: ✓ Practiced recursive traversal of binary trees ✓ Learned how to compare two trees node by node ✓ Strengthened understanding of tree recursion logic Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTrees #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA in Java – Day 72 ✅ LeetCode Problem Solved: Subsets II 🔁 Concept Used: Backtracking + Recursion 🧠 Key Focus: Handling duplicate elements correctly Today I solved Subsets II, where the main challenge was generating all unique subsets from an array that may contain duplicates. 🔑 What I learned: Why sorting the array is important before recursion How to skip duplicates using this condition: if (idx > i && nums[idx] == nums[idx - 1]) continue; Proper backtracking steps (add → recurse → remove) How recursion builds subsets step by step Learning something new every day and getting better at problem-solving 💪 #DSA #Java #LeetCode #Backtracking #Recursion #ProblemSolving #CodingJourney #DailyLearning #Consistency
To view or add a comment, sign in
-
-
🚀 DSA Learning Journey | Day 2 | Java Solved “Search in Rotated Sorted Array.” 💡 Key Idea: Applied Binary Search by determining which half of the array is sorted and narrowing the search space. ⚙ Implementation • Language: Java • Time Complexity: O(log n) • Space Complexity: O(1) 📚 Learning how binary search can be adapted to work with rotated sorted arrays. #Java #DSA #LeetCode #ProblemSolving #BinarySearch #JavaDeveloper
To view or add a comment, sign in
-
-
Day 47 of #100DaysOfLeetCode 💻✅ Solved #101. Symmetric Tree problem in Java. Approach: • Used recursion to compare the left and right subtrees of the root • If both nodes are null, the tree is symmetric at that level • If one node is null and the other is not, the tree is not symmetric • Compared the values of both nodes • Recursively checked left.left with right.right and left.right with right.left to verify mirror structure Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 43.62 MB (Beats 48.60% submissions) Key Learning: ✓ Practiced mirror comparison in binary trees ✓ Learned how recursion can verify symmetry between two subtrees ✓ Strengthened understanding of tree traversal and structural comparison Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTrees #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 38 of #100DaysOfLeetCode 💻✅ Solved #222. Count Complete Tree Nodes problem in Java. Approach: • Used recursion to traverse the binary tree • Counted the current node and recursively counted nodes in left and right subtrees • Added the counts to get the total number of nodes • Returned 0 when the node is null to stop recursion Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 44 MB Key Learning: ✓ Practiced recursion with binary trees ✓ Understood how tree traversal helps count nodes in a tree ✓ Improved recursive thinking while solving tree problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 30 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Sorting Technique 🧩 Problem Solved: Longest Common Prefix Problem: Given an array of strings, find the longest common prefix shared among all the strings. Approach: Sorted the array of strings and compared only the first and last strings. Since sorting groups similar prefixes together, the common prefix between these two strings represents the common prefix for the entire array. Key Learning: ✔️ Using sorting to simplify string comparison problems ✔️ Observing patterns to reduce unnecessary checks ✔️ Efficient prefix detection in string arrays If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 26 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search in Rotated Sorted Array 🧩 Problem Solved: Search in Rotated Sorted Array II Problem: Given a rotated sorted array that may contain duplicates, determine if a target element exists in the array. Approach: Applied a modified Binary Search. At each step, identified which half of the array was sorted and adjusted the search space accordingly. Special care was taken to handle duplicates, which can make determining the sorted half more challenging. Key Learning: ✔️ Handling duplicates in binary search problems ✔️ Identifying sorted portions in rotated arrays ✔️ Adapting classic algorithms to complex scenarios 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
-
-
✨ DSA in Java – Day 83 🚀 Today I solved an interesting problem on Binary Trees: 👉 Sum of Root to Leaf Binary Numbers 🌱 What I Learned: How to traverse a binary tree using DFS (Depth First Search) Building numbers along the path using: ➤ current = current * 2 + node.val Identifying leaf nodes and calculating final values Improving recursion understanding in tree problems 💡 Approach: Start from root with value 0 At each node, update the current number If it's a leaf node → add it to the final sum Traverse left and right recursively 📌 Key Insight: Binary tree problems become easier when you think of them as path-based problems rather than node-based problems. 💻 Consistency is the key! Day by day, step by step, getting stronger in DSA 💪 #DSA #Java #BinaryTree #CodingJourney #LeetCode #100DaysOfCode #WomenInTech #Consistency
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
-
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