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

logic of restore a binary tree based on travseral results, java

Can you help to explain the logic of how to do draw the original binary tree based on traversal results? I know pre-order and in-order traversal, but I can't figure out where to start with this question. Many thanks in advance! A binary tree has…
user3735871
  • 527
  • 2
  • 14
  • 31
0
votes
1 answer

How to find whether two trees are structurally same using level order traversal?

I came up with an algorithm to check if two trees are structurally similar i.e. the data at the corresponding nodes in the two trees may be different but if a node in tree1 has one left child then it's corresponding node in tree2 must have one left…
Dubby
  • 1,154
  • 3
  • 16
  • 31
0
votes
1 answer

How to traverse a tree stored in SQL database with Python?

I have a root tree stored in a SQL using materialized path (storing path string for each row). What is the best way to visit each node node without starting from the root each time? Is materialized path right for my approach? Harry ├── Jane │ ├──…
KJW
  • 15,035
  • 47
  • 137
  • 243
0
votes
1 answer

How to traverse through the children div recursively

i am having the div structure like this, which will be like children-grandchildren-great grand-children and so on repeatedly as the div structure end is unknown. so my question is How to traverse recursively until the last div.
Strawberry
  • 667
  • 2
  • 10
  • 24
0
votes
2 answers

java and xml, use of Element

i'm a beginner in java and XML , but I have a task to perform and I don't know how to use a recursive function which uses Element. I made this program. public class JDOM2 { private static final String xmlroutes =…
Thonath
  • 13
  • 1
  • 4
0
votes
2 answers

traversal of a binary search tree

I'm trying to create a program to work with binary search trees and my instructor has this function set up with this declaration, which must stay the same. void BSTType::traverse(std::ostream& out, TravType trav) const{ this is currently how i…
0
votes
0 answers

Path Traversal in Java

I have a list of Activities and a list of Activities and the Start Activity, which I am supposedly fetching by parsing an XML. Now I need to find the Possible Paths from Start to End in Java. I googled some algo's that could do the same but,…
user2176576
  • 734
  • 3
  • 14
  • 39
0
votes
1 answer

C - How to return the key of a tree that is found using the size of the data in the tree?

I have a binary tree and each node has this footprint. The tree is balanced by the key. struct node { STRING key; VECTOR data; struct node left; struct node right; } I want to have a function that will return the key of a node that has…
0
votes
1 answer

Building a Tree with inorder and preorder traversal in Python3.x

I am trying to build a tree using the preorder and inorder traversals (list of ints). Here is what I have so far: def build(preorder, inorder, heap): # Builds tree with the inorder and preorder traversal if len(preorder) == 0: return…
somebody
  • 85
  • 3
  • 10
0
votes
2 answers

Setting attributes for the first column's contents with jquery

I have the following table which is loaded dynamically into a
. Now I am trying to traverse into the table as to disable all the input fields in the first column titled "index". How would I go about that? What I have come up with is the…
0
votes
1 answer

Writing to a file in Python 3.x

from arrayheap import ArrayHeap def generateTable(self, node, table): def codeTable(node, codeString): if node.isLeaf: table[node._char] = codeString return if node.getleft() is not…
somebody
  • 85
  • 3
  • 10
0
votes
1 answer

What am I doing wrong? - Output to file in python 3.x

Here is some of the code I have - My issue is in the generateTable() function: I have created a Huffman Code tree and I want to output each node's location so that it appears like so: 10 111100 32 110 33 1010110110 34 10101111 38…
somebody
  • 85
  • 3
  • 10
0
votes
1 answer

Traversing a Huffman Code Tree in Python 3.x

I am trying to generate inorder and preorder traversals of a Huffman Code Tree in python. I seem to have hit a wall though. I need to generate the traversals and write them to corresponding files, and then create a binary path to the locations of…
somebody
  • 85
  • 3
  • 10
0
votes
1 answer

Level traversal in binary tree

Here is the part of code of the binary tree class that I'm writing. class Node { private T value; private Node left; private Node right; public T getValue() { return value; } public void setValue(T value)…
user3490321
0
votes
4 answers

Big O for this recursive algorithm

I did the following algorithm involving a Binary Heap structure: Algorithm: heapMinimum(node) Input : Position n Output : Sequence minList; containing the postions that hold the minimum value 1. minList <-- sequence 2. if parent(node) == NULL…
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360