Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flex-algo

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flex-algo - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

4

lib/binaryTree.d.ts

@@ -20,3 +20,7 @@ export declare class BinaryNode {

leftSideView(): NodeValueType[];
_height(node: BinNode): number;
height(): number;
_nodeExists(idxToFind: number, height: number): boolean;
countCompleteTreeNodes(): number;
}
export {};

@@ -134,4 +134,51 @@ "use strict";

};
BinaryTree.prototype._height = function (node) {
if (node === null) {
return 0;
}
if ((node === null || node === void 0 ? void 0 : node.left) === null) {
return 1;
}
return this._height(node === null || node === void 0 ? void 0 : node.left) + 1;
};
BinaryTree.prototype.height = function () {
return this._height(this.root) - 1;
};
BinaryTree.prototype._nodeExists = function (idxToFind, height) {
var left = 0;
var right = Math.pow(2, height) - 1;
var level = 0;
var current = this.root;
while (level < height) {
var mid = Math.ceil((left + right) / 2);
if (idxToFind >= mid) {
current = current === null || current === void 0 ? void 0 : current.right;
left = mid;
}
else {
current = current === null || current === void 0 ? void 0 : current.left;
right = mid;
}
level += 1;
}
return current !== null;
};
BinaryTree.prototype.countCompleteTreeNodes = function () {
var height = this.height();
var upperCount = Math.pow(2, height) - 1;
var left = 0;
var right = upperCount;
while (left < right) {
var mid = Math.ceil((left + right) / 2);
if (this._nodeExists(mid, height)) {
left = mid;
}
else {
right = mid - 1;
}
}
return upperCount + left + 1;
};
return BinaryTree;
}());
exports.BinaryTree = BinaryTree;

2

package.json
{
"name": "flex-algo",
"version": "0.1.7",
"version": "0.1.8",
"description": "\"SDK for commonly used data structure and algorithms\"",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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