# Questions tagged [tree-traversal]

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

**-3**

votes

**0**answers

37 views

### data structures - about Stack and Binary Tree

i have a work to make given stacks by user and i must put these values to binary tree in LDR inorder.but i take force close,How i can fix ?this func is first to run from main :void writetotree() /...

**0**

votes

**1**answer

34 views

### Traversing JSON to buid a parent child output with Javascript

I have to traverse the below input JSON to build a parent child relation as in the sample JSON.Logic, the element which has immediate_parent_id of -1 that becomes a root node. Than root node ...

**-1**

votes

**1**answer

30 views

### Recursive function returning a reference

I would like to ask about a recursive function I am writing but I think I am not getting right the concepts of pointer, reference, and object itself. This function reads a tree sequence from ...

**1**

vote

**1**answer

39 views

### Binary Tree Level Order Traversal in leetcode

got error when tried to run the code "terminate called after throwing an instance of 'std::bad_alloc'what(): std::bad_alloc"Code:#include<bits/stdc++.h>using namespace std;class ...

**0**

votes

**1**answer

27 views

### php 7 - sort multilevel associative array by keys to have it sorted on each level lexicographically

In PHP7, how to sort recursively all levels of the array to have any adjacent keys to be in lexicographical order?This sample array:$a=['c'=>['d'=>1, 'a'=>2], 'b'=>['b'=>3, 'a'=&...

**1**

vote

**3**answers

29 views

### Level order traversal in a binary search tree in java

I have made 4 different traversals for my binary search tree. I am stuck at the last one which is the level order traversal and I can't get seem to find out how to do it correctly.The main problem ...

**0**

votes

**1**answer

20 views

### Why use recursion on a pre order traversal (binary search tree)?

I have these 3 different traversal methods below, which traverses my binary search tree. I know that both post order and in-order traversal is from the bottom to the root, but preorder is from root to ...

**2**

votes

**3**answers

52 views

### Iterative Post order traversal without visited array

I have recently started learning computer science and Java coding and came across Traversal techniques. I am writing a Java code using Stack. I have been with this issue and couldn't find any solution....

**1**

vote

**1**answer

24 views

### How to get parent multiple levels up the DOM tree without jQuery or modifying Element.prototype?

I am wondering if there is a way to select a specific element way up the DOM only using vanilla JS while not having to use parentNode multiple times. I understand you can do this with jQuery and ...

**0**

votes

**1**answer

50 views

### Given a query containing two integers as nodes, find all the children of those two nodes in tree?

This is my interview question which has the following problem statement You are given M queries (1 <=M <=100000) where every query has 2 integers which behave as nodes of some tree. How ...

**3**

votes

**2**answers

46 views

### How to recognize some binary search tree traversal belongs to post-order or in-order?

If the pre-order of a binary search tree is [P, A, R, S], How to recognize [R, S, A, P] belongs to in-order or post-order?If is post-order how to find out is (Left, Right, Root) or (Right, Left, Root)...

**0**

votes

**1**answer

30 views

### Issue constructing a tree using a tree

So I have this method which basically traverses through a tree and constructs another tree, basically a map method but for an array, but im facing issue that instead of constructing a tree properly ...

**0**

votes

**1**answer

25 views

### Complexity of tree traversal for printing all paths recursively

I have written a program to find all valid parameter combination if an input N is given. There should be N number of parameters.For example, if N=2, the answer will be ()(), (()) and if N=3 the ...

**0**

votes

**0**answers

30 views

### Could someone please explain how recursion functionality is working on working tree data structure

While I am working in the below code, I didn't understand how recursion is working, because insertLevelOrder() function after completing root.left functionality cursor is coming outside, but how root....

**-3**

votes

**1**answer

20 views

### Read Values of specific array at specific XML node with PHP

Hello I am trying to list tour name in the 6 node of filter object. Formated xml image is also attached. This is my loop.foreach($results->filters->filter[6] as $key=>$tours){...

**1**

vote

**1**answer

43 views

### Filter keys of the objects in a deeply nested JSON with jq

Given the following input[{"k1":[{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6}],"k2":[{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6}]}]how should I proceed to obtain the following output?[{...

**0**

votes

**0**answers

13 views

### Which Tree Traversal technique should be used to evaluate (2-3) + (2*(4+3))?

I can use PostOrderTrversal to evaluate(2-3) + ((4+3)*2)to23-43+2*+But when I try to do the same for (2-3)+(2*(4+3))I get23-243+*+which I guess will cause issue when solving.

**3**

votes

**1**answer

53 views

### Is there any kind of “line visitor” in Eclipse JDT Java Parser? If there is not, does someone knows a good workaround?

I wanna visit the nodes in an AST from a Java file and extract some information related to these nodes. But, I wanna pass by the AST guided by the lines in the source code file. I know there is ...

**3**

votes

**1**answer

137 views

### In Eclipse JDT Java parser, is it possible to traverse the AST node by node without the using of visitors?

The standard way to access information on Nodes through the Eclipse JDT API is with Visitor's pattern. For example:unit.accept(new MyVisitorAdapter<Object>() {@Override public void visit(...

**2**

votes

**1**answer

216 views

### BFS in JavaScript using Recursion

It is easy to do DFS using recursion:function dfs(tree, fn, level) {fn(tree, level)tree.children.forEach(function(child){dfs(child, fn, level + 1)})}However every example I have ...

**0**

votes

**1**answer

62 views

### Binary tree level order traversal using double pointer

Creating binary tree doesn't matter. I can see printed result of LevelOrder but it keeps put up a error. How can I fix changes while minimizing them? I need to be hurry :(I think print DELETE() is ...

**0**

votes

**0**answers

20 views

### BTree - Traverse only PART of tree (Python 3)

Summary: I know how to build a Binary Tree in Python. I know how to traverse it. I even know how to search for specific values in that BTree; however, I can't figure out how to traverse only part of a ...

**3**

votes

**2**answers

104 views

### Vertical Order Traversal in using Level Order Concept of Binary Tree

I want to traverse a Binary Tree vertically. And I found a working code in Geeks for Geeks in C++. I want to convert it into C# but I am unable to do so. Please guide me. Below is my attempt:// we ...

**0**

votes

**0**answers

34 views

### BST pre order traversal to in order traversal

I have been trying to implement an in order traversal of a tree, however, I want to do it using a queue (my code tries to find the kth largest element in a tree, im using a queue and stack to do this)...

**0**

votes

**2**answers

41 views

### Is it possible to print each level of a binary tree on a separate line using depth-first traversal?

I am familiar with the use of a queue to print each level in a separate line in O(n) time. I want to know if there is any way to do this using pre-order, in-order or post-order traversal. I have ...

**1**

vote

**0**answers

33 views

### construction of bst from preorder traversal

While constructing Binary search tree from given Preorder traversal, can't we use normal method for construction of BST from set of array values instead of following the method given here. If not ,...

**1**

vote

**2**answers

66 views

### ZigZag binary tree traversal in C++

I am trying to attempt zig zag traversal of binary tree. But I am stuck at one type of test cases, i.e., when the tree is not balanced. If I give my input as 33 9 20 null null 15 7for a binary ...

**0**

votes

**1**answer

74 views

### View of a binary tree from 45 degree

So I am not asking diagonal view of a tree, which fortunately I already know. I am asking if I view a tree from 45-degree angle only a few nodes should be visible. So there is a plane which at an ...

**1**

vote

**2**answers

62 views

### I need an algorithm to walk a tree with optional and alternative nodes to calculate all possible paths

Given the following tree which is a sort of Backus-Nauf form like notation where| indicates or (so B is F or G) and [] indicate optional (so H is optional)Def: A B CA: D EB: F | GC: [H] ID: a b...

**0**

votes

**1**answer

22 views

### Found a bug, fixed it , I dont understand why it was bugging?

I've come across a bug that has now been fixed but I still dont understand the underlying cause for it.What I would like to do:Use post-order tree traversal to get postfix expression from a binary ...