Language: EN FI

Exercises > Binary Search Tree Insertion

These exercises demonstrate the content of the ByTheMark service. These are meant for private individuals for learning data structures and algorithms. If you want to try out more content, you can register to the ByTheMark Personal free of charge.

Insert the given keys into the initially empty binary search tree.

Insert(Node root, Key k)
1 if (root == null) // insertion position found
2   return new Node(k);
3 if (k <= root.key) // proceed to the left branch
4   root.left = Insert(root.left, k);
5 else // k > root.key, i.e. proceed to the right branch
6   root.right = Insert(root.right, k);

  Last modified Tue Mar 01 20:54:04 EET 2011