Log N Time Complexity for Loop