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.
6
votes
1answer
32 views
Implementation of k-d-Tree
I am a complete beginner in C and I have started learning it by implementing binary trees. So have implemented a basic k-d-Tree. I provide two structs and two methods for comparing values on different ...
1
vote
1answer
33 views
Recursive Preorder Traversal
For today, I tackled this coding challenge question:
Given a binary tree, write a method to recursively traverse the tree in the preorder manner. Mark a node as visited by adding its data to the list -...
1
vote
0answers
41 views
A Random Insult Generator (i.e. a Tree class for generating random sequences of elements)
I made a generic tree class, which is meant to be useful for generating random sequences of elements, for example, sentences (sequences of strings).
Also, I have some concernings regarding the tree's ...
3
votes
0answers
110 views
Hackerrank: Kindergarten Adventures
Problem statement
Description:
Meera teaches a class of n students, and every day in her classroom is
an adventure. Today is drawing day!
The students are sitting around
a round ...
-6
votes
0answers
836 views
Range Modular Queries [closed]
Given an array, A=[a0,a1,a2...an], perform queries in the form left right x y. For each query, find the number of elements in satisfying the following criteria ...
4
votes
1answer
51 views
1
vote
1answer
32 views
Method that remove duplicates from a list of words in Java [closed]
Today, I took a coding challenge with this question:
Given a List of Strings, write a method removeDuplicates that removes duplicate words from the List and returns an ArrayList of all the unique ...
2
votes
0answers
21 views
Improved Van Emde Boas tree based map in Java
After working on Van Emde Boas tree -based map in Java, I came up with this code. I managed to fix the bugs and improve the performance by using internally primitive integers instead of wrapped ...
-3
votes
1answer
40 views
Huffman tree node
I've implemented a Huffman tree for one of my academic coursework. For each of the nodes in the tree, there will be a left child, right child, and a parent. For each ...
2
votes
2answers
51 views
Alternate Tree implementation
I am trying to implement algorithms related to trees in Scala. I have dabbled with the following implementations of a tree. Are there any pros and cons of preferring the non-...
0
votes
0answers
41 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
55 views
Van Emde Boas tree -based map in Java
(Follow-up question: Improved 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
57 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
81 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
541 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
33 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
23 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
49 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
75 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
1answer
78 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
26 views
XmlJTree implementation
How can I make this more performant with large XML files (50 MB and up to several GBs)?
...
4
votes
1answer
104 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
46 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
46 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
62 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
194 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
81 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
46 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
25 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
72 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
63 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
19 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
88 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
136 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
75 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
167 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
138 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
380 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
64 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
63 views
3
votes
1answer
126 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
61 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 ...
1
vote
0answers
466 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
68 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
96 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
164 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
156 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
47 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
144 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 ...