Questions tagged [tree-traversal]

The process of visiting each node in a tree based on certain criterion.

The process of visiting each node in a tree based on certain criterion.

Use this tag for programming questions related to traversal of all types of trees.

See also:

832 questions
0
votes
1 answer

BST traversal in C

Traversing a tree using C. It will accept a character and prints the post fix/ in fix/ pre fix. The problem is when it prints the output it looks like this input a b c d e f g h i IN ORDER: C abcdefghi PRE ORDER: C …
Eyam Saye
  • 39
  • 7
0
votes
1 answer

PHP traverse category subcategory tree array into a custom 2D array

I have an parent child array similar to this: Array ( [0] => Array ( [category_id] => 1 [category_name] => Home & Garden [parent_id] => 0 [level] => 1 ) [1] => Array ( …
PHPDev
  • 139
  • 1
  • 3
  • 12
0
votes
1 answer

How to construct a tree given a level-order traversal?

I have read a similar question on this matter, but I don't need to build a BST. From a given input, for example: 2 0 3 0 1 0 3, which will build: Explanation: 2 -> the root has 2 children 0 -> the left child of the root has no children 3 -> the…
Mark
  • 253
  • 1
  • 5
  • 22
0
votes
1 answer

A Java method to see whether is a dom tree object a subset of another dom tree object

I am going to check that if a dom tree java object contains another dom tree java object or not? what is the most efficient way of doing that? If I use recursive method for that probably the whole process would be really time consuming so is there…
Ali
  • 1,759
  • 2
  • 32
  • 69
0
votes
1 answer

Is the order ascending?

I have a question about the traversal of a tree. When we print the values of a binary search tree using in order traversal are the values printed in an ascending order??
Mary Star
  • 375
  • 7
  • 27
0
votes
1 answer

Boolean Expression Optimization For All AND Conditions

I am trying to solve the boolean expression optimization problem for a simple rule engine. Here is what I am trying to do, lets say if I have following 5 conditions (where a,b,c,d,e,f are complex boolean expressions) if (a AND b AND c AND d AND e…
0
votes
1 answer

Step-by-step method for coming up with recursive algorithms for tree traversals?

I'm trying to understand intuitively how to create recursive functions (for anything) but mostly for traversing a tree to check if that tree meets certain criteria. For a random example, counting the number of nodes in a Binary Tree that are not the…
0
votes
2 answers

Searching in Pre Order Traversal way

I have a binary search tree. I know how to search using the search property. But my task is to search the tree without using search property.(Say, search in binary tree) This is how I have to search. 1. If you find the value in the current node…
sanjay Kumar
  • 140
  • 1
  • 14
0
votes
1 answer

How to list in an alphabetical order the words of a ternary search tree?

How can I go about listing the words a TST contains in an alphabetical order? Unlike BSTs where an in-order traversal will do the trick, this won't work TST. Neither would pre-order nor post-order traversals. More so, the nodes of TST contain…
mkab
  • 933
  • 4
  • 16
  • 31
0
votes
1 answer

Error implementing Level Order Traversal Binary Search Tree with Java PriorityQueue

I am trying to implement a level order traversal for my BST, but I am getting a weird error. Here is the code: public void levelOrderTraverseTree(Node focusNode) { PriorityQueue currentLevel = new PriorityQueue(); …
Zach
  • 4,555
  • 9
  • 31
  • 52
0
votes
3 answers

Java Binary Tree. Printing InOrder traversal

I am having some problems printing an inOrder traversal of my binary tree. Even after inserting many items into the tree it's only printing 3 items. public class BinaryTree { private TreeNode root; private int size; public…
user69514
  • 26,935
  • 59
  • 154
  • 188
0
votes
2 answers

is wikipedia iterative postorder tree traversal pseudo code wrong?

Here is the pseudo code that wikipedia gives for iterative postorder tree traversal. iterativePostorder(node) parentStack = empty stack lastnodevisited = null while (not parentStack.isEmpty() or node ≠ null) if (node ≠ null) …
0
votes
1 answer

Print all paths in an n-ary tree according to their count

I have the following n-ary tree. The value in the nodes are of the form names {count}. The count value of any node is the number of paths that include the node. I need to print all paths(from root to leaf) in the tree until the count of that node…
GvanJoic
  • 213
  • 2
  • 14
0
votes
1 answer

Traversing 2-3-4 Tree

I have been thinking lately and have come up with two options for finding the inorder traversal of a 2-3-4 tree. One of them is recursive approach with a switch case on the type of node it is and the other is more of an iterative approach. For…
Telo Springs
  • 45
  • 1
  • 12
0
votes
1 answer

Finding PostOrder traversal from LevelOrder traversal without constructing the tree

Given a binary tree where value of each internal node is 1 and leaf node is 0. Every internal node has exactly two children. Now given level order traversal of this tree return postorder traversal of the same tree. This question can be easily solved…
Tanu Saxena
  • 779
  • 6
  • 15