Understanding time/space complexity