惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
P
Privacy & Cybersecurity Law Blog
T
Tor Project blog
Google Online Security Blog
Google Online Security Blog
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News and Events Feed by Topic
The Register - Security
The Register - Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
SecWiki News
SecWiki News
T
True Tiger Recordings
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 最新话题
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
T
Troy Hunt's Blog
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
L
Lohrmann on Cybersecurity
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
J
Java Code Geeks
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
Jina AI
Jina AI
S
Secure Thoughts
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
月光博客
月光博客
S
Schneier on Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
Know Your Adversary
Know Your Adversary
PCI Perspectives
PCI Perspectives
罗磊的独立博客
A
Arctic Wolf
雷峰网
雷峰网
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Latest news
Latest news

DEV Community

Optimizing Chunking and Data Extraction for Zero-Hallucination RAG Controlling Blender with AI — Building an MCP Server for 3D Creation 5 Smart Contract Vulnerabilities Every Developer Should Know in 2026 Cursor users who write failing tests before prompting the AI complete features in 37% fewer iterations than those who pr When AI Becomes a Danger: 370,000 Grok Conversations Exposed I Refactored 100 Functions With Claude. CI Was Green. Production Got Slower in 7 Spots. I read my own commits like a stranger Child Safety vs. Data Center Dollars The Reason Your AI Chatbot Feels Fast Has Nothing to Do With a Better Model Beyond Vibe-Coding What I learned testing AI translation tools in 2026 (DeepL is still good, but LLMs caught up) AWS ECS Fargate Cost Allocation: Why Your Per-Cluster Spend Shows as One Line How to Surface License Violations in GitHub Advanced Security with feluda We Deleted 10 Real Users with a Test-Cleanup Script — RCA The Decision Subtraction Framework: How to Evaluate Any AI Tool How I Access My Home PC From Anywhere Without Spending a Penny # agents.md: Teaching AI Agents How to Scrape (The Future of Web Automation) KAI vs Global vs Tojiro vs Miyabi: How to Actually Tell Japanese Knife Brands Apart Why We Accidentally Blocked Our Users: A Deep Dive into Idempotency in Distributed Systems I Connected Hermes Agent to a Live MCP Server with 59 Tools and Here's What It Actually Built Our first app is finally live on the Play Store after 4 months of hard work 🚀 I Built UUIDs That Look Random But Sort Like Timestamps (50% Smaller Indexes!) The Night Our Event Pipeline Crashed Because We Didn't Measure Memory First How to Control Token Spend in Codex-Style AI Workflows Understanding the Model Context Protocol (MCP): Complete Guide 185,000 Affected in 7-Eleven Breach: Why Salesforce Is the New Soft Target for ShinyHunters Hack your AWS CLI to add CloudShell support and turn your terminal into a bastion How to Check Telegram Account Age and Estimated Creation Date ChromaDB vs Qdrant vs Weaviate vs pgvector: vector database shootout 2026 Robinhood Just Launched AI Trading Agents — Here's the Economic Data API They Need Robinhood Just Launched AI Trading Agents — Here's the Economic Data API They Need Dhrishti Part 1 - Building Runtime Observability for Distributed Systems CSS Box Shadows: The Complete Guide From Flat to Floating When I Learned Python, I Made a CLI Tool I built a free API that measures the cost of software complexity My AI Agent Hit a Duplicate Post Error. Here Is the Engineering Lesson. How I Revived a Paused Agri-Tech App to Empower Farmers Using GitHub Copilot PostgreSQL 01003 오류 원인과 해결 방법 완벽 가이드 Introducing the UCP Playground Extension: An AI Shopping Agent in Your Side Panel Demystifying WebP to PNG: Secure Serverless Edge Routing Configurations Without Leaking Credentials Age Verification's Dirty Secret: The Tech Works. The System Doesn't. Tipos de errores, Wrapping e Inspección en Go The Next Decade of Data Engineering: From Modern Data Stack to Data Engineering Harness Tell me which LLM and cloud base suitable for creating agentic coding AI. it's all coverup the BMDA like 1. Business Understanding 2. Model / Architecture Design 3. Agile Development 4. Deployment & Monitoring Why Traditional QA Fails Browser-Based Casino Games I Built Sổ Lãi, a Practical Profit Tracker for Vietnamese Online Shops Bugs not dead: How to catch bugs in game code GitHub Suspended My 2-Year Developer Account — Here’s What I Learned April ecommerce grew at 11% - here's what that means for backend infrastructure Go Modules in Practice: Init, Tidy, Vendor, and Publishing Packages Building Metadata Capabilities in Apache SeaTunnel: A Committer’s Journey How to Correctly Read a PostgreSQL EXPLAIN ANALYZE Output label and Input Tag I Revived Intelliyash: A Local-First AI Builder for Low-End Machines How I Added dbt Cloud to Coral — My Open Source Hackathon Journey vens-action: reranking Trivy/Grype CVEs by real risk in CI Le projet qui fonctionnait… mais que je détestais modifier Magento 2 Static Content Deploy Optimization: Faster Builds, Fewer Headaches Top API Gateways for AI Applications and Agentic Workflows (2026 Developer Guide) Seasons time-lapse - alignment Struggle is part of mastery — stop skipping it We built a 5-level MLM referral system. 6 months, 6 users, $0 earned. Here's what we learned killing it Transforming XML to JSON and CSV with XSLT Building a Side Project with AI Pair Programming: Lessons Learned with Sharebox I Made Local AI Faster Than the Cloud — A Complete Home Automation Voice Control Journey An MCP server can vanish from your AI agent mid-conversation. Here's the 30-second timeout that did it to me. I Was Wrong About Events for Three Years—Until I Learned What Async Runtime Was Really Costing SleepPublish vs Zapier: Handling Your Heavy Auto Publish Tasks Mastering the print() Function in Python EIP-7928 parallelization, native privacy roadmap, EIP-8141 deep dive, EF restructuring Turning a Toaster Oven into a Reflow Oven — A Safety Design Story 20 Currency & Exchange Rate API Questions Answered (2026) — Exchange Rate API SurrealDB 3.1: stability, DiskANN, and a new release process Git Workflows: From Solo to Team (2026) Why Your OpenAI Wrapper Is Costing Too Much (And How LangGraph Fixes It) Veltrix and the Day the Trace Loops Broke Building an SEO crawler in TypeScript: what I learned Benchmarking the Claude Agent SDK on a local LLM: Haiku and Sonnet tier performance 82% of Phishing Attacks Are Now AI-Generated - And File Sharing Is a Key Attack Vector We Measured LLM Prompt Caching in Production — Same Prompt, 0% to 91% Hit Rates We gave Kiro a brain for AWS, locally, for free We Built an AI Voice Agent That Calls Real Estate Leads in Under 5 Minutes. Here's How I got tired of bloated reminder apps, so I built one in Java I Built a Fully Autonomous Social Media Agent in 72 Hours — Here's the Architecture 1 Minute SQL Tips with WoWSQL — 28 May 2026 Understanding known_hosts and Host Key Verification: What It Protects Against and How TOFU Works A-Z AI Glossary From a Forgotten Multiplayer Prototype to a Chaotic Hidden-Object Game — Reviving WhatUsee 🚀 Handling Localization in PCF Components: A Practical Walkthrough AI Agents Are Great at 80% of Our Code. The Other 20% Is Why We Still Need Seniors. How to Monitor AI Agents in Production I Analyzed 1,000 AI-Generated Blog Posts for Quality. Here's the Data. From Forgotten Repo to Live App: How I Finished Photremium.com Using GitHub Copilot Custodial vs trust-minimized: two settlement layers for the agent economy Treasure Hunting at Scale: Why Our Cache-Aside Cache Cost Us 40% in Tail Latency During Black Friday Designing Forms an AI Agent Can Actually Submit You’re Ignoring 95% of Your LLM Response From Abandoned Prototype to AI-Powered Google Form Platform Beginner’s AI Glossary PostgreSQL 01008 오류 원인과 해결 방법 완벽 가이드
Tree Traversal: Why the Order You Pick Is a Data Flow Decision
Prakhar Sriv · 2026-05-28 · via DEV Community

Tree traversal usually gets taught as three separate algorithms to memorize: preorder, inorder, postorder. They are not three algorithms. They are one recursive function with a single line moved to a different spot, and that one line decides which problems you can solve.

I watched this trip up people prepping for months. They had all four traces memorized and still froze when a new problem asked them to pick an order. The trace is the easy part. Knowing which order hands you the information you need is the part that actually matters in an interview.

TL;DR: Traversal visits every node once. The four standard orders differ only in when the current node gets processed relative to its children. Preorder processes the node before its children, postorder after, inorder between, and level order goes breadth first with a queue. Pick the order by asking which direction data has to move between a parent and its children.

The four orders on one tree

Run all four on the same tree and the difference stops being abstract.

        1
       / \
      2   3
     / \   \
    4   5   6
   /
  7

Enter fullscreen mode Exit fullscreen mode

  • Preorder (node, left, right): 1, 2, 4, 7, 5, 3, 6
  • Inorder (left, node, right): 7, 4, 2, 5, 1, 3, 6
  • Postorder (left, right, node): 7, 4, 5, 2, 6, 3, 1
  • Level order (breadth first): 1, 2, 3, 4, 5, 6, 7

Inorder looks unsorted here because this is not a binary search tree. The sorted property only shows up when the values obey the BST invariant of left less than node less than right. On a plain binary tree, inorder still walks left, node, right, but the numbers come out in whatever order the structure gives you.

The only thing that changes is one line

The three depth first orders are the same code. The recursive call structure is identical. The only difference is where the line that processes the node sits relative to the two recursive calls.

def preorder(node):
    if not node:
        return
    process(node)        # before the children
    preorder(node.left)
    preorder(node.right)

def inorder(node):
    if not node:
        return
    inorder(node.left)
    process(node)        # between the children
    inorder(node.right)

def postorder(node):
    if not node:
        return
    postorder(node.left)
    postorder(node.right)
    process(node)        # after the children

Enter fullscreen mode Exit fullscreen mode

Move one line, change the order. That is the whole trick for the depth first family.

Why postorder is the one that computes heights

This is where order stops being trivia. Take the height of a binary tree. To know a node's height, you need the heights of both children first. You take the larger child height and add one. That dependency, children before parent, is exactly what postorder gives you.

def height(node):
    if not node:
        return -1            # an empty subtree has height -1
    left = height(node.left)
    right = height(node.right)
    return max(left, right) + 1

Enter fullscreen mode Exit fullscreen mode

Trace it on the tree above and watch every node wait for its children before it can answer.

Node 7: leaf                      -> 0
Node 4: left(7)=0, no right       -> max(0, -1) + 1 = 1
Node 5: leaf                      -> 0
Node 2: left(4)=1, right(5)=0     -> max(1, 0) + 1 = 2
Node 6: leaf                      -> 0
Node 3: no left, right(6)=0       -> max(-1, 0) + 1 = 1
Node 1: left(2)=2, right(3)=1     -> max(2, 1) + 1 = 3

Enter fullscreen mode Exit fullscreen mode

Try the same thing with preorder and you hit the parent first, with no information about the subtree below it. You can still make it work by passing depth down as a parameter and tracking a maximum in an outer variable, but it is fifteen awkward lines where postorder is five. Diameter, subtree sums, balanced checks, distributing coins: same shape every time. The parent cannot answer until both children have reported back, so you process the children first.

The first time I had to write any of these iteratively under a timer, I realized I had memorized the recursion and never the stack sitting under it. That gap is part of why I built Codeintuition, and the binary tree course traces the stack state for the iterative versions one frame at a time.

Level order is the odd one out

Level order is the only one that is not depth first. It uses a queue, not the call stack. Enqueue the root, then repeatedly dequeue a node and enqueue its children. Nodes come out one full level at a time.

from collections import deque

def level_order(root):
    if not root:
        return
    queue = deque([root])
    while queue:
        node = queue.popleft()
        process(node)
        if node.left:
            queue.append(node.left)
        if node.right:
            queue.append(node.right)

Enter fullscreen mode Exit fullscreen mode

Anything that works on nodes at the same depth (level sums, zigzag traversal, connecting nodes across a level) needs this breadth first access. Forcing depth first to do the same job means tracking depth by hand, which is more bookkeeping than the problem deserves.

Picking the order: which way does the data flow?

Almost every tree problem opens with the same hidden question. Does the parent need answers from its children, or do the children need data handed down from the parent? Answer that and the order falls out.

  • Postorder: the parent needs results from both children (height, diameter, subtree sums, balanced checks)
  • Preorder: the children need data passed down from the parent (root to leaf path sums, serialization)
  • Inorder: you want values in sorted order out of a BST
  • Level order: the work happens per level (level sums, zigzag, connecting same depth nodes)

A quick aside worth its own paragraph: there is a real argument that some problems read fine in more than one order, and reconstructing a tree from traversals is its own rabbit hole (preorder alone is not enough, you need inorder too, or null markers). That is a separate post. For the day to day of picking an order on sight, the data direction question settles it.

Listing the four orders is the easy part of this topic. Looking at an unfamiliar tree problem and knowing which order hands you the right information before you write a line is the skill that actually transfers to an interview, and it comes from understanding why each order exists, not from re-reading the traces.

I wrote a longer version on my own blog that walks through the iterative conversions for all three depth first orders.

Which traversal order was the one that finally made sense to you only after you got burned picking the wrong one on a real problem?