Skip to main content

All Questions

Tagged with
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 ...
Raphael Irvin's user avatar
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. <...
Saurabh's user avatar
  • 435
1 vote
1 answer
67 views

Synchronize list of trees with DB using DRF serializer

Given the models below: ...
Davit Tovmasyan's user avatar
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 ...
Saurabh's user avatar
  • 435
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. ...
Curious Programmer's user avatar
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𝑛)) ...
nz_21's user avatar
  • 1,051
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. ...
Emma's user avatar
  • 3,592
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: ...
nz_21's user avatar
  • 1,051
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 ...
learner-coder's user avatar
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....
screeb's user avatar
  • 232
-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. ...
Daniel Chepenko's user avatar
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 ...
Alice's user avatar
  • 595
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 ...
desa's user avatar
  • 143
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 ...
loremIpsum1771's user avatar
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] ...
user avatar

15 30 50 per page