Least common ancestor - the next problem that I try to solve.
I have to versions of program: Tarjan and O(log(N)) finding ancestor.
Soon will see how it's made (for correctness and quality).
Seee http://e-maxx.ru/algo/lca. When i saw first time there algorithms, I thought: "Man, they use recursion EVERYWHERE". It's suprising. Alexander Shen writes in his books that you must find the way to avoid recursions!!
So, for big cycles whill be stack overflow. Just think: function calls itself, it must remember point of stop, all framebufer and so on...
But on the other hand : recursion helps us. Thanks you. mrs. recursion!))
Комментариев нет:
Отправить комментарий