<?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: Python Code Kata 2: Karate Chop (Binary Search)</title>
	<atom:link href="http://www.protocolostomy.com/2009/12/13/python-code-kata-2-karate-chop-binary-search/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.protocolostomy.com/2009/12/13/python-code-kata-2-karate-chop-binary-search/</link>
	<description>Made with only the finest 1's and 0's</description>
	<lastBuildDate>Thu, 26 Jan 2012 21:20:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Toby</title>
		<link>http://www.protocolostomy.com/2009/12/13/python-code-kata-2-karate-chop-binary-search/comment-page-1/#comment-30105</link>
		<dc:creator>Toby</dc:creator>
		<pubDate>Tue, 15 Dec 2009 03:08:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=662#comment-30105</guid>
		<description>Your ternary search will have base-3 for the log, rather than base-2. However, you do two tests in place of one, so the resulting constant factor is:

&gt;&gt;&gt; math.log(2)/math.log(3) * 2
1.2618595071429148

On that basis, ternary search will lose to binary search, on average.

Interpolation search (binary search with mid-point chosen by linear interpolation) improves the big-O performance of binary search (O(log log N) - assuming values are uniformly distributed) but in practice is slower for realistic values of N.</description>
		<content:encoded><![CDATA[<p>Your ternary search will have base-3 for the log, rather than base-2. However, you do two tests in place of one, so the resulting constant factor is:</p>
<p>&gt;&gt;&gt; math.log(2)/math.log(3) * 2<br />
1.2618595071429148</p>
<p>On that basis, ternary search will lose to binary search, on average.</p>
<p>Interpolation search (binary search with mid-point chosen by linear interpolation) improves the big-O performance of binary search (O(log log N) &#8211; assuming values are uniformly distributed) but in practice is slower for realistic values of N.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Pate</title>
		<link>http://www.protocolostomy.com/2009/12/13/python-code-kata-2-karate-chop-binary-search/comment-page-1/#comment-30052</link>
		<dc:creator>Roger Pate</dc:creator>
		<pubDate>Mon, 14 Dec 2009 16:53:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=662#comment-30052</guid>
		<description>Everywhere you have &quot;lo = haystack[0]&quot; (chop, chop3, chop3_take2) you need &quot;lo = 0&quot;.</description>
		<content:encoded><![CDATA[<p>Everywhere you have &#8220;lo = haystack[0]&#8221; (chop, chop3, chop3_take2) you need &#8220;lo = 0&#8243;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry Hastings</title>
		<link>http://www.protocolostomy.com/2009/12/13/python-code-kata-2-karate-chop-binary-search/comment-page-1/#comment-30019</link>
		<dc:creator>Larry Hastings</dc:creator>
		<pubDate>Mon, 14 Dec 2009 11:06:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=662#comment-30019</guid>
		<description>I was going to point out the &quot;bisect&quot; module, but the speedy Mr. Dalke beat me to it.  I think it&#039;s worthwhile for Python programmers to sit and read the standard library documentation now and then.  There&#039;s a lot of worthwhile functionality built in there, and it can make your life easier, but only if you know about it.  For example, it was by reading the library documentation like a book that I found this hidden gem: shlex.split().  Now that&#039;s useful!

The list.index method is an O(n) operation--it cannot assume the list is sorted.  So it&#039;s faster than your binary search just because it&#039;s in C and yours is in Python.  That only matters because your numbers are small.  As the numbers grew your binary search would start to win.  I tried looking for 9000000 in range(10000000); your &quot;chop&quot; found it a thousand times faster than list.index did.  And &quot;bisect.bisect_left&quot; (also written in C) was ten-thousand times faster than insert.

Finally, I think &quot;guess the number&quot; is more impressive if you only ask true-false questions.  Obviously, your questions would be of the form &quot;Is the number less than &quot;.  After 7 questions, you don&#039;t need to ask--you can state what their number is.</description>
		<content:encoded><![CDATA[<p>I was going to point out the &#8220;bisect&#8221; module, but the speedy Mr. Dalke beat me to it.  I think it&#8217;s worthwhile for Python programmers to sit and read the standard library documentation now and then.  There&#8217;s a lot of worthwhile functionality built in there, and it can make your life easier, but only if you know about it.  For example, it was by reading the library documentation like a book that I found this hidden gem: shlex.split().  Now that&#8217;s useful!</p>
<p>The list.index method is an O(n) operation&#8211;it cannot assume the list is sorted.  So it&#8217;s faster than your binary search just because it&#8217;s in C and yours is in Python.  That only matters because your numbers are small.  As the numbers grew your binary search would start to win.  I tried looking for 9000000 in range(10000000); your &#8220;chop&#8221; found it a thousand times faster than list.index did.  And &#8220;bisect.bisect_left&#8221; (also written in C) was ten-thousand times faster than insert.</p>
<p>Finally, I think &#8220;guess the number&#8221; is more impressive if you only ask true-false questions.  Obviously, your questions would be of the form &#8220;Is the number less than &#8220;.  After 7 questions, you don&#8217;t need to ask&#8211;you can state what their number is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tweets that mention Python Code Kata 2: Karate Chop (Binary Search) &#124; Musings of an Anonymous Geek -- Topsy.com</title>
		<link>http://www.protocolostomy.com/2009/12/13/python-code-kata-2-karate-chop-binary-search/comment-page-1/#comment-29988</link>
		<dc:creator>Tweets that mention Python Code Kata 2: Karate Chop (Binary Search) &#124; Musings of an Anonymous Geek -- Topsy.com</dc:creator>
		<pubDate>Mon, 14 Dec 2009 02:16:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=662#comment-29988</guid>
		<description>[...] This post was mentioned on Twitter by scott sutton, Yeluri. Yeluri said: Python Code Kata 2: Karate Chop (Binary Search) &#124; Musings of an ...: If you had a phone book listing every pers.. http://bit.ly/6qqfxV [...]</description>
		<content:encoded><![CDATA[<p>[...] This post was mentioned on Twitter by scott sutton, Yeluri. Yeluri said: Python Code Kata 2: Karate Chop (Binary Search) | Musings of an &#8230;: If you had a phone book listing every pers.. <a href="http://bit.ly/6qqfxV" rel="nofollow">http://bit.ly/6qqfxV</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Dalke</title>
		<link>http://www.protocolostomy.com/2009/12/13/python-code-kata-2-karate-chop-binary-search/comment-page-1/#comment-29975</link>
		<dc:creator>Andrew Dalke</dc:creator>
		<pubDate>Sun, 13 Dec 2009 22:44:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=662#comment-29975</guid>
		<description>You can also compare your result to the code in the &#039;bisect&#039; module, which also has C equivalents.

One of the differences you&#039;ll see is the use of &#039;//&#039; instead of &#039;/&#039;. That&#039;s for future compatibility since in Python 3 &#039;int/int&#039; won&#039;t return a float.</description>
		<content:encoded><![CDATA[<p>You can also compare your result to the code in the &#8216;bisect&#8217; module, which also has C equivalents.</p>
<p>One of the differences you&#8217;ll see is the use of &#8216;//&#8217; instead of &#8216;/&#8217;. That&#8217;s for future compatibility since in Python 3 &#8216;int/int&#8217; won&#8217;t return a float.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

