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

Traversing my tree contents using pattern matching on objects

I am trying to represent a tree data-structure in F# using the following type: type Node = val mutable left: Node option val mutable right: Node option val mutable value: int new (l, r, v) = {left = l; right = r; value = v} I can create a…
badmaash
  • 4,775
  • 7
  • 46
  • 61
0
votes
1 answer

How could I write a traversal query in neo4j (gremlin/cypher either one)?

Perferbly gremlin, but either one will do; I am storing nodes in a database that form tree like structures. example: /dir/inside_dir/alaskan-natives/story1 Nodes are attached with a relationship called HAS_CHILD_NODE (if it would be more efficient…
kr1zmo
  • 837
  • 3
  • 13
  • 30
0
votes
2 answers

C++ freezes on testing whether a member variable equals NULL

I created a program which, so far, creates a binary tree of nodes for a Huffman coding program. For some reason, when the debugger gets to the point where it tests if the two children equal Null or not (so there an actual character on the tree and…
sinθ
  • 11,093
  • 25
  • 85
  • 121
0
votes
6 answers

a method to count the number of nodes with 2 children in Binary search tree

Thats the best I could come up but it still doesn't work cause it returns 1 even if there was more than one node that have two children. int countTwoChildren(Node node) { if(node==null) { return 0; } if(node.left!=null &&…
hws
  • 41
  • 1
  • 2
  • 5
0
votes
2 answers

Iterative Threaded Binary Tree Traversing with only constant extra space

How to traverse a threaded binary tree non recursively in O(n) without using a stack (just allowed to use constant extra space for temp variables, so we can't add visit flag to each node in the tree). I spent a good time thinking about it but it…
K''
  • 5,020
  • 7
  • 33
  • 43
0
votes
1 answer

Is it possible to get the node above the current node?

I'm asked a question, when I traverse my binary tree, is it possible to get the node above the current node ? As a double linked list.
Marc Lamberti
  • 763
  • 2
  • 9
  • 24
-1
votes
3 answers

Jquery tree traversing not selecting

I have some jquery variables that attempt to get values of nearby elements however they don't work. I thought closest() was the right selector. JQUERY: $(".answerContainer").on("click", ".editAnswer", function(e){ e.preventDefault(); var answer_id…
kirby
  • 3,981
  • 14
  • 41
  • 54
-1
votes
1 answer

Getting 'maximum recursion depth exceeded' error when implementing recursive binary tree traversal in Python

I'm trying to implement a recursive algorithm in Python to traverse a binary tree and print out all the nodes in order. However, when I run my code, I'm getting a "maximum recursion depth exceeded" error. class TreeNode: def __init__(self,…
pvpb0t
  • 33
  • 6
-1
votes
3 answers

Javascript Tree (Array of object) Traversal with Ancestors

I am trying to make a tree traversal function in javascript. I also want ancestors of any nodes. That's why I have written code like this: const visit = (tree) => { if (!typeof ancestors){ const ancestors = [] } console.log(ancestors) if…
-1
votes
2 answers

figure out the structure of a binary search tree given preorder traversal

Hi I am struggling to figure this out. The pre-order traversal of a binary search tree is: 15, 9, 6, 1, 7, 13, 23, 19, 39, 32. what would be the postorder traversal of it? to figure out the post order traversal, we need to obtain the structure of…
-1
votes
1 answer

Don't understand this concept about binary tree traversal in C++

So I was doing this leetcode question and didn't understand what was happening. It is about preorder traversal through a binary tree. Problem in question At first I thought it would be simple enough to implement the traversal code I learned in…
-1
votes
1 answer

Construct a binary tree and traverse it in pre-order

Let's say i need to build this tree from the digits 61207895 and then perform a pre-order traversal of the tree. 6 / \ / \ / \ 1 7 / \ / \ 0 2 5 8 \ …
-1
votes
2 answers

Google Apps Script - How to efficiently traverse a Drive tree to get to a particular folder

So I have a folder tree that looks a bit like - grandad - parent 1 - ana - jack - david - parent 2 - fred - lydia - david - parent 3 - alfred - jo - david ...so every single parent folder has a child called…
yago
  • 168
  • 1
  • 11
-1
votes
1 answer

OutOfMemoryError when trying to add elements from a B+Tree to an ArrayList

I'm attempting to traverse through a B+ Tree and add the elements from the leaves into an ArrayList with the following code: public void toArrayList(Node node){ Node currentNode = node; if(currentNode instanceof InnerNode){ …
K091916
  • 9
  • 2
-1
votes
2 answers

Javascript - Traverse A Tree To Generate The Sequence Of The Nodes

I have found few SO questions relevant to this but none of them were based on the exact problem I am trying to solve. Basically, I am working on a tree structure and every node is assigned an id. The objective is to generate a sequence string that…
planet_hunter
  • 3,866
  • 1
  • 26
  • 39