<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Hunting high and low</title>
	<atom:link href="http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/</link>
	<description>a mostly .NET but also some other cool techs blog</description>
	<lastBuildDate>Mon, 16 Aug 2010 19:53:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Wolfram Bernhardt</title>
		<link>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/comment-page-1/#comment-6813</link>
		<dc:creator>Wolfram Bernhardt</dc:creator>
		<pubDate>Fri, 23 Oct 2009 11:28:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/#comment-6813</guid>
		<description>Hi again!

1) Okay, I see. So I learned something about Python finally... hope I won&#039;t be sent to hell for it.
2) I would have accepted Prolog or Lisp perfecly... well at least I could have read it...


Okay, I&#039;ll check out your code soon.</description>
		<content:encoded><![CDATA[<p>Hi again!</p>
<p>1) Okay, I see. So I learned something about Python finally&#8230; hope I won&#8217;t be sent to hell for it.<br />
2) I would have accepted Prolog or Lisp perfecly&#8230; well at least I could have read it&#8230;</p>
<p>Okay, I&#8217;ll check out your code soon.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Franz Antesberger</title>
		<link>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/comment-page-1/#comment-6804</link>
		<dc:creator>Franz Antesberger</dc:creator>
		<pubDate>Thu, 22 Oct 2009 19:58:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/#comment-6804</guid>
		<description>To your questions:
1) no, you are not right. the subrange excludes the upper bound, son the mid element is only in the second array
2) yes, you are right. With copy/paste i have lost some code. Of course you have to build the min of the mins and the max of the maxes.
To your first comment: You liked to have some code in a &quot;reasonable&quot; programming language. As I know you, you will not accept prolog or lisp or caml ( or caml light ) or f#, but only in your fetish language c#.
So I built it in c#:
[code]
&lt;pre&gt;
using System;
using System.Collections.Generic;

namespace MinMax
{
    class Program
    {
        public static int Counter { get; set; }

        public static int[] Range( int fromIncl, int toExcl )
        {
            int inc = fromIncl &lt; toExcl ? 1 : -1;
            var len = Math.Abs(toExcl - fromIncl);
            var result = new int[len];
            for( int pos=0, val=fromIncl; pos &lt; len; ++pos, val+=inc )
                result[pos] = val;
            return result;
        }

        public static int[] Subrange( int[] arr, int fromIncl, int toExcl )
        {
            var len = toExcl - fromIncl;
            var result = new int[len];
            for (int pos = 0; pos &lt; len; ++pos)
                result[pos] = arr[fromIncl + pos];
            return result;
        }

        public static KeyValuePair MinMax( int[] arr )
        {
            if( arr.Length == 1 )
                return new KeyValuePair(arr[0],arr[0]);
            if( arr.Length == 2 )
            {
                Counter = Counter + 1;
                if( arr[0] &lt; arr[1] )
                    return new KeyValuePair(arr[0], arr[1]);
                return new KeyValuePair(arr[1], arr[0]);
            }
            var mid = arr.Length/2;
            var left = MinMax(Subrange(arr, 0, mid));
            var right = MinMax(Subrange(arr, mid, arr.Length));
            Counter = Counter + 2;            
            return new KeyValuePair( Math.Min(left.Key,right.Key), Math.Max(left.Value,right.Value));
        }

        static void Main()
        {
            Counter = 0;
            Console.Out.WriteLine(MinMax(Range(0, 16)));
            Console.Out.WriteLine( &quot;comparisons: &quot; + Counter );
            Counter = 0;
            Console.Out.WriteLine(MinMax(Range(16, 0)));
            Console.Out.WriteLine(&quot;comparisons: &quot; + Counter);
        }
    }
}
&lt;/pre&gt;
[/code]
I tried to put some lambda and linq in it, but the only reasonable way was:
   var min = arr.Min();
   var max = arr.Max();
;-)</description>
		<content:encoded><![CDATA[<p>To your questions:<br />
1) no, you are not right. the subrange excludes the upper bound, son the mid element is only in the second array<br />
2) yes, you are right. With copy/paste i have lost some code. Of course you have to build the min of the mins and the max of the maxes.<br />
To your first comment: You liked to have some code in a &#8220;reasonable&#8221; programming language. As I know you, you will not accept prolog or lisp or caml ( or caml light ) or f#, but only in your fetish language c#.<br />
So I built it in c#:<br />
[code]</p>
<pre>
using System;
using System.Collections.Generic;

namespace MinMax
{
    class Program
    {
        public static int Counter { get; set; }

        public static int[] Range( int fromIncl, int toExcl )
        {
            int inc = fromIncl &lt; toExcl ? 1 : -1;
            var len = Math.Abs(toExcl - fromIncl);
            var result = new int[len];
            for( int pos=0, val=fromIncl; pos &lt; len; ++pos, val+=inc )
                result[pos] = val;
            return result;
        }

        public static int[] Subrange( int[] arr, int fromIncl, int toExcl )
        {
            var len = toExcl - fromIncl;
            var result = new int[len];
            for (int pos = 0; pos &lt; len; ++pos)
                result[pos] = arr[fromIncl + pos];
            return result;
        }

        public static KeyValuePair MinMax( int[] arr )
        {
            if( arr.Length == 1 )
                return new KeyValuePair(arr[0],arr[0]);
            if( arr.Length == 2 )
            {
                Counter = Counter + 1;
                if( arr[0] &lt; arr[1] )
                    return new KeyValuePair(arr[0], arr[1]);
                return new KeyValuePair(arr[1], arr[0]);
            }
            var mid = arr.Length/2;
            var left = MinMax(Subrange(arr, 0, mid));
            var right = MinMax(Subrange(arr, mid, arr.Length));
            Counter = Counter + 2;
            return new KeyValuePair( Math.Min(left.Key,right.Key), Math.Max(left.Value,right.Value));
        }

        static void Main()
        {
            Counter = 0;
            Console.Out.WriteLine(MinMax(Range(0, 16)));
            Console.Out.WriteLine( "comparisons: " + Counter );
            Counter = 0;
            Console.Out.WriteLine(MinMax(Range(16, 0)));
            Console.Out.WriteLine("comparisons: " + Counter);
        }
    }
}
</pre>
<p>[/code]<br />
I tried to put some lambda and linq in it, but the only reasonable way was:<br />
   var min = arr.Min();<br />
   var max = arr.Max();<br />
 <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wolfram Bernhardt</title>
		<link>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/comment-page-1/#comment-6777</link>
		<dc:creator>Wolfram Bernhardt</dc:creator>
		<pubDate>Tue, 20 Oct 2009 21:38:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/#comment-6777</guid>
		<description>Ah... now I understand... but I have some questions.

1)
Doesn&#039;t the part:

&lt;code&gt;left = minmax( list[0:mid] )
right = minmax( list[mid:])&lt;/code&gt;

copy the &#039;mid&#039;-element? 

This doesn&#039;t influence the result, but results in a bad in influence (more work to do).



2) 
I think the code isn&#039;t correct.

&lt;pre&gt;&lt;code&gt;left = minmax( list[0:mid] )
    right = minmax( list[mid:])
    min = left[0]
    minmax.counter = minmax.counter + 1
    if right[0]  max:
        max = right[1]&lt;/code&gt;&lt;/pre&gt;

What about the min-result of right? And the max-result of left?
So I think 

&lt;code&gt;sample = range( 16, 0 )&lt;/code&gt;

leads to a wrong result.

Greets,
    Wolfram</description>
		<content:encoded><![CDATA[<p>Ah&#8230; now I understand&#8230; but I have some questions.</p>
<p>1)<br />
Doesn&#8217;t the part:</p>
<p><code>left = minmax( list[0:mid] )<br />
right = minmax( list[mid:])</code></p>
<p>copy the &#8216;mid&#8217;-element? </p>
<p>This doesn&#8217;t influence the result, but results in a bad in influence (more work to do).</p>
<p>2)<br />
I think the code isn&#8217;t correct.</p>
<pre><code>left = minmax( list[0:mid] )
    right = minmax( list[mid:])
    min = left[0]
    minmax.counter = minmax.counter + 1
    if right[0]  max:
        max = right[1]</code></pre>
<p>What about the min-result of right? And the max-result of left?<br />
So I think </p>
<p><code>sample = range( 16, 0 )</code></p>
<p>leads to a wrong result.</p>
<p>Greets,<br />
    Wolfram</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wolfram Bernhardt</title>
		<link>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/comment-page-1/#comment-6775</link>
		<dc:creator>Wolfram Bernhardt</dc:creator>
		<pubDate>Tue, 20 Oct 2009 21:26:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/#comment-6775</guid>
		<description>Hi Franz!

That looks very interesting. Thanks a lot!
Unfortunately I am not sure I understand what &lt;code&gt;list[0]&lt;/code&gt; means... Could you please provide this example in a reasonable programming language? :)


Greets,
    Wolfram</description>
		<content:encoded><![CDATA[<p>Hi Franz!</p>
<p>That looks very interesting. Thanks a lot!<br />
Unfortunately I am not sure I understand what <code>list[0]</code> means&#8230; Could you please provide this example in a reasonable programming language? <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Greets,<br />
    Wolfram</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Franz Antesberger</title>
		<link>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/comment-page-1/#comment-6774</link>
		<dc:creator>Franz Antesberger</dc:creator>
		<pubDate>Tue, 20 Oct 2009 21:07:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/#comment-6774</guid>
		<description>Sorry, this stupid blog software removes all my code formatting! So the script will not run, if you don&#039;t correct the indentation, but I hope, the clear concepts of python make the thing self-quack-describing</description>
		<content:encoded><![CDATA[<p>Sorry, this stupid blog software removes all my code formatting! So the script will not run, if you don&#8217;t correct the indentation, but I hope, the clear concepts of python make the thing self-quack-describing</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Franz Antesberger</title>
		<link>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/comment-page-1/#comment-6773</link>
		<dc:creator>Franz Antesberger</dc:creator>
		<pubDate>Tue, 20 Oct 2009 21:04:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/#comment-6773</guid>
		<description>You showed the solution of finding min/max of a list with size n with exactly 1.5 n comparisons of the list members ( you didn&#039;t count the iterator comparisons, I will not count mine, too ).
But because its very ugly to instanciate Pair or something like that in c#, I quacked my solution in beautiful duck typed python, just to show, that I can.
I used divide and conquer and you will see, that I need LESS than 1.5 n.
In the given example with 16 elements, I need only 22 comparisons compared to your 24.

&lt;pre&gt;
&lt;code&gt;def minmax( list ):
    if len(list) == 1:
        return ( list[0], list[0] )
    if len(list) == 2:
        minmax.counter = minmax.counter + 1
        if list[0] &gt; list[1]:
            return (list[1], list[0] )
        return (list[0], list[1] )
    mid = len(list) / 2
    left = minmax( list[0:mid] )
    right = minmax( list[mid:])
    min = left[0]
    minmax.counter = minmax.counter + 1
    if right[0]  max:
        max = right[1]
    return (min,max)

minmax.counter = 0
sample = range( 0, 16 )
print minmax( sample )
print minmax.counter&lt;/code&gt;
&lt;/pre&gt;

( that&#039;s no code fragment, but the hole thing! )
I leave the proof, that this will always needs LESS that 1.5 n comparisons as an exercise ;-)</description>
		<content:encoded><![CDATA[<p>You showed the solution of finding min/max of a list with size n with exactly 1.5 n comparisons of the list members ( you didn&#8217;t count the iterator comparisons, I will not count mine, too ).<br />
But because its very ugly to instanciate Pair or something like that in c#, I quacked my solution in beautiful duck typed python, just to show, that I can.<br />
I used divide and conquer and you will see, that I need LESS than 1.5 n.<br />
In the given example with 16 elements, I need only 22 comparisons compared to your 24.</p>
<pre>
<code>def minmax( list ):
    if len(list) == 1:
        return ( list[0], list[0] )
    if len(list) == 2:
        minmax.counter = minmax.counter + 1
        if list[0] &gt; list[1]:
            return (list[1], list[0] )
        return (list[0], list[1] )
    mid = len(list) / 2
    left = minmax( list[0:mid] )
    right = minmax( list[mid:])
    min = left[0]
    minmax.counter = minmax.counter + 1
    if right[0]  max:
        max = right[1]
    return (min,max)

minmax.counter = 0
sample = range( 0, 16 )
print minmax( sample )
print minmax.counter</code>
</pre>
<p>( that&#8217;s no code fragment, but the hole thing! )<br />
I leave the proof, that this will always needs LESS that 1.5 n comparisons as an exercise <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
