<?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: Two Word Anagram Finder Algorithm (in Ruby)</title>
	<atom:link href="http://martin.ankerl.com/2008/08/09/two-word-anagram-finder-algorithm/feed/" rel="self" type="application/rss+xml" />
	<link>http://martin.ankerl.com/2008/08/09/two-word-anagram-finder-algorithm/</link>
	<description>No movement is faster than no movement</description>
	<lastBuildDate>Fri, 30 Jul 2010 11:00:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
	<item>
		<title>By: Martin Ankerl</title>
		<link>http://martin.ankerl.com/2008/08/09/two-word-anagram-finder-algorithm/comment-page-1/#comment-2438</link>
		<dc:creator>Martin Ankerl</dc:creator>
		<pubDate>Sun, 10 Aug 2008 07:35:46 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=156#comment-2438</guid>
		<description>On second thought, there is a way to get rid of the linked list search that is required when words have the same hash key. This is just a braindump of me and might be gibberish and not work at all but I don&#039;t want to forget it while Im on holiday.

A possible way to get rid of the linked list search is to use &lt;a href=&quot;http://en.wikipedia.org/wiki/Cuckoo_hashing&quot; rel=&quot;nofollow&quot;&gt;cuckoo hashing&lt;/a&gt;. We just need another cummulative hash function (e.g. XOR of the letters), then we should be able to get rid of the filtering and have O(n) build up speed, and O(1) query speed. Will look into this next week.</description>
		<content:encoded><![CDATA[<p>On second thought, there is a way to get rid of the linked list search that is required when words have the same hash key. This is just a braindump of me and might be gibberish and not work at all but I don&#8217;t want to forget it while Im on holiday.</p>
<p>A possible way to get rid of the linked list search is to use <a href="http://en.wikipedia.org/wiki/Cuckoo_hashing" rel="nofollow">cuckoo hashing</a>. We just need another cummulative hash function (e.g. XOR of the letters), then we should be able to get rid of the filtering and have O(n) build up speed, and O(1) query speed. Will look into this next week.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Ankerl</title>
		<link>http://martin.ankerl.com/2008/08/09/two-word-anagram-finder-algorithm/comment-page-1/#comment-2437</link>
		<dc:creator>Martin Ankerl</dc:creator>
		<pubDate>Sun, 10 Aug 2008 06:46:49 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=156#comment-2437</guid>
		<description>Great idea A, thanks! This should be even faster. I will try this next week when I am back from my holidays.

UPDATE Ok I have just implemented your idea, and the result is a much simpler and faster code. Thanks again, I have also updated the blog entry above and added the new code. This does not really need much tweaking when there are more than one match, just keep a list of all the matches and try each of these, just like normal hash collision handling.</description>
		<content:encoded><![CDATA[<p>Great idea A, thanks! This should be even faster. I will try this next week when I am back from my holidays.</p>
<p>UPDATE Ok I have just implemented your idea, and the result is a much simpler and faster code. Thanks again, I have also updated the blog entry above and added the new code. This does not really need much tweaking when there are more than one match, just keep a list of all the matches and try each of these, just like normal hash collision handling.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A</title>
		<link>http://martin.ankerl.com/2008/08/09/two-word-anagram-finder-algorithm/comment-page-1/#comment-2436</link>
		<dc:creator>A</dc:creator>
		<pubDate>Sun, 10 Aug 2008 06:30:23 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=156#comment-2436</guid>
		<description>&quot;Given a list of numbers, find all combination of two numbers that add up to a given number &quot;,

You trade memory for speed and make this faster.

can be solved using a hashmap in O(n)

soln:
&lt;pre&gt;M = {}
S = the target sum
for each element e in the list
      if M[S-e] exists? (e,S-e) is a pair
      add e to the M&lt;/pre&gt;

This will be ammortized O(n) - 

Caveat: if there is more than 1 repeat this may need tweaking..i.e. 1,2,2,2,3 
with sum S=4 
the pairs from the algo above are (2,2), (2,2) and (3,1)
in reality it is (2,2), (2,2) , (2,2) and (3,1) 
3 pairs of 2s because there are 3C2 ways of choosing a pair of 2s from three 2s.</description>
		<content:encoded><![CDATA[<p>&#8220;Given a list of numbers, find all combination of two numbers that add up to a given number &#8220;,</p>
<p>You trade memory for speed and make this faster.</p>
<p>can be solved using a hashmap in O(n)</p>
<p>soln:</p>
<pre>M = {}
S = the target sum
for each element e in the list
      if M[S-e] exists? (e,S-e) is a pair
      add e to the M</pre>
<p>This will be ammortized O(n) &#8211; </p>
<p>Caveat: if there is more than 1 repeat this may need tweaking..i.e. 1,2,2,2,3<br />
with sum S=4<br />
the pairs from the algo above are (2,2), (2,2) and (3,1)<br />
in reality it is (2,2), (2,2) , (2,2) and (3,1)<br />
3 pairs of 2s because there are 3C2 ways of choosing a pair of 2s from three 2s.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
