androidengineers.Book a session

Trees

Applications: File Systems, DOM, Organization Charts

article20 minEasy

Trees are ubiquitous because human knowledge and operating system constructs naturally organize hierarchically.


1. Operating System File Systems

Every computer file system (ext4, APFS, NTFS) is an N-ary tree:

  • Root Directory: / (Unix/Linux/macOS) or C:\ (Windows).
  • Directories (Folders): Internal nodes that contain subdirectories and files.
  • Files: Leaf nodes storing raw data blocks.
                      / (Root)
                    /   \
                 bin     usr
                        /   \
                      lib   local
                             |
                            bin

Path resolution like /usr/local/bin is a simple top-down traversal from root.


2. Web Browsers: The DOM (Document Object Model)

When a web browser parses an HTML document, it constructs an in-memory tree representation:

<html>
  <body>
    <h1>Welcome</h1>
    <p>Data structures are <b>awesome</b>.</p>
  </body>
</html>
              html
                |
              body
             /    \
           h1      p
           |      / \
        "Welcome" ""  b
                      |
                  "awesome"

JavaScript DOM operations like document.getElementById() or querySelector() execute tree traversal algorithms under the hood.


3. Abstract Syntax Trees (AST) in Compilers

When Kotlin or Java compiles source code, the compiler frontend parses raw code tokens into an Abstract Syntax Tree (AST):

val result = (a + b) * c
         [*]
        /   \
      [+]   [ c ]
     /   \
   [ a ] [ b ]

The compiler can now analyze variable types, perform optimizations (constant folding), and generate target bytecode by walking this tree.


Summary

DomainTree StructurePrimary Value
File SystemsDirectory / Folder TreeHierarchical file naming, path isolation, and permission inheritance
Web BrowsersDOM TreeCSS style cascading and selective layout invalidation
CompilersAbstract Syntax Tree (AST)Mathematical precedence and syntax semantic validation

YOUR LEARNING JOURNEY

0 of 55 available lessons completed

Progress saved in this browser. No account needed.
Applications: File Systems, DOM, Organization Charts | Data Structures | Android Engineers