📚🌃 Continuing my dive into data structures and algorithms. 🙂 🌳 Tonight’s Focus: Chapter 19 – Binary Tree Traversal In linear structures like arrays or linked lists, we move step-by-step: 0️⃣ ➡️ 1️⃣ ➡️ 2️⃣ ➡️ 3️⃣ But trees are hierarchical 🌳, so we use a different approach: Breadth-First 🔺 and Depth-First 🐋 Traversal ✅ FYI -Tree depth helps us understand how far a node is from the root -The goal is to visit every node and represent the full structure ⚙️ Traversal Basics Each node goes through two phases: Discovered Collection – We identify a node (starting from the root) and add it to this list as soon as it's found. Explored Collection – After a node is discovered, we examine its children. Once all its children have been discovered, we move the node to this list. 🔺 Breadth-First Traversal -Uses a queue (First In, First Out) -Visits nodes level by level, left to right, moving nodes from the discovered to explored collection as they are processed -Example order: A → B → C → D → E… 🐋 Depth-First Traversal -Uses a stack (Last In, First Out) -Nodes are discovered by traversing deep down the left-most path, then backtracked to the nearest unexplored node. During processing, nodes are moved from the discovered collection to the explored collection. ⚡ Performance Time: O(n) Space: O(n) Same across best, average, and worst cases 📚 Might just do half a chapter for the more involved chapters next. If you’re learning too (or just love emoji-powered breakdowns), follow along for more chapters in this series! 🚀 #JavaScript #Algorithms #Coding #DevNotes
Learning Binary Tree Traversal: Breadth-First and Depth-First
More Relevant Posts
-
📚🌃 Continuing my dive into data structures and algorithms. 🙂 🫧 🔁 🫧 Tonight’s focus: Chapter 22: Bubble Sort ❌ Bubble Sort is one of the simplest sorting algorithms, but also one of the most inefficient. It’s often taught not because it’s fast, but to help you recognize and avoid sluggish 🐌 sorting patterns in your own code. ⚙️ How Bubble Sort Works -Start at the beginning of the list. -Compare each pair of adjacent elements. -If the first is greater than the second, swap them. -Move one step forward and repeat the comparison. -Once you reach the end, go back to the beginning and repeat the process. -Continue this cycle until all items are sorted. -When it runs a full pass with no swaps, the list is officially sorted. ✅ Key Notes -Its best-case scenario is a sorted list, ironically, the one time you don’t need a sort. -It’s slowest when the list is in reverse order because every element needs to be moved. ⚡🐢🐌 Performance -Time complexity: Worst and average case is O(n²). -Even small lists can take many steps, sorting 4 numbers might involve 8+ steps. -Requires multiple passes through the list. It will still pass through elements that have already been sorted, so it’s inefficient for large datasets. If you're learning too, or just love a good emoji-powered breakdown, follow along for more chapters in this series! 🚀 #JavaScript #Algorithms #Coding #DevNotes
To view or add a comment, sign in
-
📚🌃 Continuing my dive into data structures and algorithms. 🙂 🔍 Tonight’s focus: Chapter 24: Selection Sort ⚙️ How Selection Sort Works -Assume the first item is the smallest. -Scan the entire list to find the actual smallest item. 🔎 -Swap it with the first item and add it to the sorted region. -Move to the next unsorted item and repeat: ----Assume it's the smallest. ----Compare it with the rest of the unsorted region. ----Swap the new smallest into place in the sorted region. -Continue until all items are sorted! ✅ Key Notes -Splits the list into a sorted region (usually at the front) and an unsorted region. -Swaps each new smallest item into place, expanding the sorted region one item at a time. -Simple to understand and implement, but not very efficient. ⚡ Performance -Time: O(n²) -Space: The items sort in their place, so memory usage is minimal. -Not ideal for large datasets. -Slightly less practical than Insertion Sort, but still a good learning tool. 💻 Implementation Tips -Outer loop (i): tracks the boundary between sorted and unsorted. -Inner loop (j): finds the smallest item in the unsorted region. -Swap smallest item with the first unsorted item. If you're learning too, or just love a good emoji-powered breakdown, follow along for more chapters in this series! 🚀 #JavaScript #Algorithms #Coding #DevNotes
To view or add a comment, sign in
-
📚🌃 Continuing my dive into data structures and algorithms. 🙂 🕸️ Tonight’s Focus: Chapter 20 – Graph Traversal (DFS & BFS) Unlike trees, graphs aren’t always hierarchical. They can be messy, interconnected, and unpredictable. So how do we explore them? With two trusty tools: Depth First 🐋 and Breadth First 🧭 Search ✅ FYI Graphs can represent anything from social networks to maps to recommendation systems We explore them to uncover all reachable nodes and understand their connections At the start, we only see one node. The rest are hidden until discovered ⚙️ Traversal Basics Each node goes through two phases Discovered Collection – Nodes are added here as soon as they’re found Explored Collection – Once all discovered neighbors of a node have been checked, the node moves here 🐋 Depth First Search (DFS) Uses a stack (Last In, First Out) Goes deep into one path before backtracking Newly discovered nodes are added to the beginning of the list Example path: A → B → C → E → F → G… 🧭 Breadth First Search (BFS) Uses a queue (First In, First Out) Explores level by level, checking all immediate neighbors before moving outward Newly discovered nodes are added to the end of the list Example path: A → B → C → D → E… ⚙️ Discovery Order DFS: Order depends on how neighbors are listed and pushed BFS: Order follows the queue. First discovered, first explored ⚡ Performance Time: O(n) Space: O(n) Same across best, average, and worst cases. Depends on graph size and structure 📚 These chapters are getting deeper. Might split them up going forward If you’re learning too (or just love emoji-powered breakdowns), follow along for more chapters in this series 🚀 #JavaScript #Algorithms #Coding #DevNotes
To view or add a comment, sign in
-
📚🌃 Continuing my dive into data structures and algorithms. 🙂 🃏↪️🃏Tonight’s focus: Chapter 23: Insertion Sort Insertion Sort is like organizing cards 🃏 in your hand one at a time, you compare and place each card in its correct spot. ⚙️ How Insertion Sort Works -Start with the second item in the list (the first item is considered sorted). -Mark it as the active item. 📌 -Compare the active item to the items on its left (aka the sorted region). -Keep shifting left until you find a value smaller than the active item, then insert it to the right. -Repeat for each item in the unsorted region, reassigning the active item 📌 each time. ✅ Key Notes -Follows a “look left” approach: each new active item 📌 is compared to those before it, one by one, moving toward the first index, until it finds a value that is less than itself. ⚡ Performance -Time: O(n²) in the average and worst case. Best case (already sorted): O(n). -Space: Uses constant memory, no extra space needed. -Not ideal for large datasets, but useful when memory is limited, the list is mostly sorted. -Ok for small data sets. If you're learning too, or just love a good emoji-powered breakdown, follow along for more chapters in this series! 🚀 #JavaScript #Algorithms #Coding #DevNotes
To view or add a comment, sign in
-
🚀 DSA Challenge – Day 93 Problem: Find Median from Data Stream 📊⚙️ This was an exciting deep dive into data structures and real-time computation — maintaining the median efficiently while continuously adding numbers from a stream. 🧠 Problem Summary: You need to design a class MedianFinder that can: ✅ Add numbers dynamically from a data stream. ✅ Return the median at any point in time. If the total number of elements is even → median = mean of the two middle values. If odd → median = middle value. ⚙️ My Approach: 1️⃣ Use two heaps to maintain balance: A max heap (maxHeap) for the smaller half of numbers. A min heap (minHeap) for the larger half. 2️⃣ Whenever a new number arrives: Push it into the maxHeap (inverted to simulate max behavior). Balance both heaps so that their size difference is never more than 1. 3️⃣ Ensure heap order: the maximum in maxHeap ≤ minimum in minHeap. 4️⃣ The median is: The top of the larger heap (if odd count). The average of both tops (if even count). 📈 Complexity: Time: O(log n) → For insertion and heap balancing. Space: O(n) → To store all elements in heaps. ✨ Key Takeaway: This problem highlights how heaps can turn complex real-time median calculations into a smooth, efficient process — a great example of data structure synergy in action. ⚡ 🔖 #DSA #100DaysOfCode #LeetCode #ProblemSolving #Heaps #PriorityQueue #DataStructures #Algorithms #Median #Python #CodingChallenge #InterviewPrep #EfficientCode #DynamicProgramming #TechCommunity #LearningByBuilding #CodeEveryday
To view or add a comment, sign in
-
-
🚀 Days 41–56 of #100DaysOfCoding: Strengthening Problem-Solving with Arrays & NumPy Over the past 16 days, I’ve focused on building a solid foundation in data structures and numerical computing. This phase has been about improving efficiency, mastering algorithmic thinking, and understanding data manipulation at a deeper level. 🔹 Core Array Problems Solved: 1️⃣ Find Min/Max Elements – Implemented an O(n) linear-time approach without sorting, optimizing both time and space 2️⃣ In-Place Array Reversal – Applied the two-pointer technique to reverse arrays efficiently (O(1) space) 3️⃣ Element Frequency Counter – Designed a function to compute occurrences of target elements in linear time 4️⃣ Second Largest Element – Solved using two tracking variables in a single traversal 5️⃣ Move Zeros to End – Implemented a stable version maintaining element order; currently refining with a two-pointer optimization 🔹 NumPy Fundamentals: Explored essential NumPy operations for data analysis, including: Mean, Median, Standard Deviation, Variance Array slicing, broadcasting, and vectorized computations These are fundamental tools for upcoming machine learning and data science projects. 🔹 Key Learnings: ✅ Optimization in both time and space complexity is critical ✅ In-place algorithms significantly enhance memory efficiency ✅ Clean, simple solutions often outperform over-engineered ones Next steps: optimizing current implementations and diving deeper into advanced data structures and algorithms. GitHub Repository: https://lnkd.in/gsucUW-F What’s your favorite array-related problem or concept I’d love to hear your thoughts in the comments 👇 #Python #NumPy #DataStructures #Algorithms #ProblemSolving #CodingChallenge #LearningInPublic #TechJourney #100DaysOfCode #yohancodes #selflearnig
To view or add a comment, sign in
-
Building with Google Maps Route Matrix API I recently built something small with the Google Maps Route Matrix API — and it completely changed how I think about “maps” in code. What starts as a simple “get travel time” API call quickly becomes a lesson in data design, caching, and spatial reasoning. Here’s what stood out: Batching Smartly - You can only query 625 origin–destination pairs per request (25×25). Writing a Python batching system with retry + exponential backoff was oddly satisfying — and essential to keep it stable at scale. Traffic Isn’t Static - Setting traffic_model=best_guess and departure_time=now makes the results real. But it also means you need caching or you’ll blow through your quota fast. Real-time data is powerful — and expensive if you don’t handle it wisely. Distance ≠ Duration - Ranking by duration_in_traffic instead of plain distance gives a truer sense of “closeness.” A few lines of logic turned raw data into something context-aware. Spatial Data Has Layers - Once I started visualizing the matrix output, I saw patterns — clusters, bottlenecks, and optimal nodes that could feed into routing algorithms or even ML models. #GoogleMapsAPI #GeospatialAnalysis #Python #GoogleMaps
To view or add a comment, sign in
-
When I was 18, studying literature in high school, I learned about Masahiro Mori's theory of the Uncanny Valley (while writing a thesis on Gothic Horror no less: good spooky season timing). Fast forward another 18 years, and I get to use that theory in my work! Including referencing the king of uncanny art: 2004's The Polar Express. Here though, I'm talking about Object Relational Mapping (ORM) usage (a far cry from Christmas films with disturbing, almost real animation). Hear me out. Those characters are just a little bit wrong, and make us uncomfortable. Similarly, applying OLTP (transactional) ORMs in an OLAP (analytical) space is almost good, but just wrong enough to dive into the developer experience Uncanny Valley. We wrote an article with ClickHouse outlining why these OLTP ORMs feel wrong in the analytics space: mainly, the assumptions the ORMs make fit the transactional world, but are exactly contrary to the assumptions made in the analytical world. In that article, we wrote that you shouldn't torture your OLTP ORM into serving the OLAP space. In this new article, we show an alternative. TypeScript is awesome (more to come on python during the course of this week). It gives us a lot "for free" when we use it. So if your OLTP ORM is in typescript (like Drizzle, Prisma or TypeORM), we show that you can derive fairly good native TypeScrip types from their schema objects, and use those types objects to create MooseOLAP objects that are native to the analytical space. Later this week, we'll show how we can enrich these further with LLM based inference on top of the generic models you derive in TypeScript. Would love to get feedback about how people are modeling data in the analytical space! Shout out to Michael Klein at District Cannabis, one of our customers, who was one of the first folk we worked on copilot assisted data modeling with: keep posted for his story. Blog: https://lnkd.in/gVg8D_7q Other links in 🧵 #OLAP #OLTP #ORM #MooseStack #TypeScript
To view or add a comment, sign in
-
-
While Johanan Ottensooser waxes poetic about high school lit class, we wanted to make sure you knew this was a technical blog. If you have a TypeScript ORM for your transactional database: 1. derive native typescript types from your schemas 2. use those schemas with MooseOLAP for analytical database native data modeling Read more: https://lnkd.in/gyRRzTZP #OLTP #OLAP #ORM #TypeScript #MooseStack
When I was 18, studying literature in high school, I learned about Masahiro Mori's theory of the Uncanny Valley (while writing a thesis on Gothic Horror no less: good spooky season timing). Fast forward another 18 years, and I get to use that theory in my work! Including referencing the king of uncanny art: 2004's The Polar Express. Here though, I'm talking about Object Relational Mapping (ORM) usage (a far cry from Christmas films with disturbing, almost real animation). Hear me out. Those characters are just a little bit wrong, and make us uncomfortable. Similarly, applying OLTP (transactional) ORMs in an OLAP (analytical) space is almost good, but just wrong enough to dive into the developer experience Uncanny Valley. We wrote an article with ClickHouse outlining why these OLTP ORMs feel wrong in the analytics space: mainly, the assumptions the ORMs make fit the transactional world, but are exactly contrary to the assumptions made in the analytical world. In that article, we wrote that you shouldn't torture your OLTP ORM into serving the OLAP space. In this new article, we show an alternative. TypeScript is awesome (more to come on python during the course of this week). It gives us a lot "for free" when we use it. So if your OLTP ORM is in typescript (like Drizzle, Prisma or TypeORM), we show that you can derive fairly good native TypeScrip types from their schema objects, and use those types objects to create MooseOLAP objects that are native to the analytical space. Later this week, we'll show how we can enrich these further with LLM based inference on top of the generic models you derive in TypeScript. Would love to get feedback about how people are modeling data in the analytical space! Shout out to Michael Klein at District Cannabis, one of our customers, who was one of the first folk we worked on copilot assisted data modeling with: keep posted for his story. Blog: https://lnkd.in/gVg8D_7q Other links in 🧵 #OLAP #OLTP #ORM #MooseStack #TypeScript
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