sum series and time complexity

My highly sophisticated rule of thumb for eyeballing time complexity is to find the cheapest unit of work and count how many times it runs. I find it a bit more reliable than counting the nested loops . This is easy to see why: left = 0 0...n .each do |right| while bad left += 1 end end Here, right and left only move forward once , so the total amount of movement is 2n , linear time. Similarly, a…