A tree is a graph in which there is exactly one path between any two nodes. It is often used as a hierarchical data structure.

learn more… | top users | synonyms

1
vote
0answers
13 views

Iterator through binary trees (with parent-pointer) without memory-overhead

I have been working on a custom Tree class that enforces certain rules upon insertion and deletion. The implemented tree is a Red-Black-Tree but since the ...
3
votes
0answers
28 views

Request for memory optimizations for solution to Google FooBar challenge, “ion_flux_relabeling,”

I just finished one of the Google FooBar Challenges.My Python is super rusty. I did the challenge in Haskell first and then attempted to covert the code. I am guessing that led to some bad Python ...
5
votes
1answer
74 views

Remove all nodes that satisfy a condition from a binary tree

Assume a binary tree with a data structure like this: ...
3
votes
1answer
44 views

Given a binary search tree determine if it's complete and if it's full

Here is the code of my binary search tree and a few unit tests. BinarySearchTree ...
0
votes
0answers
20 views

Prosemirror AST -> Pandoc AST converter

This converts from Prosemirror AST to Pandoc AST, and I am having some issues with the complexity of the code, and want to simplify it and make sure I am not doing anything silly. Essentially, I am ...
1
vote
1answer
53 views

C++ Quadtree SDL2

I've written a simple Quad-tree in C++ for an SDL2 application I'm working on. It's quite simplistic, and seems to be doing its job. Its only designed to work with a collection of unmovable physical ...
3
votes
0answers
51 views

Vertical sum in a given binary tree

I'm working on this problem, Problem statement, Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines. Examples: ...
0
votes
0answers
18 views

Move nodes if no veto from councilors

Working on a DTP based on Maven/Spring having a JTree(containing nodes as layers) try to implement a Authorithy for decide if layers can be droped to a target-layer....
5
votes
1answer
73 views

Find paths whose sum equals a target value in a binary tree

You are given a binary tree in which each node contains an integer value (which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The path ...
5
votes
3answers
131 views

Tree abstraction

This code provides a Tree abstraction. I would like to finalize the code structure only in tree directory, before starting ...
5
votes
1answer
58 views

Tic Tac Toe game tree generator minimax

I have coded a working Tic Tac Toe game tree generator. It doesn't only generate the game tree, it also applies minimax values to each node. The code works fine on a board that already has 2 or more ...
5
votes
3answers
139 views

Inverting a binary tree

I have written this code to invert a binary tree. Thus if the original tree is: Then the tree returned should be: ...
7
votes
3answers
87 views

Binary tree in Python exercise

I'm practicing Python. Being completely new to the language I'd like to hear someone else thoughts on the way I use the language. I'm coming from (mainly) Java and C so I'd expect new ways of doing ...
3
votes
1answer
151 views

Google Foobar Challenge: Ion Flux Relabeling

I am currently working on a Foobar challenge, the Ion Flux Relabelling. I came up with a java solution but Google returns an OutOfMemoryError. The prompt is, ...
1
vote
1answer
52 views

Finding numbers divisible by primes in a given range

The problem statement (Codeforces# 385C) is this: We are given a sequence of \$n\$ numbers, i.e. \$x_i\$ and \$m\$ queries to find how many of these are divisble by primes between two given numbers ...
1
vote
1answer
61 views

BST insertion and in order traversal

...
3
votes
1answer
75 views

Serialize and deserialize binary tree

Here is my code of serialize and de-serialize a binary tree, looking for advice. One issue in my mind which I cannot resolve is, I am using a global variable index, wondering if more elegant solutions ...
2
votes
2answers
56 views

Finding the longest path in an equally-weighted tree

Its purpose is to find the longest path in an equally-weighted tree denoted as such: 3 1 2 2 3 The first number denotes both the number of vertices and the ...
0
votes
0answers
89 views

Binary search tree implementation in Python

I am reading about algorithms and got to the binary search trees. I wanted to ask if the following implementation of a Binary Tree is correct. ...
1
vote
0answers
36 views

Creating a non-binary tree by weights of the node and then traversing it

I wrote this code which adds children to nodes according to the weight of the heading of a non-binary tree. I am a novice programmer, so I would love to know how this code can be improved. ...
3
votes
1answer
80 views

Return path to a value in a nested object

Description: Its not a programming challenge but I though to write a small utility which will return the path to a primitive value in a possibly nested object. The idea is not original. Code: ...
1
vote
2answers
117 views

Decision tree node split by Gini coefficient (used in RandomFerns/RandomForest algorithm)

I am implementing the Random Ferns Algorithm for Classification. For simplicity, let's imagine a single decision tree with only a single node. As input we have a feature and the label of each dataset. ...
4
votes
0answers
94 views

Python AVL Tree

While learning python, I decided to implement some data structures, this time AVL tree. I think the logic is correct, is there a way to make it more clearer and any ideas to add more tests? ...
2
votes
1answer
44 views

Beginning C BST implementation

I'd really appreciate if I could get some feedback on the following code with regard to security, efficiency and possible uncaught errors. Personally I feel the ...
4
votes
1answer
128 views

Binary search tree implementation in C#

I have implemented a BST for an assignment in C#. I am still in the process of implementing IEnumerable and ToList functions but ...
4
votes
0answers
131 views

Assembling and traversing a tree, given a list of items and parent pointers

I've written a function which takes input such as this: ...
2
votes
2answers
57 views

Binary Tree Inversion

I solved this problem. Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 To this ...
3
votes
1answer
64 views

Insert Tree in F#

Can this be improved, or made more concise? ...
3
votes
1answer
83 views

Serialize and deserialize a tree

Suppose each node of a tree has maximum n children. I want to serialize and de-serialize for a tree. My current solution is doing pre-order traverse, and using <...
2
votes
1answer
46 views

BTreeMap as a multimap in Rust

I'm learning Rust so as an exercise I'm trying to write a datatype wrapping the builtin BTreeMap to allow it to store duplicates. Like the STL multimap type. The ...
5
votes
0answers
112 views

Red-black tree appears to be slower than std::multimap

I've written a red-black tree in C as an exercise. The tree works and it is not bad, but it is about 10% slower than std::multimap from libstdc++ which I'm ...
1
vote
0answers
47 views

Huffman code generator in Typescript

Write a program that takes any input text and produces both a frequency table and the corresponding Huffman code. Take approximately 360 words from any English document as your input text. ...
1
vote
0answers
46 views

Multi-way Tree organized alphabetically and search in preorder trasversal order

In attempt to create a k-ary or multiway binary tree sorted alphabetically at every deep, I created this class in Ruby to handle the order and search in a recursive way by the ...
3
votes
1answer
78 views

C++ Tree Object Class

I'm writing a class that acts as the base for almost all objects in my project. I know this class technically doesn't represent a tree structure, because it can have more than 2 children. What should ...
2
votes
2answers
47 views

Inserting into a binary search tree in C

I am in the process of refactoring this simple binary search tree code responsible for adding new values: ...
-1
votes
1answer
96 views

Balanced Binary Tree

There are some things that smell about this code, for instance multiple checking, length both returning value and changing some other variable. But I can't for the ...
3
votes
1answer
116 views

Calculating binary tree height as asked in the interview

Input: The first line contains the number of vertices \$n\$. The second line contains \$n\$ integer numbers from the range \$\left[−1, n − 1\right]\$ representing the \$0\$-based index of the ...
12
votes
3answers
617 views

Google Foobar Challenge: Lucky Triples

Note: Since my time has passed for this challenge, I do not remember exactly the stipulations but will attempt to recapitulate them to the best of my knowledge. Essentially, the challenge was this: ...
3
votes
1answer
71 views

Find the shortest whole repetitive substring (part 2)

This is a continued improvement from discussion here (Find the shortest whole repetitive substring), since code has changed a lot dues to improvement, I post it here. Major smart ideas are from ...
1
vote
1answer
23 views

Displaying a List in a Managed Metadata TreeView

I have some Managed Metadata in SharePoint which is in the following format: Managed Metadata Service People Job Title And I have a list of people, ...
3
votes
1answer
47 views

Binary trees exercise

I'm not sure about this code but it feels ugly to me. It is a solution to this. ...
4
votes
2answers
120 views

QuadTree C++ Implementation

I recently created a QuadTree implementation in C++. It varies slightly from most implementations. Instead of storing elements it only organizes elements. This allows programmers to insert elements ...
3
votes
1answer
56 views

Printing different aspects of a binary tree

I had an assignment, for which I got full marks, but am really upset about the code I have written. I feel it is too manual and repetitive. Please help me make it more optimized. I am making many ...
6
votes
4answers
167 views

Count number of nodes in a binary tree the OO way

I am trying to write a simplify the algorithm of finding the number of nodes in a binary tree by using good object oriented design. I have been into good OOP style recently and found it really ...
0
votes
1answer
57 views

Root to leaf path with given sum in binary tree

For a given binary tree and a sum, I have written the following function to check whether there is a root to leaf path in that tree with the given sum. ...
3
votes
0answers
45 views

Optimising insert operation for btree

I'm working on implementation insert operation for a btree, and would like to know if there is any way to optimise the inserting operation to make it go faster. The code seems really long so I'm ...
3
votes
1answer
76 views

Trie Tree match string containing ? and *

Using Python 2.7 and here is my code which implement trie match for a whole word, and also support if the whole word contains ? (match any one character) or ...
8
votes
3answers
366 views

Building a minimal-height BST from a monotonically increasingly ordered array structure

Problem statement: Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height. Assumptions: The array (and ...
2
votes
0answers
51 views

GSS4 - Segment Tree implementation 2

The problem is also known as GSS4. The exact detail can be seen here but I reached TLE. You are given a sequence A of N(N <= 100,000) positive integers. There sum will be less than \$10^{18}\$....
4
votes
3answers
195 views

Kattis Challenge - Animal Classification

I'm new to competitive programming and C++ in general. I have solved the Kattis Animal Classification challenge. We are given two classification trees, each represented using nested parentheses. ...