Binary Search Tree graph
A Binary Search Tree is a binary tree with a search property where elements in
the left sub-tree are less than the root and elements in the right sub-tree are
greater than the root.

Walking (Traversing) a Binary Search Tree
There can be 3 types of tree traversals in a binary tree as below.
Pre-Order traversal
In this traversal the traversal happens in the following order.
For
the binary search tree, displayed above the Pre-Order traversal would be as
follows.

The C# implementation for the same is as follows.
public void PreOrder_Rec (TNode root)
{
if (root != null)
{
Console.Write(root.Data +" ");
PreOrder_Rec(root.Left);
PreOrder_Rec(root.Right);
}
}
In-Order traversal
In this traversal the traversal happens in following order:
For
the binary search tree, displayed above the In-Order traversal would be as
follows.

The C# implementation for that is as follows.
public void InOrder_Rec(TNode root)
{
if (root != null)
{
InOrder_Rec(root.Left);
Console.Write(root.Data +" ");
InOrder_Rec(root.Right);
}
}
Post-Order traversal
In this traversal the traversal happens in the following order:
For
the binary search tree, displayed above the Post-Order traversal would be as
follows.

The C# implementation for that is as follows:
public void PostOrder_Rec(TNode root)
{
if (root != null)
{
PostOrder_Rec(root.Left);
PostOrder_Rec(root.Right);
Console.Write(root.Data +" ");
}
}
Important Notes
For Additional task:


Links:
1. https://www.c-sharpcorner.com/UploadFile/19b1bd/binarysearchtreewalkstraversal-implementation-using-C-Sharp/
2. https://en.wikibooks.org/wiki/A-level_Computing_2009/AQA/Problem_Solving,_Programming,_Operating_Systems,_Databases_and_Networking/Programming_Concepts/Tree_traversal_algorithms_for_a_binary_tree
Скачано с www.znanio.ru
Материалы на данной страницы взяты из открытых источников либо размещены пользователем в соответствии с договором-офертой сайта. Вы можете сообщить о нарушении.