fix recursion depth O(logN): some algorithms