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

what is the exact difference between different types of treee traversing

how do I choose how should i traverse a tree in-order, pre-order, post-order? I understand what is the difference between those, but what is the practical difference? Time complexity? thank you..
tania
  • 1,086
  • 2
  • 12
  • 31
-1
votes
3 answers

How to create a function that returns smallest value of an unordered binary tree

This seems like it should be really easy but I've been having trouble with this for quite some time. As the title says, I'm just trying to find the node in a Binary tree (not a BST!) with the smallest value and return it. I can write a recursive…
Wakka Wakka Wakka
  • 271
  • 1
  • 9
  • 16
-1
votes
1 answer

Traversing a tree - How to print the edges first

If I have a tree as below: A Root Level / \ / \ G Z Level 1 / \ / \ / \ / \ C D T J Level 2 I have three questions: How can I traverse…
Anthony
  • 33,838
  • 42
  • 169
  • 278
-2
votes
1 answer

Amortized Time Calculation in AVL tree

My professor showed the following problem in class and mentioned that the answer is O(1) while mine was quit different, I hope to get some help knowing of what mistakes did I made. Question: Calculate the Amortized Time Complexity for F method in…
user14826913
-2
votes
1 answer

Binary search tree traversal

Hi guys I have a doubt in inserting a new node in BST. In the addNode module I am trying to insert an element in the BST, but each time while adding a new node it is adding to the same root node which I passed from main function initially without…
susil95
  • 300
  • 3
  • 5
  • 16
-2
votes
1 answer

Need help in Extracting information from an JSON which is storing an Abstract Syntax Tree

{ "id": "9", "children": [{ "id": "8", "children": [{ "id": "7", "children": [{ "id": "6", "children": [ { "id": "0", …
-2
votes
1 answer

How can i return tree traversal as an array from a C function

I can in-order traverse a tree with the below code. But if want to return the in-order traversal from this function how can i do that? void inorder(Node* root){ if(root==NULL){ return; } inorder(root->left); …
red5pider
  • 351
  • 1
  • 9
  • 24
-2
votes
2 answers

Exercise review Trees binary c++

Given a binary tree, whose root is located a treasure, and whose internal nodes can contain a dragon or does not contain anything, you are asked to design an algorithm that tells us the leaf of the tree whose path to the root has the lowest number…
Alvaro
  • 47
  • 6
-2
votes
1 answer

Where is my kd tree traversal code wrong?

I was optimizing my c++ raytracer. I'm tracing single rays through kdtrees. So far I was using Havran's recursive algorithm 'B', which seems antique and overblown for OOP. My new code is as short as possible (and hopefully more easily optimized by…
5-to-9
  • 649
  • 8
  • 16
-2
votes
1 answer

Cycle detected while printing root to leaves path

I used the solution to this problem to print all root to leaves path for a n-ary tree I have. Unfortunately, I suspect, there is a cycle in one of the branch of the tree due to which the program breaches the maximum recursion limit. A / …
Bhavish Agarwal
  • 663
  • 7
  • 13
-2
votes
1 answer

Binary Search Tree Recursion

Given the root node of a Binary Search Tree, I'm trying to create a recursive search where all nodes within a given maximum and minimum range are found but in the LEAST amount of visits. So essentially the set up to this question will be(I…
user2251001
  • 51
  • 1
  • 2
-2
votes
3 answers

Change properties of option in a select element with jQuery

Code: function disableOption(pos) { //document.getElementById("selectSuggestion").options[pos].disabled=true; <-- this is what I want to do var option = $(#selectRating).children()[pos]; <-- doesnt work …
Petrus K.
  • 840
  • 7
  • 27
  • 56
-2
votes
1 answer

Inorder Traversal of a tree

How can I Flatten a tree (inorder traversal) for following Tree structure: https://gist.github.com/damadamdam/7b6364220b11871f2930 My expected answer is also attached with the gist.
-3
votes
3 answers

How to iterate through a list of nodes which might have sub-lists of nodes (unknown depth levels)

I have a list of nodes, and each node might have a list of subNodes (the number of levels are unknown): class Node { int score; boolean selected; List subNodes; } Here's how an hypothetical structure might look like: NODE +…
j3d
  • 9,492
  • 22
  • 88
  • 172
-3
votes
1 answer

What are the inorder and postorder traversals of the following tree?

With respect to the following tree: What is the correct inorder traversal? U S T X C P Y R B A I G J F N H V T E D L U S T X C P Y R B A D E I G J F N H V T L What is the correct postorder traversal? U T S X P R Y C B D I J G N V T H F E L A U…
1 2 3
55
56