Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 ...
aswine's user avatar
  • 123
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 ...
coderodde's user avatar
  • 31.3k
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-...
Stefan Reich's user avatar
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 ...
OrderAndChaos's user avatar
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 ...
Prithvi Boinpally's user avatar
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, ...
user2769790's user avatar
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 ...
TheLearner's user avatar
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 ...
overexchange's user avatar
  • 3,401
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 ...
t3chb0t's user avatar
  • 44.6k
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 ...
haldagan's user avatar
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. ...
Mosbius8's user avatar
  • 787
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: ...
KyleMit's user avatar
  • 227
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: ...
Etheryte's user avatar
  • 654
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 ...
user3651245's user avatar
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 ...
Priyantha Weerasinghe's user avatar