Comparing version 0.1.7 to 0.1.8
@@ -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; |
{ | ||
"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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12773
313