All Questions
15 questions
2
votes
1
answer
140
views
function to group data by parent branches
I wrote this function to take database output like from PDO's fetchAll(PDO::FETCH_ASSOC) and turn it into a tree. For small datasets it works well. However, when ...
1
vote
1
answer
90
views
Java - Select the maximum integers from sliding windows over an array
So I have the following algorithm. Given an array A[0 ... n - 1] and the window length w, compute all the windows ...
8
votes
1
answer
218
views
An array with \$O(\log\ n)\$ time complexity for all operations
Does this exist already? It's an array (=variable-size list with integer indices) where add/remove/set and get all take \$O(\log\ n)\$ time.
I couldn't find this anywhere, so I made up the name "Log-...
4
votes
1
answer
10k
views
Convert nested array of values to a tree structure
I have a nested array that represents a parent child relationship, that I need to convert to a tree structure.
Example nested array
...
2
votes
1
answer
135
views
Printing a K-ary tree stored in level-order in an array
I am given an array that represents a k-ary tree (I am also given the branching factor "k") that is stored in level order. My task was to print the tree in level order.
For example a trinary tree ...
4
votes
1
answer
203
views
Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height
I'm trying to find the complexity of this code and some suggestions for improving the code quality. and handling the code gracefully, esp in the areas of exception handling, checking edge cases, ...
1
vote
1
answer
984
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 ...
6
votes
3
answers
239
views
Tree abstraction
This code provides a Tree abstraction.
I would like to finalize the code structure only in tree directory, before starting ...
4
votes
3
answers
3k
views
(Re)Creating a tree from a flat collection (or "unflatten" a tree)
I need to create a tree from a flat collection. The order of elements is defined in a specification so it's rather impossible that it will ever change... but I want the whole algorithm to be ...
3
votes
3
answers
938
views
Building prefix tree from dictionary, performance issues
I'm trying to build a prfix tree. So, using the following dictionary 'and','anna','ape','apple', graph should look like this:
I've tried 2 approaches: using ...
3
votes
2
answers
410
views
Make binary search tree from sorted array
Here is my code for converting a sorted array to a binary search tree. Please review and let me know the improvements or some better way of solving this.
...
3
votes
1
answer
9k
views
Create a Tree Node from JavaScript Array
I'm trying to create a list of subpaths from a flattened array.
Here's the starting point:
...
5
votes
1
answer
3k
views
Turning a 2D array into a tree
I have the following data structure that's obtained from a third party:
...
3
votes
1
answer
7k
views
Array implementation of unbalanced binary search tree
I'm preparing for an interview. I tried implementing binary search tree in C++. I used array but it seems to be complicated to restructure the array while deleting nodes. Is linked list a better data ...
1
vote
1
answer
181
views
Rendering JSON array as a tree
This code is working fine for me, but I want to simplify it.
Function parents is defining parents of the tree and children ...