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

Understanding printed output for a BST traversal

I'm trying to understand how the below code works. The code executes as it should but I don't understand parts of it. It's a method for an in-order traversal of a binary search tree: def traverse(self): def io(node): print("restart")…
david
  • 117
  • 1
  • 5
3
votes
1 answer

Re-arrange a flat array with level info into n-ary tree with childrens

Given an array in the format of levels and their immediate children store in a consecutive array return a n-ary tree Given Input format : [{'name':'a', 'level': -1}, {'name':'b', 'level': 0}, {'name':'c', 'level': 1}, …
devvapp
  • 143
  • 1
  • 2
  • 9
3
votes
0 answers

Differences between 2 implementation of tree traversal

In "Data Structures and Algorithms in Python" of Michael T. Goodrich, page 334, I've found the implementation of preorder traversal a little bit confusing. def _subtree_preorder(self, p): """Generate a preorder iteration of positions in subtree…
A. Device
  • 31
  • 2
3
votes
1 answer

Convert Tree Structure from database to JSON Object in java?

I have a parent child relationship (Tree Structure) in database and I want to traverse it and create a json object out of it. My Database Parent child relationship structure (Demo Data). child_id parent_id Item_Name 1 1 …
John
  • 276
  • 1
  • 9
  • 29
3
votes
2 answers

JSON parsing [`jq`]: Get value of grandparent’s sibling

Example { "gp_sibling": "desired_value", "grand-parent": { "parent": [ { "key": "known_value", "sibling": "asdf" } ] } } Problem definition I have a large JSON. I know that key has a unique value. I need to…
tukusejssirs
  • 564
  • 1
  • 7
  • 29
3
votes
0 answers

Check permission before stat method to avoid errors

My first time ever trying to traverse directories, but stat is throwing errors for some of the directories due to what seems to be a lack of permission. Error: EPERM: operation not permitted, stat 'K:\System Volume Information' I'd like to simply…
oldboy
  • 5,729
  • 6
  • 38
  • 86
3
votes
1 answer

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 information about the lines associated with each node,…
3
votes
1 answer

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() { @Override public void visit(MethodCallExpr node, Object arg) { …
3
votes
1 answer

Count number of nodes per level in a binary tree

I've been searching for a bit now and haven't been able to find anything similar to my question. Maybe i'm just not searching correctly. Anyways this is a question from my exam review. Given a binary tree, I need to output a list such that each item…
3
votes
1 answer

Find Path to Specified Node in Binary Tree (Python)

I'm having trouble computing the path from the root to a specified node in a binary tree (this is specifically about a Python solution to this problem). Here's an example. Given the binary tree below, if I specify the node whose value is 4, I want…
hobscrk777
  • 2,347
  • 4
  • 23
  • 29
3
votes
1 answer

JSF refuses to process a deeply nested composite component. No, really: "JSF1098: [...] This is a waste of processor time [...]"

The premise is quite straightforward: I have a page layout that relies on nested composite components (CC) to do the rendering, i.e. one JSF page references a CC, which itself references another CC, which contains a call to a third CC. - Source…
Antares42
  • 1,406
  • 1
  • 15
  • 45
3
votes
1 answer

Converting a preorder traversal array to an level order traversal array (or vice versa) given that the binary tree was filled in Level Order

Say you have a binary tree that was filled in level order, i.e. every level is filled before any of that level's node's children. Such a tree can be uniquely defined by it's level order traversal. For instance {1,2,3,4,5,6} is 1 2 3 4 5 …
3
votes
3 answers

How to check if a given array represents postorder traversal of Binary Search Tree?

There is a given array and we need to know if it represents a post-order traversal of BST. (example: if the question was in-order instead of post-order , we only need to check if the array is sorted time o(n))
3
votes
1 answer

General Tree Post Order Traversal

var tree = { "name" : "root", "children" : [ { "name" : "first child", "children" : [ { "name" : "first child of first", "children" : [] }, { "name" : "second child of…
3
votes
4 answers

Finding border of a binary tree

We are given a binary search tree; we need to find out its border. So, if the binary tree is 10 / \ 50 150 / \ / \ 25 75 200 20 / \ / / \ 15 35 120 155…
Flash
  • 2,901
  • 5
  • 38
  • 55