Summary
Keywords
Full Transcript
Support Simple Snippets by Donations - Google Pay UPI ID - tanmaysakpal11@okicici PayPal - paypal.me/tanmaysakpal11 --------------------------------------------------------------------------------------------- In this tutorial we will understand different tree traversal techniques in a binary tree. Tree traversal (also known as tree search and walking the tree) refers to the process of visiting (checking and/or updating) each node in a tree data structure, exactly once. Such traversals are classified by the order in which the nodes are visited. Binary tree traversal can be categorized mainly in 2 types - 1) Depth First Search(DFS) - These searches are referred to as depth-first search (DFS), since the search tree is deepened as much as possible on each child before going to the next sibling. a) Pre-order (NLR)(node - left - right) - - Access the data part of the current node. - Traverse the left subtree by recursively calling the pre-order function. - Traverse the right subtree by recursively calling the pre-order function. The pre-order traversal is a topologically sorted one, because a parent node is processed before any of its child nodes is done. b) In-order (LNR) - - Traverse the left subtree by recursively calling the in-order function. - Access the data part of the current node. - Traverse the right subtree by recursively calling the in-order function. In BST in-order traversal retrieves the keys in ascending sorted order. c) Post-order (LRN) - - Traverse the left subtree by recursively calling the post-order function. - Traverse the right subtree by recursively calling the post-order function. - Access the data part of the current node. 2) Breadth First Search - Trees can also be traversed in level-order, where we visit every node on a level before going to a lower level. This search is referred to as breadth-first search (BFS), as the search tree is broadened as much as possible on each depth before going to the next depth. --------------------------------------------------------------------------------------------- Timecodes - 0:00 Introduction 01:04 What is Tree Traversal? 03:10 Types of Tree Traversal - DFS & BFS 06:47 DFS - Preorder vs Inorder vs Postorder 25:10 Summary --------------------------------------------------------------------------------------------- Theory & Code article - https://simplesnippets.tech/what-is-binary-search-tree-bst-with-full-code-dsa/ Full DSA playlist - https://www.youtube.com/watch?v=XCyuHSJS7XE&list=PLIY8eNdw5tW_zX3OCzX7NJ8bL1p6pWfgG Full C++ Programming for Beginners Course - https://www.youtube.com/watch?v=AKNGgAXTark&list=PLIY8eNdw5tW_o8gsLqNBu8gmScCAqKm2Q --------------------------------------------------------------------------------------------- Simple Snippets Official Website - http://simplesnippets.tech/ Simple Snippets on Facebook - https://www.facebook.com/simplesnippets/ Simple Snippets on Instagram - https://www.instagram.com/simplesnippets/ Simple Snippets on Twitter - https://twitter.com/simplesnippet Simple Snippets Google Plus Page - https://plus.google.com/+SimpleSnippets Simple Snippets email ID - [email protected] For More Technology News, Latest Updates and Blog articles visit our Official Website - http://simplesnippets.tech/
