New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

namastey-avl-tree

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

namastey-avl-tree

A comprehensive JavaScript package for implementing AVL Tree data structure, offering balanced tree operations for efficient data management.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

namastey-avl-tree

Brief Description

namastey-avl-tree is a JavaScript package that implements the AVL Tree data structure. AVL Trees are self-balancing binary search trees that ensure the height difference between the left and right subtrees (balance factor) is no more than one, which guarantees O(log n) time complexity for insertions, deletions, and lookups.

Features

  • insertValue(value): Inserts a value into the AVL Tree, maintaining the balance of the tree.
  • searchValue(value): Searches for a value in the AVL Tree and returns the node if found, or null if not found.
  • inOrder(node): Performs an in-order traversal of the tree, printing the values in ascending order.
  • getHeight(node): Returns the height of a given node.
  • getBalanceFactor(node): Returns the balance factor of a given node.
  • rightRotate(node): Performs a right rotation on the subtree rooted with the given node.
  • leftRotate(node): Performs a left rotation on the subtree rooted with the given node.

Installation

To install the namastey-avl-tree package globally, run:

npm install -g namastey-avl-tree

Examples

Inserting Values

const AVLTree = require('namastey-avl-tree');
const tree = new AVLTree();

tree.insertValue(10);
tree.insertValue(20);
tree.insertValue(5);
tree.insertValue(6);
tree.insertValue(15);

tree.inOrder(tree.root); // Output: 5, 6, 10, 15, 20

Searching for a Value

const result = tree.searchValue(15);
console.log(result ? 'Found' : 'Not Found'); // Output: Found

Tree Balancing Example

tree.insertValue(25);
tree.insertValue(30);
tree.inOrder(tree.root); // Output: 5, 6, 10, 15, 20, 25, 30

FAQs

Package last updated on 27 Aug 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc