Skip to content

Latest commit

 

History

History
50 lines (32 loc) · 1.46 KB

readme.md

File metadata and controls

50 lines (32 loc) · 1.46 KB

Javascript Algorithms

Here I will add a handful of algorithms from many fields I find useful and interesting.

Euclidean (aka GCD)

Preview
GCD stands for Greatest Common Divisor.
Given 2 natural numbers, find their greatest common divisor that divides both of them without leaving any reminder.

Time Complexity: O(log min(a, b))

Graph (Data Structure)

Preview
Will be used in graph algorithms later on.
Assuming each node is connected to at least one other node.
Can be direcred/undirecred and/or weighted/unweighted.
Using adjacency list.
Default graph is direcred & unweighted (weight = 1).

Bin (Data Structure)

Preview
To be used in bin packing algorithms.

Next Fit (NF) - Bin Packing

Preview
At any given time there is only 1 open bin that we check. It considers the items in an order defined by a list 'items'. If an item fits inside the currently considered bin, the item is placed inside it. Otherwise, the current bin is closed, a new bin is opened and the current item is placed inside this new bin.

Time Complexity: O(n) where n = |items|

Approximation Guarantee: 2*OPT(n) where n = |items|

Binary Search

Preview
Finds the position (index) of a target value within a sorted array.

Time Complexity: O(log n) where n = |items|

License

All algorithms are licensed under the MIT license.

Have fun!