1.0.0 • Published 3 years ago

javascript-algoritms v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

JavaScript Algorithms

Library for a bunch of useful JavaScript algorithms.

Complexity - Low

Search

naiveSearch()
TypeLoop in loop
How it worksCompares a string with another string and returns number of matches found.
PositiveSimple, good for small data sets.
NegativeInefficient for large data sets.
Efficiency AverageO(n^2)

Sorting - Low

bubbleSort()
TypeLoop in loop
How it worksSwapping, sorting from smallest to largest.
PositiveSimple, good for small data sets.
NegativeInefficient for large data sets.
Efficiency AverageO(n^2)
selectionSort()
TypeLoop in loop
How it worksSwapping, sorting from largest to smallest.
PositiveSimple, good for small data sets.
NegativeInefficient for large data sets.
Efficiency AverageO(n^2)
insertionSort()
TypeLoop in loop
How it worksSorting into new array.
PositiveSimple, good for small data sets and nearly sorted data, or when new data is addded continuously.
NegativeInefficient for large data sets.
Efficiency AverageO(n^2)

Complexity - Medium

Sorting - Medium

mergeSort()
TypeRecursive with loop
How it worksSplits arrays until each array has only one item (= is sorted). Then merge and sort each array until there's only one array left.
PositiveMore complex, good for large data sets
Negative
Efficiency AverageO(n log n)
quickSort()
TypeRecursive with loop
How it worksSets pivot on the mean value, puts smaller numbers left of pivot and larger right of pivot. Then sorts left half and right half of increasingly smaller sizes, until its done.
Positive
NegativeWith too large data sets you might run out of call stacks.
Efficiency AverageO(n log n)

Complexity - High

radixSort()
TypeLoop in loop
How it worksSorts an array of integers by loop-sorting them in buckets by number and then putting them back together.
PositiveFast.
NegativeOnly works on integers.
Efficiency AverageO(n k)