Skip to content

TheAlgorithms/JavaScript

master
Switch branches/tags
Code

Latest commit

* Bugfix AVLTree comparator

The original insertBalance function was doing raw value comparisons as opposed to using the tree's comparator. This is clearly unintentional, and would (ultimately) cause the structure to segfault when constructed with the stringData included in the updated test.

I've added the fix, scanned the rest of the code for similar issues, and added the appropriate test case which passes successfully with the fix. The jest code coverage increases slightly as well with the changes.

* 100% jest code coverage

Added a couple of extra elements to the original test tree, and then removed elements in an order such that all previously uncovered branches of code are now covered.

Also added an emptyTree structure to test some additional (trivial) base cases.

* standard style fix

missed this from my previous commit

* Iterative & in-place BFS

An iterative analog to the traditional recursive breadth-first-search algorithm for binary trees.

This in-place solution uses the pre-existing "traversal" array for both tracking the algorithm as well as storing the result.

Also tweaked old code by resetting the traversal array each time the tree is traversed (otherwise you're only allowed to traverse a tree once which doesn't seem correct even with a single traversal function).

* Update BreadthFirstTreeTraversal.js

got rid of unnecessary currentSize
added currentNode for clarity

* refactor out traversal member var

.. per earlier discussion w mods
also tweaked the tests to achieve 100% coverage
7a1141b

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

The Algorithms - JavaScript

JavaScript Repository of TheAlgorithms, which implements various algorithms and data structures in JavaScript.

JavaScript Banner

Language grade: JavaScript Checks Contributions Welcome standard.js Discord chat


These implementations are for demonstrative purposes only. Dedicated implementations of these algorithms and data structures are much better for performance and security reasons. We also do not provide any guarantee for api stability.


Before contributing to this repository, make sure to read our Contribution Guidelines. You can look at other TheAlgorithms Repositories or the issues with a "help wanted" label for inspiration regarding what to implement. Our maintainers will guide you through how to make your contribution properly if you make any mistakes. The names of the maintainers of this repository is listed in the CODEOWNERS file.

You can find a list of the algorithms currently in the repository in the directory. Explanations of many of the algorithms can be found in the wiki.