Question: You are given an array of m lamp posts with non - negative integer light values, where 0 means that the lamp post can only

You are given an array of m lamp posts with non-negative integer light values, where 0 means that the lamp post can only light up a section outside one house, 1 means it can light a given house plus the two immediately neighboring houses on either side of this house, and a light value of k means it can light a given house plus the next k houses on either side of this house (2k +1 consecutive houses in total). You can place a lamp post next to any house. A house may be lit by several lamp posts.
(a)If we have an array of five lamp posts [3,5,2,6,1], what is the minimum number of lamp posts needed to light the street with len =24 houses?
(b)Prove the greedy algorithm that sorts the set of lamp posts in decreasing order (and picks lamp posts until all houses on the street are lit) is optimal.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!