intervals - How to prove greedy algorithm optimality -


After the

s has a set of intervals (n numbers of intervals) having two natural The numbers that can be found together and a list of n h numbers (containing n numbers of numbers)

I want to put the smallest subset of each number for such that SK (P) calls in our list N, at least one gap in P which is included in it Overlapping intervals in P is allowed.

Trivial Example:

  S = {[1..4], [2..7], [3 .. 5], [8..15] , [9 .13]} N = [1, 4, 5] // so P = {[1..4], [2.7]}  

show me below Given the solution to this problem

  N = MergeSort (N) upper, lower = infinity, -1P = empty set for each q (; = less and q & lt; q & Gt = upper) If for every R in S = false max_interval = [-infinity, infinity] if r in r then .rightEndPoint> gt; Max_interval.rightEndPoint max_interval = r P.append (max_interval) cum = max_interval.leftEndPoint upper = max_interval.rightEndPoint S.remove (max_interval)  

I have found this solution, but I completely I'm not. How to prove the optimality of a greedy algorithm (which is proven, which will always give the best results)

My question: How can I prove the optimality of this greedy solution? P>

Thanks in advance.

Yes, your algorithm reaches the optimal solution. I am not supposed to have formal evidence but with the expectation to explain the following good reasoning.

  1. Array N is sorted in ascending order and you are reaching the elements accordingly in non descending order. In other words, the current element is always> = the last element
  2. for each element, we first check whether it can be adjusted in the previously selected interval, Let's move on, otherwise we will not go to the next element.
  3. For the current element, we choose the interval (not selected) so that its 'end point' might possibly be as big as possible. It makes sense because in this way we can adjust most elements that follow our current element. For example, if the present element is 10, and we have two candidate intervals [8, 12] and [9, 15], under any circumstances, we will not pre-select because we know that the following element is greater than 10 needed .

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -