Exercise 1: Pre-Order and Post-Order Traversal of a File System — Possible Solution ==================================================================== GIVEN ------------------------------ root -> {docs, src} docs -> {readme.txt} src -> {main.py, utils.py} PRE-ORDER TRAVERSAL (visit BEFORE children) ------------------------------ Visit root first, then fully traverse its first child (docs) before moving to its second child (src). root, docs, readme.txt, src, main.py, utils.py POST-ORDER TRAVERSAL (visit AFTER children) ------------------------------ Fully traverse docs's own children before docs itself; fully traverse src's own children before src itself; visit root only once everything beneath it is done. readme.txt, docs, main.py, utils.py, src, root WHICH ONE MATCHES A REAL DIRECTORY LISTING ------------------------------ Pre-order matches how a typical directory-listing tool prints a folder before descending into it - "root" is printed first, then "docs" is printed and its contents shown, then "src" is printed and its contents shown. This is exactly this chapter's own definition of pre-order: visiting a node before any of its children, which is precisely "print the folder name, then show what's inside it" rather than the reverse. WHY THIS WORKS AS AN ANSWER ------------------------------ Both traversals are produced by consistently applying this chapter's own visit-timing rule for every node, not just the root - docs and src are each expanded fully (all their own children handled) using the same before/after rule recursively, and the real-world match is justified by pointing at the specific definition (visit-before-children) rather than just asserting pre-order "looks like" a directory listing.