All Questions
42 questions
7
votes
3
answers
761
views
Optimal Algorithm to Append and Access Tree Data
I have been studying intermediate or more advanced data structures in Python, one of which I've decided to try out is the Tree Data Structure. I've been studying the theories as well as the ...
2
votes
2
answers
216
views
Lowest Common Ancestor in Binary Tree (Iterative)
In the below code I've implemented a method to find the lowest common ancestor of a binary tree.
This is an iterative approach using this pseudocode.
Please suggest any improvements that can be made.
<...
1
vote
1
answer
67
views
Synchronize list of trees with DB using DRF serializer
Given the models below:
...
5
votes
2
answers
279
views
Binary Tree Preorder Traversal
What is the best way to move _add and _preorder methods in class Node to ...
2
votes
2
answers
395
views
Iterative “post order” tree traversal [closed]
I wanted to get feedback on the correctness and efficiency of this post order traversal routine that my wife and I find really easy to grasp.
...
2
votes
1
answer
724
views
Python Fenwick Tree
I am trying to solve this question: https://open.kattis.com/problems/fenwick
A Fenwick Tree (also known as a Binary Indexed Tree) is a data
structure on an array which enables fast (𝑂(log𝑛)) ...
4
votes
2
answers
463
views
Heap Sort and Binary Tree Sort Algorithms (Python)
Heap Sort
A Binary Heap is a Complete Binary Tree where the items are stored in a special order such that the value in a parent node is greater or smaller than the two values in the children nodes.
...
1
vote
1
answer
152
views
Flatten binary tree to linked list
I'm trying to flatten a binary tree into a linked list.
I have a working, correct solution:
...
4
votes
1
answer
237
views
Maximum profit earned on weighted un-directed tree
I came across this problem while giving a sample test.
The problem was that we have given a tree which is undirected. We can
start from any node of our choice. Initially we have power "P" and
...
4
votes
2
answers
908
views
Find the in-order successor of a given node in a binary search tree
I have an implementation of an algorithm to return the in-order successor of a given node in a binary search tree. We are allowed to assume that each node in the BST has a reference to its parent node....
-4
votes
1
answer
94
views
Finding the sublist with best utility function among all list's permutations [closed]
I try to find the the better solution in terms of time complexity.
Among the list of elements I need to find the sublist with maximum value of given utility function.
Each element has it's own type. ...
5
votes
2
answers
113
views
A recursive solution to symmetirc tree
I tried to solve a symmetric tree problem
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree ...
4
votes
1
answer
1k
views
Building balanced BST from sorted array: recursive and iterative approaches
I am implementing an algorithm to solve the following problem:
Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal ...
1
vote
1
answer
173
views
Binary Tree Longest Consecutive Sequence
I written code to solve this problem which I found on leetcode. My solution worked for the vast majority of the test cases run against it but failed on 2 for some reason. The first test case it failed ...
1
vote
1
answer
2k
views
Recursive Binary Tree Inorder Traversal in Python
This is a very simple problem to see if my understanding of basic Python is correct
Problem:
Given a binary tree, return the inorder traversal of its nodes' values.
Example:
Input: [1,null,2,3]
...