Support us


to write
more tutorials




to create new
visualizers




to keep sharing
free knowledge
for you


every dollar helps
Explore the English language on a new scale using AI-powered English language navigator.

Binary search tree. List values in order

To construct an algorithm listing BST's values in order, let us recall binary search tree property:

  • left subtree of a node contains only values lesser, than the node's value;
  • right subtree of a node contains only values greater, than the node's value.
Algorithm looks as following:
  1. get values in order from left subtree;
  2. get values in order from right subtree;
  3. result for current node is (result for left subtree) join (current node's value) join (result for right subtree).
Running this algorithm recursively, starting form the root, we'll get the result for whole tree. Let us see an example of algorithm, described above.

Example

BST get values in order example, step 1
BST get values in order example, step 2
BST get values in order example, step 3
BST get values in order example, step 4
BST get values in order example, step 5
BST get values in order example, step 6

Recommended books

  1. Cormen, Leiserson, Rivest. Introduction to algorithms. (Theory)
  2. Aho, Ullman, Hopcroft. Data Structures and Algorithms. (Theory)
  3. Robert Lafore. Data Structures and Algorithms in Java. (Practice)
  4. Mark Allen Weiss. Data Structures and Problem Solving Using C++.(Practice)

Contribute to AlgoList

Liked this tutorial? Please, consider making a donation. Contribute to help us keep sharing free knowledge and write new tutorials.


Every dollar helps!

Leave a reply

Your name (optional):
Your e-mail (optional):
Message: