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
2 answers

Finding up to nth level of pathways in an undirected graph?

I have created an undirected graph with 6 vertices, visually represented like this: https://i.stack.imgur.com/EtIbO.png I would like to write a script that can find all paths from a starting point without revisiting the same node, with no given end…
server_kitten
  • 386
  • 3
  • 13
0
votes
3 answers

Traversal to print two BSTs ordered using recursion. Use of extra memory like arrays is not allowed

I was asked this question in an interview. Given are two BST (Binary Search Tree). We need to traverse the two trees in such a way that a merged sorted output is the result. Constraint is that we cannot use extra memory like arrays. I suggested a…
0
votes
1 answer

BST [homework] how does this method of iterative traversal work?

I'm using an example from a free book Open Data Structures (in Java) by Pat Morin. I believe i understand the concept of what is going on for tree traversal (keep going left until you can't go any more left, then right and then back up. I'm a little…
peter_gent
  • 175
  • 2
  • 4
  • 17
0
votes
3 answers

Performance of Morris Traversal vs recursive In-Order in a binary tree

I am doing some preparations before going to interviews and i just learned about Morris Traversal. This is Morris Traversal code which i wrote in Java(its working): protected void morrisTraversal(){ BinaryNode pre = null;//BinaryNode is a class…
0
votes
2 answers

MySQL modified preorder tree traversal - getting a subtree based on a node

I have a standard mptt tree table as per picture here on sitepont. I can't for the life of me find a good way to get an entire subtree based on a chosen node though. Example (from that linked page): Imagine that the tree is a menu, if someone…
0
votes
3 answers

how can get a tree with only one tree traversal?

consider I want to transfer a binary tree in a serialised way and I have only one string to pass that tree and I can use the help of only one traversal, is there any way I could do that?? - (was asked to me in Ebay).. in other words can a binary…
Madara
  • 150
  • 1
  • 8
0
votes
2 answers

Build unordered list from multidimensional array without recursion

I have a problem building an unordered list from multidimensional array containing entities and their children. The problem is I do not want to use recursion as the tree could get very deep and recursion could produce unnecessary load on…
shadyyx
  • 15,825
  • 6
  • 60
  • 95
0
votes
1 answer

What is the minimum cost to traverse a binary Tree

I want to traverse a Binary Tree with minimum cost, where cost of each edge is 1. Traversal is complete when each node of the tree is visited. For instance, the minimum cost of the traversal of following tree is 13. * / \ * * …
Mostafiz Rahman
  • 8,169
  • 7
  • 57
  • 74
0
votes
2 answers

C++, How to create and draw a Binary Tree then traverse it in Pre-Order

How do I create a Binary Tree and draw it using a Pre-Order Traversal strategy? The root would be the first number going in. I have a set of numbers: 48 32 51 54 31 24 39. 48 would be the root. How are the child nodes pushed onto the Binary…
Ryan
  • 11
  • 1
0
votes
2 answers

Median nodes in a binary tree

I had an exam with the following question I couldn't answer: We have a binary tree where each node has a certain height(from bottom) and a certain depth(from root). We start counting both from zero; for example: For a tree with a root with a single…
Gene Frank
  • 23
  • 1
  • 1
  • 4
0
votes
1 answer

What is the algorithm for serializing the DOM to an XML text file?

E.g. tree: A A1 A2 serialize to an xml: It seems either root-first traversal (preorder) or root-last traversal (postorder) is not enough to achieve this. What is the good way to do this?
JackWM
  • 10,085
  • 22
  • 65
  • 92
0
votes
1 answer

seg fault in BFS traversal of BST

I have implemented a binary tree and its BFS traversal. The program is below: struct elemq{ int ele; struct elemq *left; struct elemq *right; }; struct que{ struct elemq *ss; struct que *next; }; void qinsert(struct elemq…
Justin Carrey
  • 3,563
  • 8
  • 32
  • 45
0
votes
2 answers

How do I traverse a scene graph-like tree structure?

I have a scene graph where I have: class Node { public: struct { COLLISION_TYPE collisionType; void* boundingVolume; }collisionData; struct { XMFLOAT3 position; XMFLOAT3 rotation; }leafData; Node(Model* representModel, Node*…
0
votes
1 answer

Level Order Traversal of a tree

In order to do level order(BFS) traversal of a generic tree I wrote the following display function for the code mentioned in the link below. The problem is that each level is printed twice. Can someone tell me why. Original Code without this…
Sameer
  • 757
  • 1
  • 14
  • 35
0
votes
2 answers

Level Order traversal of a generic tree(n-ary tree) in java

(In case you want to avoid the lengthy explanation, all I am looking for is a level order traversal for a generic-tree(n-ary tree) in java. The code supplied works and needs the level order display function. Looked around for an hour but couldnt…
Sameer
  • 757
  • 1
  • 14
  • 35