Homework
What to hand in
algo with walk and depth, passing go test ./..., plus a report on your
own stack limit.
1. Find your limit
Increase -n until the recursion breaks. Record:
- the largest
nthat passed; - the smallest
nthat failed; - the
frames elidednumber from the message; - the frame size in bytes you compute from it.
Compare with step 3's 119 bytes. If yours differs, explain what is different
about your WalkRecursive.
2. Frame size is not a constant
Add a large local to WalkRecursive — say var buf [1024]byte — and use it, so
the compiler cannot discard it.
Find the limit again. By what factor did it drop? Does that match the kilobyte you added?
3. Speed
Measure both traversals, n = 10⁵ … 10⁷:
| n | recursive | iterative | ratio |
|---|
The iterative one should win everywhere. One sentence: why.
4. A branching tree
A chain is the worst case. Build a balanced tree with the same number of
folders (-depth and -branch).
What is the recursion depth now? Tie your answer to the tree's height, not its folder count.
That number is a trailer for lessons 11 and 12. Write it down — you will come back to it.
5. The decision
One paragraph: when will you write recursion in your own program, and when your own stack?
State a rule that turns on depth, not taste. The rule has to be answerable without running the program.