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) orC:\(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
| Domain | Tree Structure | Primary Value |
|---|---|---|
| File Systems | Directory / Folder Tree | Hierarchical file naming, path isolation, and permission inheritance |
| Web Browsers | DOM Tree | CSS style cascading and selective layout invalidation |
| Compilers | Abstract Syntax Tree (AST) | Mathematical precedence and syntax semantic validation |