<?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>Suraj&#039;s blog &#187; Data structure</title>
	<atom:link href="http://www.surajshrestha.com.np/tag/data-structure/feed" rel="self" type="application/rss+xml" />
	<link>http://www.surajshrestha.com.np</link>
	<description>imagination more important than knowledge</description>
	<lastBuildDate>Sun, 08 Aug 2010 23:20:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Algorithm to calculate height of a binary tree</title>
		<link>http://www.surajshrestha.com.np/algorithm/algorithm-to-calculate-height-of-a-binary-tree.html</link>
		<comments>http://www.surajshrestha.com.np/algorithm/algorithm-to-calculate-height-of-a-binary-tree.html#comments</comments>
		<pubDate>Mon, 03 Aug 2009 22:33:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Binary Tree]]></category>
		<category><![CDATA[Data structure]]></category>
		<category><![CDATA[Recursive]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=216</guid>
		<description><![CDATA[Binary tree is a data structure of tree shape in which each node can have either 2 or 0 children(s). Height of a tree is the maximum depth of nodes of the tree. Here is the algorithm to that returns the height of the tree. It should be called by passing position of root node [...]]]></description>
			<content:encoded><![CDATA[<p>Binary tree is a data structure of tree shape in which each node can have either 2 or 0 children(s). Height of a tree is the maximum depth of nodes of the tree. Here is the algorithm to that returns the height of the tree. It should be called by passing position of root node of tree as argument.</p>
<blockquote>
<pre><em><span style="color: #000000;">Algorithm getHeight(pos)</span></em></pre>
<pre><em><span style="color: #000000;">     Input position pos of the node whose height is to be found out</span></em></pre>
<pre><em><span style="color: #000000;">     If (isInternal(pos))</span></em></pre>
<pre><em><span style="color: #000000;">             X = getHeight(leftchild(pos))</span></em></pre>
<pre><em><span style="color: #000000;">             Y = getHeight(rightchild(pos))</span></em></pre>
<pre><em><span style="color: #000000;">             Return greater(X,Y) + 1</span></em></pre>
<pre><em><span style="color: #000000;"> Return 0</span></em></pre>
</blockquote>
<p>The method names used above are</p>
<p><strong>isInternal(pos) </strong>- Returns true if the position pos is internal</p>
<p><strong>leftchild(pos)</strong> &#8211; Returns the position of the left child of the pos</p>
<p><strong>rightchild(pos)</strong> &#8211; Returns the position of the right child of the pos</p>
<p><strong>geater(X,Y)</strong> &#8211; Returns greater of X and Y.</p>
<p>At each node, the recursive algorithm will accumulate height of left and right sub tree and pass it to parent by adding 1 to the greater one. However, if the node is external it will simply return 0 to parent. This is how the algorithm works.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/algorithm/algorithm-to-calculate-height-of-a-binary-tree.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
