tree

Unravel a tree structure stored as nested list

Unravel a tree structure stored as nested list Question: I’m working on a piece of code which simulates possible paths through a series of nodes. The nodes are assigned numbers and the connected nodes are listed in a lookup table. Since the path sometimes splits in two (or many) possibilities (and sometimes only one, i.e., …

Total answers: 1

Nested dictionary or list using given unindent data using Python

Nested dictionary or list using given unindent data using Python Question: Hi I have given below data but its unindent only using total keyword I can find the right nodes and can build tree structure. Input: Current Assets Cash Checking 583961 Savings 224600 Petty Cash 89840 Total Cash 898402 Accounts Receivable 3593607 Work in Process …

Total answers: 1

Python Recursive Tree

Python Recursive Tree Question: I’m new to programming and I want to define a function that allows me to find an element in a non-binary tree, and keep track of all the parentals of that element on a list. The tree is coded as a tuple, where index 0 is the parent, and index 1 …

Total answers: 2

How to recursively add nodes to n-ary tree in Python

How to recursively add nodes to n-ary tree in Python Question: So I have an n-ary tree with a root node that I have manually added 5 child nodes too. Each of these children nodes represents a state of its parent that has had some calculations done to its data. For example: child1.value = root.value …

Total answers: 1

Implement an AVL-balanced search tree dictionary that only stores values in leaves

Implement an AVL-balanced search tree dictionary that only stores values in leaves Question: There was a task in school: to implement a dictionary based on an AVL-balanced search tree, in which data is stored in leaves. I wrote a dictionary class: an AVL-balanced search tree in which values are stored in nodes. How can I …

Total answers: 1

find a path to a given node in binary tree – Python

find a path to a given node in binary tree – Python Question: I’m stuck finding the path of the given node so I can find the right side but not the left side. class Node: def __init__(self, key): self.left = None self.right = None self.val = key def path(self, k): if not self.val: return …

Total answers: 1

Python code to do breadth-first discovery of a non-binary tree

Python code to do breadth-first discovery of a non-binary tree Question: My problem: I have a known root node that I’m starting with and a specific other target node that I’m trying to find the shortest path to. I’m trying to write Python code to implement the Iterative Deepening Breadth-First Search algo, up to some …

Total answers: 2

Create a Category Tree using python

Create a Category Tree using python Question: A category tree is a representation of a set of categories and their parent-child relationships. Each category has a unique name (no two categories have the same name). A category can have a parent category. Categories without a parent category are called root categories. Need to create a …

Total answers: 1

recursive tree search create array of all paths

recursive tree search create array of all paths Question: I have a dict {child, parent} mydict = {‘1’: ‘0’, ‘2’: ‘0’, ‘3’: ‘1’, ‘4’: ‘3’, ‘5’: ‘3’, ‘6’: ‘2’, ‘7’: ‘6’, ‘8’: ‘7’ } I don’t know how many levels of grandchildren there are. I need to end up with a structure that has all …

Total answers: 1