Binary Search Trees

A Binary Search tree is organized in a Binary Tree. Such a tree can be defined by a linked data structure in which a particular node is an object. In addition to a key field, each node contains field left, right, and p that point to the nodes correspon…


This content originally appeared on DEV Community and was authored by divya08296

A Binary Search tree is organized in a Binary Tree. Such a tree can be defined by a linked data structure in which a particular node is an object. In addition to a key field, each node contains field left, right, and p that point to the nodes corresponding to its left child, its right child, and its parent, respectively. If a child or parent is missing, the appropriate field contains the value NIL. The root node is the only node in the tree whose parent field is Nil.

  1. In-Order-Tree-Walk (x): Always prints keys in binary search tree in sorted order.

INORDER-TREE-WALK (x) - Running time is θ(n)

  1. If x ≠ NIL.
  2. then INORDER-TREE-WALK (left [x])
  3. print key [x]
  4. INORDER-TREE-WALK (right [x])
    1. PREORDER-TREE-WALK (x): In which we visit the root node before the nodes in either subtree.

PREORDER-TREE-WALK (x):

  1. If x ≠ NIL.
  2. then print key [x]
  3. PREORDER-TREE-WALK (left [x]).
  4. PREORDER-TREE-WALK (right [x]).


This content originally appeared on DEV Community and was authored by divya08296


Print Share Comment Cite Upload Translate Updates
APA

divya08296 | Sciencx (2021-05-04T10:48:25+00:00) Binary Search Trees. Retrieved from https://www.scien.cx/2021/05/04/binary-search-trees/

MLA
" » Binary Search Trees." divya08296 | Sciencx - Tuesday May 4, 2021, https://www.scien.cx/2021/05/04/binary-search-trees/
HARVARD
divya08296 | Sciencx Tuesday May 4, 2021 » Binary Search Trees., viewed ,<https://www.scien.cx/2021/05/04/binary-search-trees/>
VANCOUVER
divya08296 | Sciencx - » Binary Search Trees. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/04/binary-search-trees/
CHICAGO
" » Binary Search Trees." divya08296 | Sciencx - Accessed . https://www.scien.cx/2021/05/04/binary-search-trees/
IEEE
" » Binary Search Trees." divya08296 | Sciencx [Online]. Available: https://www.scien.cx/2021/05/04/binary-search-trees/. [Accessed: ]
rf:citation
» Binary Search Trees | divya08296 | Sciencx | https://www.scien.cx/2021/05/04/binary-search-trees/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.