Questions tagged [inorder]

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

315 questions
22
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
  • 651
  • 2
  • 7
  • 24
21
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
  • 7,913
  • 28
  • 108
  • 196
19
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,912
  • 14
  • 59
  • 85
18
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,718
  • 2
  • 19
  • 36
14
votes
5 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
  • 3,137
  • 10
  • 48
  • 87
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,486
  • 8
  • 33
  • 39
13
votes
2 answers

Can a non-binary tree be tranversed in order?

We are dealing with a Most similar neighbour algorithm here. Part of the algorithm involves searching in order over a tree. The thing is that until now, we can't make that tree to be binary. Is there an analog to in order traversal for non-binary…
Tom
  • 43,810
  • 29
  • 138
  • 169
12
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,779
  • 1
  • 21
  • 41
9
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
  • 19,700
  • 9
  • 74
  • 90
7
votes
4 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
  • 575
  • 1
  • 11
  • 21
6
votes
1 answer

In- pre- and post-order NAMES

What is the logic behind the names in-order, pre-order and post-order? Why are they called like that? In-order. Why the word "in", what is it "in"? Pre-order. "Pre", means "previous", but previous what? Post-order. "Post" means "after", but after…
Data
  • 69
  • 4
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,407
  • 8
  • 42
  • 79
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
  • 1
  • 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
  • 319
  • 3
  • 17
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
1
2 3
20 21