Difference between revisions of "TADM2E 4.3"

From Algorithm Wiki
Jump to: navigation, search
(Recovering wiki)
 
(Recovering wiki)
 
Line 1: Line 1:
<pre>
+
<pre>
 
Algo -
 
Algo -
 
If we create pair of (min1, max2n) (min1, max2n-1)... will provide optimal result
 
If we create pair of (min1, max2n) (min1, max2n-1)... will provide optimal result
Line 6: Line 6:
 
   Start: A[0]
 
   Start: A[0]
 
   End:  A[2n-1]
 
   End:  A[2n-1]
   while (start &lt; end)
+
   while (start < end)
 
       pair(start, end)
 
       pair(start, end)
 
       start++
 
       start++
 
       end--
 
       end--
 
   EndLoop
 
   EndLoop
&lt;/pre&gt;
+
</pre>
 
--[[User:Max|Max]] 06:55, 25 June 2010 (EDT)
 
--[[User:Max|Max]] 06:55, 25 June 2010 (EDT)

Latest revision as of 18:23, 11 September 2014

Algo -
If we create pair of (min1, max2n) (min1, max2n-1)... will provide optimal result
1) Sort the set of 2n element (n log n)
2) Now assign two pointers 
   Start: A[0]
   End:   A[2n-1]
   while (start < end)
      pair(start, end)
      start++
      end--
   EndLoop

--Max 06:55, 25 June 2010 (EDT)