binary-tree

How to convert a list of edges to a tree in python?

How to convert a list of edges to a tree in python? Question: I am having a list of edges that has the following format: edges=[[1,4],[1,3],[1,2],[3,5],[3,6],[3,7]] Here in each edge the first element is the parent node and the second is a child node i.e, in [1,4]—->(1 is the parent node and 4 is child …

Total answers: 3

How do i create a function to convert a binary tree to a tuple?

How do i create a function to convert a binary tree to a tuple? Question: i came across this question where i was tasked to convert a tuple into binary tree and then convert binary tree back to tuple and return both tree and tuple. i was able to convert the tuple into the tree …

Total answers: 6

Binary tree get all nodes for every level

Binary tree get all nodes for every level Question: I am trying to solve the following, say I have this binary tree… 3 / 9 20 / 15 7 Then I need to get all nodes at every level, so my result will be… [[3],[9,20],[15,7]] I believe I am getting close to a solution, but …

Total answers: 3

Inorder Binary Tree Traversal (using Python)

Inorder Binary Tree Traversal (using Python) Question: I am trying to perform an inorder traversal of a tree. The code itself feels right, except it is not working properly. I have a feeling it has to either do with the if condition, how append works in python, or something perhaps with return. This works correctly …

Total answers: 5

Printing BFS (Binary Tree) in Level Order with Specific Formatting

Printing BFS (Binary Tree) in Level Order with Specific Formatting Question: To begin with, this question is not a dup of this one, but builds on it. Taking the tree in that question as an example, 1 / 2 3 / / 4 5 6 How would you modify your program to print it so, …

Total answers: 16