Algorithm For Time Complexity