add python O(log(n)) implementation