algorithm,data-structures,binary-tree,inorder,preorder

Start with the preorder traversal. Either it is empty, in which case you are done, or it has a first element, r0, the root of the tree. Now search the inorder traversal for r0. The left subtree will all come before that point and the right subtree will all come...

If you do an in-order traversal of a reversed BST you will get the numbers sorted in descending order. So in that case the order for your values will be: 20, 15, 10, 8, 6, 4, 2. So the successor of 8 will be 6.

java,arrays,binary-tree,inorder

myTree.inorder(0); // parameter : 0 inorder((node * 2)); // node = 0, node * 2 = 0, Therefore, the parameters will continue to be zero is an infinite loop. public class BinaryTree { char[] tree = {'k', 'q', 'r', 'g', 'e', 'i', 'y', 'p', 'l', 'b', 'x', 'm', 'g', 't',...

You want to use some kind of list structure to accumulate the data: void inorder(BSTNode r, List list) { if (r != null) { inorder(r.getLeft(), list); list.add(r.getData()); inorder(r.getRight(), list); } } Invoking the function with List list = new List(); inorder(bst, list); After inorder completes, list will contain the the...

Basically at every recursive call you continue if the node is not null. Hence the call node->left for the leaf node would not continue further and the nodes get printed in the next line as the recursive function unfolds. Dry run an example and verify for yourself....

java,recursion,binary-search-tree,inorder

The inorder successor of a given node is the lowest node in the right subtree of that node. To understand otherwise, it is the next node that will be printed in a simple in order traversal of the tree. If the node has a right child, this solution is simplified...

A C / \ / \ B C A D \ / D B It seems these trees both gives: null, B, null, A, null C, null D, null. But it's possible to save a binary tree of depth N in array of size 2N-1. A C / \...

algorithm,data-structures,tree,traversal,inorder

So the inorder is: E A C K F H D B G And the preorder must be from: a. FAEKCDBHG b. FAEKCDHGB c. EAFKHDCBG d. FEAKDCHBG You should proceed by drawing the tree for each of these options while also making it fit with the inorder traversal and see...

algorithm,binary-tree,binary-search-tree,inorder,preorder

If you have in-order traversal together with one of pre/post-order, that is enough to reconstruct a binary tree. Moreover, in case of BST (binary search tree), post-order or pre-order alone is sufficient. In your case, reconstructing a BST from pre-order 4, 1, 2, 3, 5, 6, 7, 8 gives the...

One solution that also permits sublinear deletion is to build a data structure D that uses a linked list D.L for the traversal in order of insertion, and a sorted tree D.T for the traversal in order of magnitude. But how to link them to additionally achieve a remove operation...

recursion,binary-search-tree,inorder

Like all recursion*, the call stack contains the control for your operations as the recursive calls start to return - program control is returned to the point where your current_node pointer is set to the parent that you were examining prior to making the recursive calls. (* All recursion, unless...