Questions tagged [postorder]

A method of traversing binary trees, in which the node is processed after its children.

138 questions
25
votes
6 answers

Getting parent of a vertex in a perfect binary tree

I've got a perfect binary tree that's enumerated the post-order way. An example of such tree would be 15 7 14 3 6 10 13 1 2 4 5 8 9 11 …
Danstahr
  • 4,190
  • 22
  • 38
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
14
votes
2 answers

Real world pre/post-order tree traversal examples

I understand pre-order, in-order, and post-order tree traversal algorithms just fine. (Reference). I understand a few uses: in-order for traversing binary search trees in order, pre-order for cloning a tree. But I can't for the life of me come up…
Plutor
  • 2,867
  • 2
  • 25
  • 29
12
votes
3 answers

Recursion with yield return elements order in tree

I have a recursive function that returns all subtree nodes, given the starting root node. private IEnumerable getAllNodesRecursively(Node subnode) { foreach (Node node in subnode.Nodes) getAllNodesRecursively(node); yield…
Kornelije Petak
  • 9,412
  • 15
  • 68
  • 96
7
votes
3 answers

Is there a way to find the pre order traversal of a strictly binary tree from its post order traversal without building the tree?

I am given a post order traversal of a strictly binary tree and am asked to find the pre order traversal of it. Normally, I would go a build the tree first, then find the pre order traversal. But, I was wondering if there was any way to find the pre…
fresh42juice
  • 117
  • 6
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
6 answers

How to construct a binary tree from just the level order traversal string

Consider a binary tree with the following properties: An internal node (non-leaf node) has a value 1 if it has two children. A leaf node has a value 0 since it has no children. A level order traversal on the tree would generate a string of 1s and…
Jinson George
  • 139
  • 2
  • 11
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
4
votes
1 answer

Creating perfect binary trees with postorder traversal

I'm trying to build a perfect binary tree at h height using postorder traversal. Basically I'm trying to do this: height = 3 numbers = list(range(1, 2 ** height)) tree = buildTree(height, numbers) The result would be something like this: 7 3 …
Nick
  • 137
  • 1
  • 9
3
votes
1 answer

is this post order forest traversal correct?

I have a problem understanding how to traverse a forest post-order. the definition for it is: (source: Data structures using C by Rohit Khurana page 330) traverse the subtrees of the first tree in tree post-order. traverse the remaining trees of F…
Fatemeh Karimi
  • 914
  • 2
  • 16
  • 23
3
votes
1 answer

General Tree Post Order Traversal

var tree = { "name" : "root", "children" : [ { "name" : "first child", "children" : [ { "name" : "first child of first", "children" : [] }, { "name" : "second child of…
3
votes
1 answer

Postorder traversal on a ast.nodevisitor in Python

Is it possible to do a postorder traversal on an instance of ast.NodeVisitor in Python just by manipulating the ast.NodeVisitor.generic_visit()? I did this: class ExpParser(ast.NodeVisitor): def generic_visit(self, node): for x in…
Academia
  • 3,984
  • 6
  • 32
  • 49
2
votes
1 answer

function to create array of post order binary tree

Im trying to create a recursive function that creates an array of post order integers from a given tree. This is the code: //structure typedef struct node { // Each node holds a single integer. int data; // Pointers to the node's left…
2
votes
1 answer

How many rooted binary trees with exactly 11 nodes are pleasantrees?

A label rooted tree with exactly N nodes is a pleasant tree if and only if: each of its nodes is labeled with a positive integer between 1 to N. No 2 nodes have the same label A post-order traversal of the tree visited the nodes in increasing…
Romil
  • 55
  • 3
2
votes
1 answer

Constructing full binary tree given only postorder?

I'm trying to construct a full binary tree (full meaning that every non leaf node has two leaf nodes connecting to it, i.e. node->right and node->left are != NULL) given only the postorder traversal of the tree. In addition, I am given whether or…
mttrns
  • 75
  • 6
1
2 3
9 10