6,838 questions
Advice
1 vote
9 replies
114 views
Sum of a binary tree
I have a binary tree which leafs have a size of 1, and the parent double in size at each level. I project those nodes on a linear axe (memory space). I need to get the equation that gives the adress ...
1 vote
2 answers
153 views
Given the string input, how can we traverse the binary tree recursively
Let's say our binary tree (bt) looks like this: Node* root = new Node(); root->left = new Node("B"); root->right = new Node(); root->right->right = new Node("A");...
-1 votes
1 answer
112 views
How to check binary tree symmetry iteratively to avoid stack overflow with deep trees in Python [closed]
I have a working recursive solution to check if a binary tree is symmetric. The code works correctly for my test cases, but I'm concerned about potential stack overflow with deep trees since Python ...
1 vote
1 answer
158 views
LeetCode 199. Binary Tree Right Side View constant memory complexity
I'm trying to solve LeetCode 199. Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. I've ...
10 votes
3 answers
616 views
Better way to search for a node in binary tree
This is the code I have written for searching a node in a tree as a part of my assignment: typedef struct NODE { int key; struct NODE *left, *right; } Node; Node *search(Node *head, int key)...
0 votes
0 answers
44 views
How to determine left and right indices quickly in depth-first ordered implicit binary tree?
Suppose I have a complete, perfect binary tree stored in an array. If I store node data in breadth-first traversal order (Eytzinger order), then if an internal node's index is i, its left and right ...
-1 votes
1 answer
91 views
Why does modifying the returned pair from a recursive call break my solution in Binary Tree Consecutive Sequence II?
I'm trying to solve the Binary Tree Longest Consecutive Sequence II problem (Leetcode 549). The goal is to find the length of the longest consecutive path (increasing or decreasing) in a binary tree. ...
2 votes
1 answer
300 views
Is it possible to rebuild binary tree from its postorder and preorder traversal?
I understand we can rebuild a binary tree from its inorder AND ( postorder OR preorder ) traversal. I however wonder whether rebuilding it from its postorder AND preorder traversal doable too?
-1 votes
1 answer
68 views
Not able to submit a binary tree code on gfg (vertical order traversal)
I was doing the GeeksforGeeks practice problem Vertical Tree Traversal: Given a root of a Binary Tree, find the vertical traversal of it starting from the leftmost level to the rightmost level. If ...
2 votes
0 answers
68 views
How to Implement rotateLeft rotateRight in tree based on array?
I'm trying to implement a binary tree using an array. It means that the following tree 1 / \ 2 3 / \ / \ 4 5 6 7 would be as the array below: [1, 2, 3, 4, 5, 6, 7] So it means that the ...
-2 votes
1 answer
60 views
Using list to find path sum of binary tree
def path_sum(root,temp): print("root is",root) if root == None: return False temp.append(root.val) if root.left == None and root.right == None: ...
1 vote
0 answers
93 views
Implementing Correct Node Partnership in a Doubly-Ended Array-Based Priority Queue (DEAP)
I'm working on implementing a Double-Ended Priority Queue (DEAP) data structure in C++. I'm having trouble with establishing the correct implementation of node partnerships between the min and max ...
6 votes
1 answer
89 views
Is there a simple recursive analogue of this breadth-first binary tree deserialization function in Haskell?
I am interested in methods for serializing and deserializing a binary tree in breadth-first order. The first part, serialization, is equivalent to performing a levelorder traversal where we preserve ...
1 vote
1 answer
85 views
Print Binary Tree
I am trying to visually print out a simple binary tree in Java. Here is the full code: class WordPoint { private final String word; private final float pointValue; public ...
-4 votes
2 answers
234 views
Level-Order Traversal of a Binary Tree Without Recursion? [closed]
I’m trying to implement a level-order traversal of a binary tree in C++ without using recursion. The goal is to traverse the tree level by level, starting from the root, and print the nodes in the ...