TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Binary Tree Inorder Traversal

Binary Tree Inorder Traversal with Introduction, Asymptotic Analysis, Array, Pointer, Structure, Singly Linked List, Doubly Linked List, Circular Linked List, Binary Search, Linear Search, Sorting, Bucket Sort, Comb Sort, Shell Sort, Heap Sort, Merge Sort, Selection Sort, Counting Sort, Stack, Qene, Circular Quene, Graph, Tree, B Tree, B+ Tree, Avl Tree etc.

<< Back to BINARY

In-order traversal

Steps

  • Traverse the left sub-tree in in-order
  • Visit the root
  • Traverse the right sub-tree in in-order

Algorithm

  • Step 1: Repeat Steps 2 to 4 while TREE != NULL
  • Step 2: INORDER(TREE -> LEFT)
  • Step 3: Write TREE -> DATA
  • Step 4: INORDER(TREE -> RIGHT)
    [END OF LOOP]
  • Step 5: END

C Function

void in-order(struct treenode *tree)
	{
		if(tree != NULL)
		{
			in-order(tree→ left);
			printf("%d",tree→ root);
			in-order(tree→ right);
		}
	}

Example

Traverse the following binary tree by using in-order traversal.


Binary Tree In-order Traversal
  • print the left most node of the left sub-tree i.e. 23.
  • print the root of the left sub-tree i.e. 211.
  • print the right child i.e. 89.
  • print the root node of the tree i.e. 18.
  • Then, move to the right sub-tree of the binary tree and print the left most node i.e. 10.
  • print the root of the right sub-tree i.e. 20.
  • print the right child i.e. 32.
  • hence, the printing sequence will be 23, 211, 89, 18, 10, 20, 32.

Next TopicDoubly Linked List




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf