1 min readMay 17, 2020
Nice article and good code. BTW, B-tree is something quite special and definitely not an appropriate abbreviation for a binary tree.
I’m curious why you say that the algorithm will exhaust the stack on large trees. Have you seen this happen? Your algorithms are all tail-recursive so there should be no stack overflows. You can (and probably should) assert that your algorithm is tail-recursive with the @tailrec annotation.