Questions tagged [inorder]

A method of traversing binary trees, in which the node is processed after its left child, but before its right child.

274 questions
18
votes
2 answers

How many traversals need to be known to construct a BST

I am very confused by a number of articles at different sites regarding constructing a Binary Search Tree from any one traversal (pre,post or in-order), or a combination of any two of them. For example, at this page, it says that given the pre,post…
SexyBeast
  • 8,635
  • 25
  • 92
  • 179
17
votes
4 answers

How does inorder+preorder construct unique binary tree?

Recently, my questions were marked duplicate, like this , even if they weren't. So, let me start with following and then I'll explain my question. Why this question is not a duplicate? I'm not asking how to create a binary tree when inorder &…
Abhishek
  • 6,114
  • 12
  • 46
  • 78
16
votes
8 answers

How to do in-order traversal of a BST without recursion or stack but using parent pointers?

Is it possible to do an iterative in-order-traversal on a BST whose node has a parent pointer (the parent of the root is null) without using a visited flag or a stack? I googled and didn't find a reply. The point is, how can I know - at a certain…
OmarOthman
  • 1,588
  • 2
  • 17
  • 35
14
votes
3 answers

Why is the space complexity of a recursive inorder traversal O(h) and not O(n)

So I know that the space complexity of a recursive in order traversal is O(h) and not O(n) as h = tree height and n = number of nodes in the tree. Why is that? Lets say that this is the code for the traversal: public void inorderPrint (TreeNode…
NotSure
  • 541
  • 1
  • 5
  • 21
13
votes
1 answer

How to list contents of a directory IN ORDER with node.js?

I'm a fairly experienced programmer and I've just recently discovered node.js. I love JavaScript because that's where I started (Web Development) so being able to write server-side code with its is amazing. Currently, I'm working on a simple…
Brandon
  • 4,436
  • 7
  • 30
  • 39
13
votes
2 answers

Can a non binary tree be tranversed in order?

We are dealing with a Most similar neigthbour algorithm here. Part of the algorithm involves searching in order over a tree. The thing is that until now, we cant make that tree to be binary. Is there an analog to in order traversal for non binary…
Tom
  • 39,851
  • 25
  • 129
  • 164
11
votes
2 answers

How does TCP implement/guarantee in-order data transmission?

I was wondering how exactly does TCP implement in-order delivery. lets say this is list of events packet1 sent , ack received. packet2 sent , ack not-received. packet3 sent. packet4 sent. ack4 received. ack3 received. ack2 received. Can you…
Dunes Buggy
  • 1,669
  • 1
  • 21
  • 39
11
votes
3 answers

Inorder Binary Tree Traversal (using Python)

I am trying to perform an inorder traversal of a tree. The code itself feels right, except it is not working properly. I have a feeling it has to either do with the if condition, how append works in python, or something perhaps with return. This…
Jane Sully
  • 2,375
  • 8
  • 29
  • 60
8
votes
2 answers

How do I infer the usage of parentheses when translating an expression tree?

I am working on translating an expression tree to a format that resembles infix notation; I am not evaluating the tree or executing its operations. The tree contains both logical and relational operations, and I would like to emit parentheses in an…
Steve Guidi
  • 18,493
  • 8
  • 68
  • 86
6
votes
3 answers

How does this inorder traversal algorithm work?

I don't have much experience with recursion, so I'm having a hard time determining exactly how this algorithm works: public static void inorder(Node n) { if (n != null) { inorder(n.getLeft()); System.out.print(n.data + " "); …
Haque1
  • 545
  • 1
  • 9
  • 21
6
votes
2 answers

Finding the other two traversals of a Binary Tree when given only one traversal

I know you can reconstruct a binary tree when given its inorder and preorder traversals as strings, but is it possible to find the postorder and/or preoder traversals when only given the inorder traversal?
kjh
  • 3,168
  • 8
  • 32
  • 71
6
votes
2 answers

Wanted: Recurrence Formula of In-Order binary tree output method

I'm in a bit of a jam searching for the recurrence formula of this java method void printInorder(Node v) { if(v != null) { printInorder(v.getLeft()); System.out.println(v.getData()); printInorder(v.getRight()); …
Ben
  • 99
  • 7
5
votes
1 answer

Is it possible to traverse a k-ary tree in-order?

According to the Homespring proposed language standard, salmon travelling upstream need to perform "an in-order search of the river system … to find a river node with the same name as the salmon" on the fish tick up (section 6.4.2). The problem is…
Ontonator
  • 310
  • 2
  • 15
5
votes
3 answers

Finding Preoder from Just Inorder Traversal?

I ran into a Mid-Exam Question, that took 4 days ago, I couldent underestand it! Suppose we have the answer given when we have an inorder traversal of a tree then how come we will find out the solution in case of a preorder traversal. I have the…
user4627889
4
votes
4 answers

construct a binary tree from in-order and level-order traversal

Firstly, I'd like to state this is not a homework. I'm preparing an interview and encountering this problem. I guess we can pass the definition of in-order and level-order traversal. :-). For example: 50 / \ 10 60 / \ /…
Fihop
  • 2,977
  • 6
  • 36
  • 62
1
2 3
18 19