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

How to remove duplicates in a binary search tree?

I'm trying to write a function that removes redundant items in a binary search tree. I am completely stuck. Can anyone help me? Any help would be appreciated. (C program)
ruka1
  • 1
  • 1
-1
votes
2 answers

Generate all the leaf to leaf path in an n-array tree

Given an N-ary tree, I have to generate all the leaf to leaf paths in an n-array tree. The path should also denote the direction. As an example: Tree: 1 / \ 2 6 / \ 3 4 / …
-1
votes
2 answers
-1
votes
1 answer

Level order travel of binary tree to determine symmetry

I'm trying to figure out if a tree is symmetrical iteratively. My approach consists of a level order traversal where I use two queues, the second one contains all the elements at each level and sends them to the isSymmetric function which uses that…
CISSflow
  • 89
  • 5
-1
votes
1 answer

BFS - TreeTraversal

I have the following array of employees which I'm trying to traverse using BFS approach. array = [ ["alice", "bob", "joseph"], ["bob", "tom", "richard"], ["richard", "michelle", "amy"], ["joseph", "elaine", "albert"], ["albert", "colin",…
Ali Ammaar
  • 123
  • 1
  • 1
  • 13
-1
votes
1 answer

Copy array values from parent to children

I have a tree structure array: array( array( 'id' => 0, 'tags' => array('q', 'w', 'e', 'r'), 'children' => array( array( 'id' => 1, 'tags' => array(), 'children'…
Mr.Falstaff
  • 15
  • 1
  • 6
-1
votes
1 answer

I want to store the Tree postorder traversal rather than print it? I am using the recursive approach. How do it store the correct order in the array?

I have tried to use a Global Array to save the values. But how do I write the base case for the recursion? If I return an array each time, how do I maintain the correct order of the tree traversal?
-1
votes
1 answer

Tree Traversal and check for a specific value in Java

I have a BinaryTree class which contains Root node of custom type TreeNode. TreeNode class has, T value; BTree left, right; BTree is an interface which is implemented in BinaryTree. in that binary tree class there is a method to check whether…
Scoopa
  • 45
  • 12
-1
votes
1 answer

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 standard input and it should return the entire tree.…
Pere
  • 379
  • 2
  • 10
-1
votes
1 answer

python3 - traverse tree and get all sets of leaf node siblings

I have a json file and its structure is like a nested tree: { "sub": [ { "code": "01", "name": "a" }, { "code": "02", "name": "b", "sub": [ { "code": "0201", …
ken wang
  • 165
  • 1
  • 12
-1
votes
1 answer

Pre Order, In order, and Post Order Tree Traversals

I am confused about in order, pre-order and post-order traversals, specifically this one, Pre-Order: ABAB, Post Order: BABA, In Order: AABB. I understand that the root is the first and last element of Pre and Post, but I fail to understand how to…
Jeremy
  • 103
  • 1
  • 1
  • 7
-1
votes
1 answer

Level Order Traversal Binary Tree Issue

Problem statement: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its…
segue_segway
  • 1,490
  • 1
  • 22
  • 40
-1
votes
1 answer

Implementing a nonrecursive preorder traversal method

I need to implement a preorder traversal method. Traversing a binary tree of nodes. Im trying to figure out a solution for the problem below. I know how to implement such a method, but the problem is that I can't deviate from the rules my teacher…
-1
votes
1 answer

Output Is very slightly off in ordered traversal of Binary search tree

#ifndef MOVIETREE_H_INCLUDED #define MOVIETREE_H_INCLUDED #include #include #include #include using namespace std; class BinarySearchTree { private: struct tree_node { …
-1
votes
1 answer

Modified Preorder Tree Traversal - Display Only 2 of each child

i'm trying to figure out how to use the MPTTD using sitepoint's tutorial. $result = mysql_query('SELECT title, lft, rgt FROM tree '. 'WHERE lft BETWEEN '.$row['lft'].' AND '. $row['rgt'].' ORDER BY lft ASC;'); the root has lft = 1, rgt = 42 so…