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
4
votes
1 answer

Arangodb custom filter/visitor for my tree graph

I have a graph with two edge definitions like this: isDepartment: [organisation] -> [organisation] hasAccess: [user] -> [organisation] Organisations are nested in a tree (no cycles). There are multiple top-level organisations without any incoming…
Sander Marechal
  • 22,978
  • 13
  • 65
  • 96
4
votes
3 answers

BST preorder traversal and writing tree content to temporary array

I'm trying to write binary search tree's content to temporary array in order to use in main. However I'm not sure how to do it... I have tried something like this: void Book::preorder(TreeNode *ptr, Person &temp[], int x) { if(ptr!=NULL) { …
Onur Senture
  • 519
  • 5
  • 16
4
votes
1 answer

Java - Evaluating Node Values along a Binary Tree

I am new to Tree structures. I am trying to design an algorithm which takes as input a predetermined tree. It should then seed the root of the tree with an object of my own design (I don't think it's relevant to the design of the algorithm, but the…
4
votes
1 answer

How to find the most profitable path in a board

assume that we have a board like this : and we want to find the most profitable path from left to right with the following movement pattern : for example in this board the most profitable path is : i.e. {2, 0} -> {2, 1} -> {3, 2} -> {3, 3} I…
FaNaJ
  • 1,329
  • 1
  • 16
  • 39
4
votes
1 answer

Tree traversal in Java with Generic classes

To be precise, I am trying to flatten a tree and I am stuck on trying to get the values of private attributes in a generic class using a generic function. I have attached the classes to show how the tree is structured exactly. But it's looks…
whatever123
  • 179
  • 1
  • 7
4
votes
3 answers

What happens to an array during recursion in C?

In the following code I try to print all paths from the root to leaves in a Binary Tree. If I write a recursive function as follows : void printPath(BinaryTreeNode * n, int path[],int pathlen) { //assume base case and initializations…
Dubby
  • 1,154
  • 3
  • 16
  • 31
4
votes
5 answers

N-ary trees - is it symmetric or not

Given an N-ary tree, find out if it is symmetric about the line drawn through the root node of the tree. It is easy to do it in case of a binary tree. However for N-ary trees it seems to be difficult
rakeshr
  • 1,027
  • 3
  • 17
  • 25
4
votes
1 answer

Traverse upto leaf node iOS in Tree Structure TableView

I am stuck at the point where I want to delete the particular Row Object from table but It is dynamic tree structure means object can be created, deleted, reordered, etc at any time using all the Table methods. Tree Structure is dynamic so How to…
krunal
  • 452
  • 3
  • 11
4
votes
3 answers

Finding adjacent nodes in a tree

I'm developing a structure that is like a binary tree but generalized across dimensions so you can set whether it is a binary tree, quadtree, octree, etc by setting the dimension parameter during initialization. Here is the definition of…
jett
  • 1,276
  • 2
  • 14
  • 34
4
votes
2 answers

PHP Traversing Function to turn single array into nested array with children - based on parent id

I have an array similar to this: Array ( Array ( [ID] => 1 [parentcat_ID] => 0 ), Array ( [ID] => 2 [parentcat_ID] => 0 ), Array ( [ID] => 6 [parentcat_ID] => 1 ), …
Joel
  • 2,185
  • 4
  • 29
  • 56
4
votes
2 answers

Is there tree traversal algorithm with fixed memory usage?

I have first node of the tree. Something like that: class TreeNode { int uniqueValue; List children; } I want to find the most memory efficient way to print all nodes of the tree. Tree may be big or VERY BIG. It can be deep or wide.…
Pavel Vyazankin
  • 1,470
  • 6
  • 18
  • 27
4
votes
2 answers

how can a breadth-first-search-tree include a cross-edge?

Well, I know that a breadth-first-search-tree of an undirected graph can't have a back edge. But I'm wondering how can it even have a cross-edge? I'm not able to image a spanning tree of a graph G constructed out of OFS, that contains a cross-edge.
4
votes
6 answers

Traversing a binary tree in C

I'm trying to traverse a binary tree in C. My tree contains an AST node (abstract syntax tree node for compiler). ASTnode reserves nodetype which specifies given node's type (i.e INT OP or CHAR and TYPE we don't need to concern other types), the…
iva123
  • 3,395
  • 10
  • 47
  • 68
4
votes
5 answers

How to find all possible subtrees of a binary tree in Haskell?

I need to find all possible subtrees in a binary tree: allSubtrees :: BinaryT a -> [BinaryT a] allSubtrees = undefined and the tree is: data BinaryT a = Empty | Node (BinaryT a) a (BinaryT a) deriving (Eq, Show) I'm new to Haskell and I…
Zip
  • 809
  • 2
  • 14
  • 30
4
votes
3 answers

Algorithm traversal throughout a tree structure

Class Diagnostic { //Get the size in bytes of an object static long sizeOf(Object object); //Get the references for an object (leafs) static List getRefs(Object object); //Implement this with those above public Long objectSize(Object…
fneron
  • 1,057
  • 3
  • 15
  • 39