What javascript tree data structures are available?

JavascriptTree

Javascript Problem Overview


Are there good libraries for manipulating trees in javascript? Just to be clear, I am looking for tree as in data structure not display model.

Javascript Solutions


Solution 1 - Javascript

Here are some libraries that you may find helpful:

arboreal.js, a "micro-library for traversing and manipulating tree-like data structures" in node.js and the browser.

buckets, a "complete, fully tested and documented data structure library" that includes BSTs, a heap, and a bunch of other goodies.

Solution 2 - Javascript

Two libraries to add to the list are:

  • t.js - Seems to be good for traversal;
  • TreeModel - Manipulation and traversal.

disclaimer: I built TreeModel

Solution 3 - Javascript

Try the DOM

var o = document.createElement( 'WHAT_YOU_WANT' )
// o.appendChild( ... )

Solution 4 - Javascript

Wish I'd seen that solution before, because those libraries look helpful!

Here is one I put together which is an alternative. Meant for traversal, manipulation and loading of hierarchical tree structures from self referencing flat tables, not for balanced binary trees.

DataStructures.Tree and related blog post

Solution 5 - Javascript

I am not sure what your needs are so this is a shot in the dark. I normally use (for lightweight Javascript) an array of arrays, like this:

node[i] = [parent, firstChild, secondChild, ... nthChild];

Solution 6 - Javascript

I wrote one simple data oriented tree library called data-tree. You can use this to create, traverse and search tree in BFS/DFS fashion. You can also import/export data from tree. Checkout the detailed documentation at: http://cchandurkar.github.io/Data-Tree/

To use it in a node npm install data-tree

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionocouttsView Question on Stackoverflow
Solution 1 - Javascriptty.View Answer on Stackoverflow
Solution 2 - JavascriptjnunoView Answer on Stackoverflow
Solution 3 - JavascriptRaphaël PellicierView Answer on Stackoverflow
Solution 4 - JavascriptStephen JamesView Answer on Stackoverflow
Solution 5 - JavascriptAturSamsView Answer on Stackoverflow
Solution 6 - JavascriptChaitanya ChandurkarView Answer on Stackoverflow