<?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>binary tree inorder traversal - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/binary-tree-inorder-traversal/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/binary-tree-inorder-traversal/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 13 Sep 2021 06:25:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>binary tree inorder traversal - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/binary-tree-inorder-traversal/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Inorder Tree Traversal without recursion and without stack ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/inorder-tree-traversal-without-recursion-and-without-stack/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/inorder-tree-traversal-without-recursion-and-without-stack/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 17:29:55 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[Altimetrik India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Applied Materials interview questions and answers]]></category>
		<category><![CDATA[Bharti Airtel interview questions and answers]]></category>
		<category><![CDATA[binary search tree inorder traversal]]></category>
		<category><![CDATA[binary search tree traversal inorder preorder postorder example]]></category>
		<category><![CDATA[binary tree inorder traversal]]></category>
		<category><![CDATA[BMC Software interview questions and answers]]></category>
		<category><![CDATA[bst inorder traversal]]></category>
		<category><![CDATA[c# tree traversal without recursion]]></category>
		<category><![CDATA[Capgemini interview questions and answers]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[CGI Group Inc interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[Ciena Corporation interview questions and answers]]></category>
		<category><![CDATA[Collabera Te interview questions and answers]]></category>
		<category><![CDATA[construct binary tree from preorder and inorder traversal]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[Genpact interview questions and answers]]></category>
		<category><![CDATA[Globallogic India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[inorder preorder postorder traversal]]></category>
		<category><![CDATA[inorder preorder postorder traversal examples pdf]]></category>
		<category><![CDATA[inorder preorder postorder traversal without recursion in c]]></category>
		<category><![CDATA[inorder traversal]]></category>
		<category><![CDATA[inorder traversal algorithm]]></category>
		<category><![CDATA[inorder traversal example]]></category>
		<category><![CDATA[inorder traversal iterative python]]></category>
		<category><![CDATA[inorder traversal java]]></category>
		<category><![CDATA[inorder traversal python]]></category>
		<category><![CDATA[inorder traversal with recursion]]></category>
		<category><![CDATA[inorder traversal without recursion]]></category>
		<category><![CDATA[inorder traversal without recursion and stack]]></category>
		<category><![CDATA[inorder traversal without recursion in c]]></category>
		<category><![CDATA[inorder traversal without recursion using stack in c]]></category>
		<category><![CDATA[inorder tree traversal]]></category>
		<category><![CDATA[inorder tree traversal without recursion]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[postorder traversal algorithm using stack]]></category>
		<category><![CDATA[postorder traversal without recursion]]></category>
		<category><![CDATA[preorder traversal without recursion]]></category>
		<category><![CDATA[SAP Labs India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Sapient Consulting Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[UnitedHealth Group interview questions and answers]]></category>
		<category><![CDATA[what is inorder traversal]]></category>
		<category><![CDATA[Wipro Infotech interview questions and answers]]></category>
		<category><![CDATA[WM Global Technology Services India Pvt.Ltd Limited (WMGTS) interview questions and answers]]></category>
		<category><![CDATA[Xoriant Solutions Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Yodlee Infotech Pvt Ltd interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=507</guid>

					<description><![CDATA[Answer : To traverse the tree using Morris Traversal...
]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="inorder-tree-traversal-without-recursion-and-without-stack" class="color-pink" style="text-align: justify;">Inorder Tree Traversal without recursion and without stack ?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>To traverse the tree using Morris Traversal is based on <a href="https://www.wikitechy.com/technology/threaded-binary-tree/" target="_blank" rel="noopener">Threaded Binary Tree</a> which means without using stack and recursion. In this traversal, we first create links to <a href="https://www.wikitechy.com/technology/python-program-inorder-successor-binary-search-tree/" target="_blank" rel="noopener">Inorder successor</a> and print the data using these links, and finally revert the changes to restore original tree.</li>
</ul>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li style="list-style-type: none;">
<ul>
<li>If current does not have left child
<ul>
<li>Print current’s data</li>
<li>Go to the right, i.e., current = current-&gt;right</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li style="list-style-type: none;">
<ul>
<li>Else
<ul>
<li>Make current as right child of the rightmost</li>
<li>node in current&#8217;s left subtree</li>
<li>Go to this left child, i.e., current = current-&gt;left</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>When the tree is modified through the traversal, it is reverted back to its original shape after the completion.</li>
<li>Unlike Stack based traversal, no extra space is required for this traversal.</li>
</ul>
</div>
</div>
<div class="read-also" style="text-align: justify;"></div>
<div class="text-center row" style="text-align: justify;"></div>
<div class="TextHeading">
<div class="hddn">
<h2 id="sample-code-in-c" class="color-red" style="text-align: justify;">Sample Code in C++</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">#include &lt;stdio.h&gt; <br/>#include &lt;stdlib.h&gt; <br/><br/>/* A binary tree tNode has data, pointer to left child <br/>and a pointer to right child */<br/>struct traversalNode { <br/>	int data; <br/>	struct traversalNode* left; <br/>	struct traversalNode* right; <br/>}; <br/><br/>/* Function to traverse binary tree without recursion and <br/>without stack */<br/>void MorrisTraversal(struct traversalNode* root) <br/>{ <br/>	struct traversalNode *current, *pre; <br/><br/>	if (root == NULL) <br/>		return; <br/><br/>	current = root; <br/>	while (current != NULL) { <br/><br/>		if (current-&gt;left == NULL) { <br/>			printf(&quot;%d &quot;, current-&gt;data); <br/>			current = current-&gt;right; <br/>		} <br/>		else { <br/><br/>			/* Find the inorder predecessor of current */<br/>			pre = current-&gt;left; <br/>			while (pre-&gt;right != NULL &amp;&amp; pre-&gt;right != current) <br/>				pre = pre-&gt;right; <br/><br/>			/* Make current as right child of its inorder <br/>			predecessor */<br/>			if (pre-&gt;right == NULL) { <br/>				pre-&gt;right = current; <br/>				current = current-&gt;left; <br/>			} <br/><br/>			/* Revert the changes made in if part to restore <br/>			the original tree i.e., fix the right child <br/>			of predecssor */<br/>			else { <br/>				pre-&gt;right = NULL; <br/>				printf(&quot;%d &quot;, current-&gt;data); <br/>				current = current-&gt;right; <br/>			} /* End of if condition pre-&gt;right == NULL */<br/>		} /* End of if condition current-&gt;left == NULL*/<br/>	} /* End of while */<br/>} <br/><br/>/* UTILITY FUNCTIONS */<br/>/* Helper function that allocates a new tNode with the <br/>given data and NULL left and right pointers. */<br/>struct traversalNode* newtraversalNode(int data) <br/>{ <br/>	struct traversalNode* node = new traversalNode; <br/>	node-&gt;data = data; <br/>	node-&gt;left = NULL; <br/>	node-&gt;right = NULL; <br/><br/>	return (node); <br/>} <br/><br/>/* Driver program to test above functions*/<br/>int main() <br/>{ <br/><br/>	/* Constructed binary tree is <br/>			12 <br/>		/ \ <br/>		13	 14 <br/>	/ \ <br/>	15	 16 <br/>*/<br/>	struct traversalNode* root = newtraversalNode(12); <br/>	root-&gt;left = newtraversalNode(13); <br/>	root-&gt;right = newtraversalNode(14); <br/>	root-&gt;left-&gt;left = newtraversalNode(15); <br/>	root-&gt;left-&gt;right = newtraversalNode(16); <br/><br/>	MorrisTraversal(root); <br/><br/>	return 0; <br/>} </code></pre> </div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output" class="color-red">Output</h2>
</div>
</div>
<div class="Output" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs" data-lang=""><span class="nt">15 13 16 12 14 
</span></code></pre>
</figure>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li style="text-align: justify;">Time Complexity : O(n) If we investigate, we can see that each edge of the tree is crossed at-most multiple times.</li>
<li style="text-align: justify;">Also, in most pessimistic scenario same number of additional edges (as info tree) are made and evacuated.</li>
</ul>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/inorder-tree-traversal-without-recursion-and-without-stack/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
