<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fan&#039;s blog &#187; CS</title>
	<atom:link href="http://fkpwolf.net/category/cs/feed/" rel="self" type="application/rss+xml" />
	<link>http://fkpwolf.net</link>
	<description>无为而无不为</description>
	<lastBuildDate>Sun, 13 May 2012 13:24:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>树的路径查找算法</title>
		<link>http://fkpwolf.net/2011/03/18/find-path-within-tree/</link>
		<comments>http://fkpwolf.net/2011/03/18/find-path-within-tree/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 03:14:40 +0000</pubDate>
		<dc:creator>Fan Fan</dc:creator>
				<category><![CDATA[CS]]></category>

		<guid isPermaLink="false">http:///?p=926</guid>
		<description><![CDATA[问题：对于树中的某个节点，找到他在树中的路径。比如如下图中Z的path为{0, 1, 3, 1}。 最原始的DFS算法为： private static void getPath(List&#60;Entry&#62; list, ID id, ArrayList&#60;Integer&#62; matchPath, int... path) { for (int i = 0; i &#60; list.size(); i++) { int length = path.length; int[] currentPath = new int[length + 1]; System.arraycopy(path, 0, currentPath, 0, length); currentPath[length] = i; Entry entry = list.get(i); if (id.equals(entry.id)) { if (matchPath.size() [...]]]></description>
			<content:encoded><![CDATA[<p><strong>问题</strong>：对于树中的某个节点，找到他在树中的路径。比如如下图中Z的path为{0, 1, 3, 1}。</p>
<p><a href="http://fkpwolf.net/WordPress/wp-content/uploads/2011/03/fig457_01_0.jpg"><img class="alignnone size-full wp-image-928" title="fig457_01_0" src="http://fkpwolf.net/WordPress/wp-content/uploads/2011/03/fig457_01_0.jpg" alt="" width="300" height="92" /></a></p>
<p>最原始的DFS算法为：</p>
<pre class="brush:java">private static void getPath(List&lt;Entry&gt; list, ID id, ArrayList&lt;Integer&gt; matchPath,
int... path) {
  for (int i = 0; i &lt; list.size(); i++) {
    int length = path.length;
    int[] currentPath = new int[length + 1];
    System.arraycopy(path, 0, currentPath, 0, length);
    currentPath[length] = i;

    Entry entry = list.get(i);
    if (id.equals(entry.id)) {
      if (matchPath.size() == 0) {
        for (int j : currentPath) {// clone
          matchPath.add(j);
        }
      }
    } else
       getPath(entry.getChildren(), id, matchPath, currentPath);
  }
}
</pre>
<p>但是这种算法虽然完成了任务，但总觉得过于罗嗦。写好后三个月，又摸回去改了改，结果如下，使用了Stack来和DFS互动。</p>
<pre class="brush:java">private static void getPath(List&lt;Entry&gt; list, ID id, Stack&lt;Integer&gt; path, Flag isFound) {
  for (int i = 0; i &lt; list.size() &amp;&amp; !isFound.value; i++) {
    Entry entry = list.get(i);
    path.push(i);
    if (id.equals(entry.id)) {
      isFound.value = true;
      return;
    } else{
      getPath(entry.getChildren(), id, path, isFound);
    }
  }
  if(isFound.value)
    return;
  if ( !path.empty())
    path.pop();
}</pre>
<p>简单的才是对的，要有这种信念。做人就得信，做&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://fkpwolf.net/2011/03/18/find-path-within-tree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Skip List查找算法</title>
		<link>http://fkpwolf.net/2007/10/14/skip-list%e6%9f%a5%e6%89%be%e7%ae%97%e6%b3%95/</link>
		<comments>http://fkpwolf.net/2007/10/14/skip-list%e6%9f%a5%e6%89%be%e7%ae%97%e6%b3%95/#comments</comments>
		<pubDate>Mon, 15 Oct 2007 02:47:00 +0000</pubDate>
		<dc:creator>Fan Fan</dc:creator>
				<category><![CDATA[CS]]></category>

		<guid isPermaLink="false">http:///2007/10/14/skip-list%e6%9f%a5%e6%89%be%e7%ae%97%e6%b3%95/</guid>
		<description><![CDATA[最先是从InfoQ上（Java集合类、Skip列表以及Google）看到的。可以将该算法形象的比喻为带索引的地址本。一般的说，该算法属于Red-Black tree（Java中TreeMap的算法）的变形。 to be continued]]></description>
			<content:encoded><![CDATA[<p>最先是从InfoQ上（<a href="http://www.infoq.com/cn/news/2007/10/collections-api">Java集合类、Skip列表以及Google</a>）看到的。可以将该算法形象的比喻为<a href="http://epaperpress.com/sortsearch/">带索引的地址本</a>。一般的说，该算法属于Red-Black tree（Java中TreeMap的算法）的变形。</p>
<p><span style="font-style: italic;">to be continued</span></p>
]]></content:encoded>
			<wfw:commentRss>http://fkpwolf.net/2007/10/14/skip-list%e6%9f%a5%e6%89%be%e7%ae%97%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

