If you have any form of iterator over your tree then you can use a perfectly mundane approach to the max depth.
Here's silly one-liner showing the concept for finding maximum reachable filesystem depth using UNIX find
, awk
and tr
:
find / -depth | tr -dc '/\n' \
| awk '{if (length($0) > max) { max=length($0)}}; END {print max}'
... find
is the iterator, tr
is a data manipulation "translating" one set of characters into another (in this case it's being used to -d (delete) the complement (-c) of the single character set being specified (/). So it converts any UNIX full path into just the / separators. From there I just find the longest line of input ... and that's my result.
Of course this approach won't help you much with your homework assignment. But the concept should be clear. :)