TheDeveloperBlog.com

Home | Contact Us

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

Binary Tree Postorder Traversal

Binary Tree Postorder 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

Post-order traversal

Steps

  • Traverse the left sub-tree in post-order
  • Traverse the right sub-tree in post-order
  • visit the root

Algorithm

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

C Function

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

Example

Traverse the following tree by using post-order traversal


binary tree Post-order traversal
  • Print the left child of the left sub-tree of binary tree i.e. 23.
  • print the right child of the left sub-tree of binary tree i.e. 89.
  • print the root node of the left sub-tree i.e. 211.
  • Now, before printing the root node, move to right sub-tree and print the left child i.e. 10.
  • print 32 i.e. right child.
  • Print the root node 20.
  • Now, at the last, print the root of the tree i.e. 18.

The printing sequence will be 23, 89, 211, 10, 32, 18.


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