
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
@datastructures-js/avl-tree
Advanced tools
node's data type: string, number.
const avlTree = require('@datastructures-js/avl-tree');
const avl = avlTree();
.node(value, parent, left, right)
creates a binary tree node with height property.
const n = avl.node('test');
console.log(n.getValue()); // test
console.log(n.getParent()); // null
console.log(n.getLeft()); // null
console.log(n.getRight()); // null
console.log(n.getHeight()); // 1
.insert(value)
inserts a value into the tree and maintains the tree balance by rotating the imbalanced node.
avl.insert(20);
avl.insert(30);
avl.insert(40);
avl.insert(50);
avl.insert(60);
avl.insert(70);
avl.insert(80);
.root()
gets the root node
console.log(avl.root().getValue()); // 50
.min()
finds the min value node (most left).
console.log(avl.min().getValue()); // 20
.max()
finds the min value node (most right).
console.log(avl.max().getValue()); // 80
.count()
gets nodes count.
console.log(avl.count()); // 7
.find(value)
finds the value's node or returns null if not found.
let n = avl.find(30);
console.log(n.getValue()); // 30
console.log(n.getRight().getValue()); // 40
console.log(n.getLeft().getValue()); // 20
console.log(n.getHeight()); // 2
.traverseInOrder(cb)
// in-order traverse (left-parent-right)
avl.traverseInOrder(node => console.log(node.getValue()));
// 20
// 30
// 40
// 50
// 60
// 70
// 80
.traversePreOrder(cb)
// pre-order traverse (parent-left-right)
avl.traversePreOrder(node => console.log(node.getValue()));
// 50
// 30
// 20
// 40
// 70
// 60
// 80
.traversePostOrder(cb)
// post-order traverse (left-right-parent)
avl.traverse(node => console.log(node.getValue()));
// 20
// 40
// 30
// 60
// 80
// 70
// 50
.traverse(cb, order)
traverse the tree in the defined order and apply a callback on each node.
order values: inOrder
, preOrder
OR postOrder
. default is inOrder
avl.traverse(node => console.log(node.getValue())); // in-order
// 20
// 30
// 40
// 50
// 60
// 70
// 80
avl.traverse(node => console.log(node.getValue()), 'preOrder');
// 50
// 30
// 20
// 40
// 70
// 60
// 80
.remove(value)
removes a value's node (if exists) from the tree and maintains the tree balance by rotating the imbalanced node.
console.log(bst.find(30).getValue()); // 30
bst.remove(30);
console.log(bst.find(30)); // null
.clear()
clears the tree.
avl.clear();
console.log(avl.count()); // 0
grunt build
The MIT License. Full License is here
FAQs
avl tree implementation in javascript
We found that @datastructures-js/avl-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.