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.
0
votes
0answers
8 views
Ternary tree preoder traversal (recursive implementation)
Problem statement:
Print out to console the ternary tree preorder traversal. Suppose that the tree can have at most 3 children, left, middle and right. Preorder traversal is to visit the middle ...
5
votes
0answers
33 views
Van Emde Boas tree -based map in Java
For the experimental part of my MSc thesis I was working on van Emde Boas tree, and I have this:
...
-1
votes
0answers
19 views
F# tree-building function causes stack overflow in Xamarin Studio [migrated]
I'm trying to build up some rules in a tree structure, with logic gates i.e. and, not, or as well as conditions, e.g. property x equals value y. I wrote the most obvious recursive function first, ...
4
votes
1answer
50 views
Make the tree from a database into a tree of Java
There is a task to get the data from the database (tree) and translate them into Java. They must maintain their properties (each entry has parent and descendants).
I'm taking data from database using ...
6
votes
2answers
63 views
Prefix search by trie tree
I'm working on the prefix search problem:
Given a set of words, for example words = ['a', 'apple', 'angle', 'angel', 'bat', 'bats'], for any given prefix, find ...
8
votes
2answers
535 views
Check if Binary Search Tree
I wrote this entirely from scratch without any Googling/reading as part of an ongoing effort to improve my problem-solving skills.
Also, please note that the focus for my project was the problem ...
2
votes
1answer
32 views
Adding a new node in an AVL tree
I was working on a class assignment today and I wrote this code which works perfectly fine. It looks tho kind of has too much 'if statements' in it, and I was thinking that it could be written much ...
1
vote
0answers
20 views
FizzBuzz - A quartet of solutions
Since the FizzBuzz challenge is about developing ideas, I've added
a third test case for which I chose divisibility by 7 and its accompanying
tag "Go". This tag was purposely given a length other ...
6
votes
0answers
48 views
Using range minimal query for lowest common ancestor (LCA) — part 2
Here is my code to use range minimal query to resolve the LCA problem. I applied comments from here.
Any advice on code bugs, performance improvement in terms of algorithm time complexity, code style ...
0
votes
0answers
58 views
Delete a node from a Binary Search Tree
I was recently solving a question on LeetCode platform to delete a node from a Binary Search Tree, I wrote the given below iterative solution, I was wondering if it was a good practice to add a ...
1
vote
0answers
43 views
Procedural TreeCreator
Some time ago asked a question about creating a tree from a flat collection.
I thought I try to rewrite it with C# 7. I could actually only use the new local functions in this example but there are ...
1
vote
1answer
72 views
Simple Binary Search Tree in C++ using unique_ptr
The BST below slightly different from the ones I commonly see on here in that it uses std::unique_ptr to manage the memory. Thoughts?
...
1
vote
0answers
24 views
XmlJTree implementation
How can I make this more performant with large XML files (50 MB and up to several GBs)?
...
4
votes
1answer
98 views
Using range minimal query for lowest common ancestor (LCA)
Here is my code to use range minimal query to resolve the LCA problem. Any advice on code bugs, performance improvement in terms of algorithm time complexity, code style are appreciated.
More ...
4
votes
1answer
38 views
Generating Signatures of Tree Structures using an Order-Independent Hash
I'm working with a file format which stores data as a tree. Each node in the tree is known as a Tag, and every tag has a name ...
2
votes
1answer
44 views
Serialize and deserialize binary tree with a lot of empty nodes
Here is my code to serialize and deserialize binary tree, which may have a lot of empty nodes. I am written in Python 2.7. Any advice on performance improvement in terms of algorithm time complexity, ...
4
votes
1answer
51 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
1answer
129 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
79 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
45 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
24 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
63 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
58 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
77 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
134 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
67 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
157 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
115 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
285 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
56 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
62 views
3
votes
1answer
111 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
59 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
228 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
52 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
88 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
146 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
121 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
45 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
138 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
133 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
63 views
Binary Tree Inversion
I solved this problem.
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
To this
...
3
votes
1answer
71 views
3
votes
1answer
90 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
58 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
117 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
72 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
48 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
106 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 ...