Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding fix #1342 fixing docs for FenWickTree and DepthFirstSearch #1647

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1650272
adding fix #1342 fixing docs for FenWickTree and DepthFirstSearch
mohmmadAyesh Mar 27, 2024
96985a6
fix the coding style to pass code-style check
mohmmadAyesh Mar 27, 2024
5aa8bfa
adding JSDOCS for BreadthFirstTreeTraversal.js and formatting the new…
mohmmadAyesh Mar 27, 2024
575eead
adding JSDOCS for the following files BoyerMoore checkRearrangedPalin…
mohmmadAyesh Mar 27, 2024
18edde7
fixing JSDOCS for Sorts Folder the folder that been modified are Alph…
mohmmadAyesh Mar 27, 2024
1ec1979
adding js docs to files that missing it in search folder like binaryS…
mohmmadAyesh Mar 27, 2024
ae93e49
fixing formatting to avoid code/style workflow fail
mohmmadAyesh Mar 27, 2024
7560357
fixing or applying suggested changes
mohmmadAyesh Mar 27, 2024
c70f197
Merge remote-tracking branch 'origin/fixing-JS-docs-for-Sorts-Folder'…
mohmmadAyesh Mar 27, 2024
8f10dee
Merge remote-tracking branch 'origin/fixing-JS-docs-for-Search-Folder…
mohmmadAyesh Mar 27, 2024
de118c6
Merge remote-tracking branch 'origin/fixing-string-folder-JSDOCS' int…
mohmmadAyesh Mar 27, 2024
d64f4c9
fixing formatting to pass code/style automatic test
mohmmadAyesh Mar 27, 2024
f9a154b
adding more commits on fix-js-docs
mohmmadAyesh Mar 28, 2024
1d37ed9
fixing styling and formatting
mohmmadAyesh Mar 28, 2024
d9cc779
try to resolve not belonging commit
mohmmadAyesh Mar 27, 2024
ad98cee
Resolve conflict in CheckPalindrome.js during cherry-pick
mohmmadAyesh Mar 27, 2024
8d5cc4b
Resolve merge conflict in checkPalindrome function
mohmmadAyesh Mar 27, 2024
fb5530f
fixing JSDOCS for some files in Recursive folder
mohmmadAyesh Mar 28, 2024
7ae0aad
fixing JSDOCS for some files in Math folder that missing it
mohmmadAyesh Mar 28, 2024
2f74313
fixing styling and formating of files in Maths folder to pass automat…
mohmmadAyesh Mar 28, 2024
3d06ddf
fixing formating of MobiusFunction.js
mohmmadAyesh Mar 29, 2024
780fb91
trying to fix spelling in LucasSeries.js
mohmmadAyesh Mar 29, 2024
714cd66
fixing spelling at LinearSieve.js
mohmmadAyesh Mar 29, 2024
53035ec
remove unnecessary changes
mohmmadAyesh Mar 29, 2024
42b95ed
modifying only jsdocs of BinaryToDecimal RGBToHex in Conversions folder
mohmmadAyesh Mar 29, 2024
d82e849
modifiying JSDOCS for uniquepath and zerooneknapsack files in dynamic…
mohmmadAyesh Mar 29, 2024
8aab6f9
modifying jsdocs at unique paths at dynamic folder
mohmmadAyesh Mar 29, 2024
7651b8b
modifying JSDOCS at BinaryLifting file at Graphs Folder
mohmmadAyesh Mar 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 32 additions & 6 deletions Trees/BreadthFirstTreeTraversal.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
/*
Breadth First Tree Traversal or level order traversal implementation in javascript
Author: @GerardUbuntu
*/

/**
* Represents a node in a binary tree.
*/
class Node {
/**
* Creates a new node with the specified data.
* @param {*} data The data to be stored in the node.
*/
constructor(data) {
this.data = data
this.left = null
this.right = null
}
}

/**
* Represents a binary tree data structure.
*/
class BinaryTree {
/**
* Creates a new binary tree with an empty root.
*/
constructor() {
this.root = null
}

/**
* Performs breadth-first traversal of the binary tree iteratively.
* @returns {Array} An array containing the data of nodes visited in breadth-first order.
*/
breadthFirstIterative() {
const traversal = []
if (this.root) {
Expand All @@ -34,6 +46,10 @@ class BinaryTree {
return traversal
}

/**
* Performs breadth-first traversal of the binary tree recursively.
* @returns {Array} An array containing the data of nodes visited in breadth-first order.
*/
breadthFirstRecursive() {
const traversal = []
const h = this.getHeight(this.root)
Expand All @@ -43,7 +59,11 @@ class BinaryTree {
return traversal
}

// Computing the height of the tree
/**
* Computes the height of the tree starting from the specified node.
* @param {Node} node The node from which to compute the height.
* @returns {number} The height of the tree.
*/
getHeight(node) {
if (node === null) {
return 0
Expand All @@ -53,6 +73,12 @@ class BinaryTree {
return lheight > rheight ? lheight + 1 : rheight + 1
}

/**
* Traverses the specified level of the tree and adds nodes' data to the traversal array.
* @param {Node} node The current node being traversed.
* @param {number} levelRemaining The remaining level to traverse.
* @param {Array} traversal The array to store the traversal result.
*/
traverseLevel(node, levelRemaining, traversal) {
if (node === null) {
return
Expand Down
14 changes: 12 additions & 2 deletions Trees/DepthFirstSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
* DFS Algorithm for traversing or searching graph data structures.
*/

// traverses a give tree from specified root's value
/**
* Traverses a given tree using Depth-First Search (DFS) algorithm from the specified root's value.
* @param {Array} tree The tree data structure represented as an array of nodes.
* @param {number} rootValue The value of the root node from which traversal starts.
* @returns {Array} An array containing the values of nodes traversed in DFS order.
*/
function traverseDFS(tree, rootValue) {
const stack = []
const res = []
Expand All @@ -23,7 +28,12 @@ function traverseDFS(tree, rootValue) {
}
return res.reverse()
}

/**
* Searches for a node with the specified value in the given tree using Depth-First Search (DFS) algorithm.
* @param {Array} tree The tree data structure represented as an array of nodes.
* @param {number} value The value to search for in the tree nodes.
* @returns {Object|null} The node object if found, or null if the value is not found in the tree.
*/
function searchDFS(tree, value) {
const stack = []
stack.push(tree[0])
Expand Down
13 changes: 13 additions & 0 deletions Trees/FenwickTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*/

class FenwickTree {
/**
* Constructs a Fenwick Tree.
* @param {Array} fenwickArray The Fenwick Tree array to be initialized.
* @param {Array} array The input array whose prefix sum is to be calculated.
* @param {number} n The size of the input array.
*/
constructor(feneickArray, array, n) {
for (let i = 1; i <= n; i++) {
feneickArray[i] = 0
Expand All @@ -14,6 +20,13 @@ class FenwickTree {
}
}

/**
* Updates the Fenwick Tree with a new value at the specified index.
* @param {Array} fenwickArray The Fenwick Tree array.
* @param {number} n The size of the Fenwick Tree array.
* @param {number} index The index at which the value is updated.
* @param {number} value The new value to be added at the index.
*/
update(feneickArray, n, index, value) {
index = index + 1
while (index <= n) {
Expand Down