Day 85 of the coding journey and tackling a classic interview problem: Inorder Traversal of a Binary Tree! 🌳 While recursion is the most intuitive approach, I implemented the incredibly efficient Morris Traversal algorithm. The beauty of Morris Traversal? It achieves O(N) time complexity with only O(1) auxiliary space! It smartly avoids the stack overhead by temporarily modifying the tree links (creating "threads") and then restoring them. Key Idea: Establish a temporary link from a node's Inorder Predecessor to the node itself. Use this link to find your way back up, process the node, and then cut the link to restore the original structure. A satisfying problem to solve with a highly optimized technique! 💪 #100DaysOfCode #DataStructures #Algorithms #BinaryTree #MorrisTraversal #Python #CodingChallenge #InorderTraversal
Solved Inorder Traversal of Binary Tree with Morris Traversal
More Relevant Posts
-
🚀Day 80 of #100DaysOfDSA 🚀 Solved LeetCode 451 — Sort Characters By Frequency 🔹 Problem: Sort a string based on the frequency of its characters in descending order. 🔹 Approach: Used Hash Map + Sorting 1️⃣ Count frequency of each character using a dictionary 2️⃣ Sort characters by their frequency (descending) 3️⃣ Rebuild the string by repeating characters based on count ✨ Key Insight: Hash maps are great for frequency counting, and sorting by values helps in many pattern-based problems. #LeetCode #DSA #Python #ProblemSolving #HashMap #Sorting #CodingJourney #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
“𝐖𝐚𝐢𝐭… Did I just 𝐭𝐮𝐫𝐧𝐞𝐝 𝐚 𝐯𝐢𝐝𝐞𝐨 𝐢𝐧𝐭𝐨 𝐀𝐒𝐂𝐈𝐈?!” 🤯 What happens when a programmer gets bored of watching normal videos? They make the video watch itself — in text. Introducing 🅰🆂🅲🅸🅸🅵🆈 — my Python script that says: “Why use pixels when you can suffer with ASCII characters?” It literally turns videos into moving text art — right inside your terminal. Built with: Python + OpenCV + NumPy Features: 🔹 Real-time playback 🔹 Custom width (for when you want widescreen… in text 😂) 🔹 0% productivity, 100% coolness Watch your video become a masterpiece of symbols, dots, and chaos: 👉 GitHub: https://lnkd.in/e3jG6pCt #Python #OpenCV #ASCIIArt #DataScience #Coding #Innovation #DeekshitaNaik #GitHubProjects #PythonDeveloper #ASCIIArt #CodeHumor #TerminalThings #DevLife #FunProjects
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟯𝟵 𝗼𝗳 #𝟭𝟴𝟬𝗗𝗮𝘆𝘀𝗢𝗳𝗖𝗼𝗱𝗲 Today, I built on the first/last occurrence solution to 𝗰𝗼𝘂𝗻𝘁 𝗼𝗰𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝗲𝘀 𝗼𝗳 𝗮 𝘁𝗮𝗿𝗴𝗲𝘁 𝗶𝗻 𝗮 𝘀𝗼𝗿𝘁𝗲𝗱 𝗮𝗿𝗿𝗮𝘆 𝘄𝗶𝘁𝗵 𝗱𝘂𝗽𝗹𝗶𝗰𝗮𝘁𝗲𝘀. Using the same lower_bound and upper_bound helpers: Lower bound → first index where element ≥ target Upper bound → first index where element > target The count is simply: count = upper_bound - lower_bound This gives an O(log n) solution — much faster than scanning the entire array, especially with many duplicates. It’s a great example of how breaking a problem into reusable pieces leads to clean and efficient code. Perfect for analytics, frequency analysis, and search optimizations! 📊 #Python #Algorithms #BinarySearch #FrequencyCount #Coding #ProblemSolving
To view or add a comment, sign in
-
-
Here’s the extra, practical note to pair with the visual—short, formal, and a bit punchy: VS Code tip (exact action): when configuring sns.displot(...), type kind= and leave the cursor right after the equals sign. Press Ctrl + Space to display the full list of valid chart types and insert one instantly. Minimal friction, faster exploration. #Python #Seaborn #DataVisualization #Analytics #DataScience
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 102 Problem: Construct Binary Tree from Inorder & Postorder Traversal 🌳🧠 This classic tree reconstruction problem is one of those fundamental challenges that strengthens your understanding of traversal orderings, recursion, and subtree boundaries. 🧠 Problem Summary: You're given two arrays: Inorder traversal of a binary tree Postorder traversal of the same tree Your task → Reconstruct the original binary tree and return its root. ⚙️ My Approach: This problem is solved by leveraging how traversal orders work: 1️⃣ Postorder traversal ends with the root node of the current subtree. 2️⃣ Using the inorder array, we can find the position of this root and determine: Left subtree range Right subtree range 3️⃣ Build the tree recursively, always consuming elements from the end of the postorder list. 📌 Key Observations: Postorder: Left → Right → Root Inorder: Left → Root → Right The last element in postorder identifies the root at each recursive step. We construct the right subtree first, then the left, because the postorder list is consumed from the end. 📈 Complexity: Time: O(n) → Each node processed once, and indexing is O(1). Space: O(n) → For the recursion stack + hash map. ✨ Key Takeaway: Tree reconstruction problems become easy once you identify the traversal patterns. Using index maps and recursion allows a clean and optimal solution. 🌳💡 🔖 #DSA #100DaysOfCode #Day102 #BinaryTrees #TreeConstruction #Recursion #LeetCode #ProblemSolving #Python #AlgorithmicThinking #TechCommunity #CodeEveryday #LearningByBuilding
To view or add a comment, sign in
-
-
365 Days of DSA – #Day193: Insert Interval ➕📅 Today’s challenge — Insert a new interval into a list of non-overlapping intervals and merge when needed! This problem tests interval handling, merging logic & careful pointer movement. 🧠 Approach summary: 🔹 Add all intervals ending before the new one 🔹 Merge overlapping intervals with the new range 🔹 Append the rest untouched Result: clean & efficient interval insertion! ⚡ #Day193 #365DaysOfDSA #Intervals #GreedyAlgorithm #LeetCode #Python #ProblemSolving #DSA #CodingChallenge #LogicBuilding
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟯𝟲 𝗼𝗳 #𝟭𝟴𝟬𝗗𝗮𝘆𝘀𝗢𝗳𝗖𝗼𝗱𝗲 Today, I solved 𝗦𝗲𝗮𝗿𝗰𝗵 𝗜𝗻𝘀𝗲𝗿𝘁 𝗣𝗼𝘀𝗶𝘁𝗶𝗼𝗻 — a practical variation of binary search. The goal was to find the index of a target in a sorted array, or the position where it should be inserted to maintain order. Using binary search, I efficiently located the correct spot in O(log n) time. The key was to track the first position where the element is greater than or equal to the target — which is exactly the insert position if the target isn’t found. This is a great example of how small tweaks to a classic algorithm can solve new problems elegantly. A useful technique for search, insertion, and maintaining sorted data dynamically! #Python #Algorithms #BinarySearch #LeetCode #Coding #ProblemSolving
To view or add a comment, sign in
-
Explore related topics
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