repo_name stringclasses 25
values | repo_full_name stringclasses 25
values | owner stringclasses 25
values | stars int64 117k 496k | license stringclasses 7
values | repo_description stringclasses 25
values | filepath stringlengths 9 75 | file_type stringclasses 3
values | language stringclasses 2
values | content stringlengths 24 383k | size_bytes int64 25 387k | num_lines int64 2 4.44k |
|---|---|---|---|---|---|---|---|---|---|---|---|
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\graph\travelling-salesman\README.md | readme | Markdown | # Travelling Salesman Problem
The travelling salesman problem (TSP) asks the following question:
"Given a list of cities and the distances between each pair of
cities, what is the shortest possible route that visits each city
and returns to the origin city?"

> There is an [interactive version of this post](https://trekhleb.dev/blog/2... | 32,464 | 510 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\image-processing\seam-carving\README.ru-RU.md | readme | Markdown | # Изменение размеров изображения с учетом его содержимого в JavaScript

> Доступна [английская интерактивная версия этой с... | 46,808 | 510 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\linked-list\reverse-traversal\README.md | readme | Markdown | # Reversed Linked List Traversal
_Read this in other languages:_
[_中文_](README.zh-CN.md),
[_Português_](README.pt-BR.md)
The task is to traverse the given linked list in reversed order.
For example for the following linked list:

The o... | 549 | 24 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\linked-list\reverse-traversal\README.pt-BR.md | readme | Markdown | # Travessia de Lista Encadeada Reversa
_Leia isso em outros idiomas:_
[_中文_](README.zh-CN.md),
[_English_](README.md)
A tarefa é percorrer a lista encadeada fornecida em ordem inversa.
Por exemplo, para a seguinte lista vinculada:

A or... | 557 | 24 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\linked-list\reverse-traversal\README.zh-CN.md | readme | Markdown | # 链表倒序遍历
我们的任务是倒序遍历给定的链表
比如下面的链表

遍历的顺序应该是
```text
37 → 99 → 12
```
因为我们每个节点只访问一次,时间复杂度应该是`O(n)`
## 参考
- [Wikipedia](https://zh.wikipedia.org/wiki/%E9%93%BE%E8%A1%A8)
| 397 | 20 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\linked-list\traversal\README.md | readme | Markdown | # Linked List Traversal
_Read this in other languages:_
[_Русский_](README.ru-RU.md),
[_中文_](README.zh-CN.md),
[_Português_](README.pt-BR.md)
The task is to traverse the given linked list in straight order.
For example for the following linked list:
,
[_中文_](README.zh-CN.md),
[_English_](README.md)
A tarefa é percorrer a lista encadeada fornecida em ordem direta.
Por exemplo, para a seguinte lista vinculada:

Порядок обхода будет такой:
```text
12 → 99 → 37
```
Временная сложность - `O(n)`,... | 731 | 20 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\linked-list\traversal\README.zh-CN.md | readme | Markdown | # 链表遍历
我们的任务是顺序遍历给定的链表
比如下面的链表

遍历的顺序应该是
```text
12 → 99 → 37
```
因为我们每个节点只访问一次,时间复杂度应该是`O(n)`
## 参考
- [Wikipedia](https://zh.wikipedia.org/wiki/%E9%93%BE%E8%A1%A8) | 407 | 19 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\binary-floating-point\README.md | readme | Markdown | # Binary representation of floating-point numbers
Have you ever wondered how computers store the floating-point numbers like `3.1416` (𝝿) or `9.109 × 10⁻³¹` (the mass of the electron in kg) in the memory which is limited by a finite number of ones and zeroes (aka bits)?
It seems pretty straightforward for integers (... | 7,304 | 104 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\bits\README.fr-FR.md | readme | Markdown | # Manipulation de bits
_Read this in other languages:_
[english](README.md).
#### Vérifier un bit (_get_)
Cette méthode décale le bit correspondant (_bit shifting_) à la position zéro.
Ensuite, nous exécutons l'opération `AND` avec un masque comme `0001`.
Cela efface tous les bits du nombre original sauf le correspo... | 10,423 | 296 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\bits\README.md | readme | Markdown | # Bit Manipulation
_Read this in other languages:_
[français](README.fr-FR.md),
[简体中文](README.zh-CN.md).
#### Get Bit
This method shifts the relevant bit to the zeroth position.
Then we perform `AND` operation with one which has bit
pattern like `0001`. This clears all bits from the original
number except the releva... | 9,005 | 275 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\bits\README.zh-CN.md | readme | Markdown | # 位运算
_Read this in other languages:_
[français](README.fr-FR.md),
[english](README.md)
#### Get Bit
该方法向右移动目标位到最右边,即位数组的第0个位置上。然后在该数上与形如 `0001`的二进制形式的数进行`AND`操作。这会清理掉除了目标位的所有其它位的数据。如果目标位是1,那么结果就是`1`,反之,结果是`0`;
> 查看[getBit.js](getBit.js)了解更多细节。
#### Set Bit
该方法把`1`向左移动了`bitPosition`位,生成了一个二进制形如`00100`的值。然后我们拿该值与目... | 8,368 | 237 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\complex-number\README.fr-FR.md | readme | Markdown | # Nombre complexe
_Read this in other languages:_
[english](README.md).
Un **nombre complexe** est un nombre qui peut s'écrire sous la forme
`a + b * i`, tels que `a` et `b` sont des nombres réels,
et `i` est la solution de l'équation `x^2 = −1`.
Du fait qu'aucun _nombre réel_ ne statisfait l'équation,
`i` est appell... | 8,082 | 238 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\complex-number\README.md | readme | Markdown | # Complex Number
_Read this in other languages:_
[français](README.fr-FR.md).
A **complex number** is a number that can be expressed in the
form `a + b * i`, where `a` and `b` are real numbers, and `i` is a solution of
the equation `x^2 = −1`. Because no _real number_ satisfies this
equation, `i` is called an _imagin... | 7,223 | 229 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\euclidean-algorithm\README.fr-FR.md | readme | Markdown | # Algorithme d'Euclide
_Read this in other languages:_
[english](README.md).
En mathématiques, l'algorithme d'Euclide est un algorithme qui calcule le plus grand commun diviseur (PGCD) de deux entiers, c'est-à-dire le plus grand entier qui divise les deux entiers, en laissant un reste nul. L'algorithme ne connaît pas... | 3,241 | 50 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\euclidean-algorithm\README.md | readme | Markdown | # Euclidean algorithm
_Read this in other languages:_
[français](README.fr-FR.md).
In mathematics, the Euclidean algorithm, or Euclid's algorithm,
is an efficient method for computing the greatest common divisor
(GCD) of two numbers, the largest number that divides both of
them without leaving a remainder.
The Eucli... | 2,853 | 61 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\euclidean-distance\README.md | readme | Markdown | # Euclidean Distance
In mathematics, the **Euclidean distance** between two points in Euclidean space is the length of a line segment between the two points. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, therefore occasionally being called the Pythagorean distance.
!... | 1,734 | 37 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\factorial\README.fr-FR.md | readme | Markdown | # Factorielle
_Lisez ceci dans d'autres langues:_
[english](README.md), [_简体中文_](README.zh-CN.md).
En mathématiques, la factorielle d'un entier naturel `n`,
notée avec un point d'exclamation `n!`, est le produit des nombres entiers
strictement positifs inférieurs ou égaux à n. Par exemple:
```
5! = 5 * 4 * 3 * 2 * 1... | 955 | 36 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\factorial\README.ka-GE.md | readme | Markdown | # ფაქტორიალი
მათემატიკაში `n` ნატურალური რიცხვის ფაქტორიალი
(აღინიშნება `n!` სიმბოლოთი)
არის ყველა ნატურალური რიცხვის ნამრავლი 1-იდან `n`-ის ჩათვლით. მაგალითად:
```
5! = 5 * 4 * 3 * 2 * 1 = 120
```
| n | n! |
| --- | ----------------: |
| 0 | 1 |
| 1 | 1 |
| 2 |... | 1,252 | 33 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\factorial\README.md | readme | Markdown | # Factorial
_Read this in other languages:_
[_简体中文_](README.zh-CN.md), [_Français_](README.fr-FR.md), [_Türkçe_](README.tr-TR.md), [_ქართული_](README.ka-GE.md), [_Українська_](README.uk-UA.md).
In mathematics, the factorial of a non-negative integer `n`,
denoted by `n!`, is the product of all positive integers less
t... | 1,036 | 36 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\factorial\README.tr-TR.md | readme | Markdown | # Faktöriyel
_Bunu diğer dillerde okuyun:_
[_简体中文_](README.zh-CN.md), [français](README.fr-FR.md).
Faktöriyel, matematikte, sağına ünlem işareti konulmuş sayıya
verilen isim, daha genel olan Gama fonksiyonunun tam sayılarla
sınırlanmış özel bir durumudur. 1'den başlayarak belirli bir
sayma sayısına kadar olan sayılar... | 1,149 | 39 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\factorial\README.uk-UA.md | readme | Markdown | # Факторіал
_Прочитайте це іншими мовами:_
[_English_](README.md), [_简体中文_](README.zh-CN.md), [_Français_](README.fr-FR.md), [_Türkçe_](README.tr-TR.md), [_ქართული_](README.ka-GE.md).
У математиці факторіал невід'ємного цілого числа `n`, позначений `n!`, є добутком усіх натуральних чисел, менших або рівних `n`. Напри... | 1,187 | 34 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\factorial\README.zh-CN.md | readme | Markdown | # 阶乘
在数学上, 一个正整数 `n` 的阶乘 (写作 `n!`), 就是所有小于等于 `n` 的正整数的乘积. 比如:
```
5! = 5 * 4 * 3 * 2 * 1 = 120
```
| n | n! |
| ----- | --------------------------: |
| 0 | 1 |
| 1 | 1 |
| 2 | 2 |
| 3 | 6 ... | 917 | 28 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\fast-powering\README.fr-FR.md | readme | Markdown | # Algorithme d'exponentiation rapide
_Read this in other languages:_
[english](README.md).
En algèbre, une **puissance** d'un nombre est le résultat de la multiplication répétée de ce nombre avec lui-même.
Elle est souvent notée en assortissant le nombre d'un entier, typographié en exposant, qui indique le nombre de... | 2,244 | 74 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\fast-powering\README.md | readme | Markdown | # Fast Powering Algorithm
_Read this in other languages:_
[français](README.fr-FR.md).
**The power of a number** says how many times to use the number in a
multiplication.
It is written as a small number to the right and above the base number.

##... | 1,875 | 72 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\fibonacci\README.fr-FR.md | readme | Markdown | # Nombre de Fibonacci
_Read this in other languages:_
[english](README.md),
[ქართული](README.ka-GE.md).
En mathématiques, la suite de Fibonacci est une suite d'entiers
dans laquelle chaque terme (après les deux premiers)
est la somme des deux termes qui le précèdent.
Les termes de cette suite sont appelés nombres de ... | 1,023 | 25 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\fibonacci\README.ka-GE.md | readme | Markdown | # ფიბონაჩის რიცხვი
მათემატიკაში ფიბონაჩის მიმდევრობა წარმოადგენს მთელ რიცხვთა მიმდევრობას,
რომელშიც ყოველი რიცხვი (პირველი ორი რიცხვის შემდეგ)
მისი წინამორბედი ორი რიცხვის
ჯამის ტოლია:
`0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...`
კვადრატების წყობა, სადაც ყოველი კვადრატის გვერდების სიგრძე, თანმიმდევრობით, ფიბო... | 1,712 | 21 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\fibonacci\README.md | readme | Markdown | # Fibonacci Number
_Read this in other languages:_
[français](README.fr-FR.md),
[简体中文](README.zh-CN.md),
[ქართული](README.ka-GE.md).
In mathematics, the Fibonacci numbers are the numbers in the following
integer sequence, called the Fibonacci sequence, and characterized by
the fact that every number after the first t... | 1,029 | 26 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\fibonacci\README.zh-CN.md | readme | Markdown | # 斐波那契数
_Read this in other languages:_
[français](README.fr-FR.md),
[english](README.md),
[ქართული](README.ka-GE.md).
在数学中,斐波那契数是以下整数序列(称为斐波那契数列)中的数字,其特征在于前两个数字之后的每个数字都是前两个数字的和:
`0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...`
边长为连续斐波纳契数的正方形平铺
.
## Définitions
La transformation de Fourier (**ℱ**) est une opération qui transforme
une fonction intégrable sur ℝ en une autre fonction,
décrivant le spectre fréquentiel de cette dernière
La **Transformée de Fourier Discrète** (**TFD... | 8,942 | 136 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\fourier-transform\README.md | readme | Markdown | # Fourier Transform
_Read this in other languages:_
[français](README.fr-FR.md).
## Definitions
The **Fourier Transform** (**FT**) decomposes a function of time (a signal) into
the frequencies that make it up, in a way similar to how a musical chord can be
expressed as the frequencies (or pitches) of its constituent... | 7,215 | 134 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\horner-method\README.md | readme | Markdown | # Horner's Method
In mathematics, Horner's method (or Horner's scheme) is an algorithm for polynomial evaluation. With this method, it is possible to evaluate a polynomial with only `n` additions and `n` multiplications. Hence, its storage requirements are `n` times the number of bits of `x`.
Horner's method can be b... | 1,939 | 21 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\integer-partition\README.md | readme | Markdown | # Integer Partition
In number theory and combinatorics, a partition of a positive
integer `n`, also called an **integer partition**, is a way of
writing `n` as a sum of positive integers.
Two sums that differ only in the order of their summands are
considered the same partition. For example, `4` can be partitione... | 1,109 | 35 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\is-power-of-two\README.md | readme | Markdown | # Is a power of two
Given a positive integer, write a function to find if it is
a power of two or not.
**Naive solution**
In naive solution we just keep dividing the number by two
unless the number becomes `1` and every time we do so, we
check that remainder after division is always `0`. Otherwise, the number can't ... | 1,275 | 52 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\least-common-multiple\README.md | readme | Markdown | # Least common multiple
In arithmetic and number theory, the least common multiple,
lowest common multiple, or smallest common multiple of
two integers `a` and `b`, usually denoted by `LCM(a, b)`, is
the smallest positive integer that is divisible by
both `a` and `b`. Since division of integers by zero is
undefin... | 1,956 | 63 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\liu-hui\README.md | readme | Markdown | # Liu Hui's π Algorithm
Liu Hui remarked in his commentary to The Nine Chapters on the Mathematical Art,
that the ratio of the circumference of an inscribed hexagon to the diameter of
the circle was `three`, hence `π` must be greater than three. He went on to provide
a detailed step-by-step description of an iterati... | 4,406 | 93 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\matrix\README.md | readme | Markdown | # Matrices
In mathematics, a **matrix** (plural **matrices**) is a rectangular array or table of numbers, symbols, or expressions, arranged in rows and columns. For example, the dimension of the matrix below is `2 × 3` (read "two by three"), because there are two rows and three columns:
```
| 1 9 -13 |
| 20 5 -6 |
... | 2,538 | 64 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\pascal-triangle\README.md | readme | Markdown | # Pascal's Triangle
In mathematics, **Pascal's triangle** is a triangular array of
the [binomial coefficients](https://en.wikipedia.org/wiki/Binomial_coefficient).
The rows of Pascal's triangle are conventionally enumerated
starting with row `n = 0` at the top (the `0th` row). The
entries in each row are numbered ... | 2,711 | 65 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\primality-test\README.md | readme | Markdown | # Primality Test
A **prime number** (or a **prime**) is a natural number greater than `1` that
cannot be formed by multiplying two smaller natural numbers. A natural number
greater than `1` that is not prime is called a composite number. For
example, `5` is prime because the only ways of writing it as a
product, `... | 1,237 | 26 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\prime-factors\README.md | readme | Markdown | # Prime Factors
_Read this in other languages:_
[简体中文](README.zh-CN.md).
**Prime number** is a whole number greater than `1` that **cannot** be made by multiplying other whole numbers. The first few prime numbers are: `2`, `3`, `5`, `7`, `11`, `13`, `17`, `19` and so on.
If we **can** make it by multiplying other wh... | 2,510 | 38 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\prime-factors\README.zh-CN.md | readme | Markdown | # 质数因子
_Read this in other languages:_
[english](README.md).
**质数** 是一个比 `1` 大的整数,且 **不能**由其它整数相乘得出。前几个质数是: `2`, `3`, `5`, `7`, `11`, `13`, `17`, `19`,依此类推。
如果我们**能**通过其它整数相乘得出,我们则称它为**合数**

_Image source: [Math is Fun](https://www.... | 2,109 | 39 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\radian\README.md | readme | Markdown | # Radian
The **radian** (symbol **rad**) is the unit for measuring angles, and is the
standard unit of angular measure used in many areas of mathematics.
The length of an arc of a unit circle is numerically equal to the measurement
in radians of the angle that it subtends; one radian is just under `57.3` degrees.
... | 1,137 | 37 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\sieve-of-eratosthenes\README.md | readme | Markdown | # Sieve of Eratosthenes
The Sieve of Eratosthenes is an algorithm for finding all prime numbers up to some limit `n`.
It is attributed to Eratosthenes of Cyrene, an ancient Greek mathematician.
## How it works
1. Create a boolean array of `n + 1` positions (to represent the numbers `0` through `n`)
2. Set positions... | 1,388 | 33 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\math\square-root\README.md | readme | Markdown | # Square Root (Newton's Method)
In numerical analysis, a branch of mathematics, there are several square root
algorithms or methods of computing the principal square root of a non-negative real
number. As, generally, the roots of a function cannot be computed exactly.
The root-finding algorithms provide approximatio... | 3,062 | 63 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\ml\k-means\README.md | readme | Markdown | # k-Means Algorithm
_Read this in other languages:_
[_Português_](README.pt-BR.md)
The **k-Means algorithm** is an unsupervised Machine Learning algorithm. It's a clustering algorithm, which groups the sample data on the basis of similarity between dimensions of vectors.
In k-Means classification, the output is a se... | 2,306 | 41 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\ml\k-means\README.pt-BR.md | readme | Markdown | # Algoritmo k-Means
_Leia isso em outros idiomas:_
[_English_](README.md)
O **algoritmo k-Means** é um algoritmo de aprendizado de máquina não supervisionado. É um algoritmo de agrupamento, que agrupa os dados da amostra com base na semelhança entre as dimensões dos vetores.
Na classificação k-Means, a saída é um co... | 2,306 | 36 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\ml\knn\README.md | readme | Markdown | # k-Nearest Neighbors Algorithm
_Read this in other languages:_
[_Português_](README.pt-BR.md)
The **k-nearest neighbors algorithm (k-NN)** is a supervised Machine Learning algorithm. It's a classification algorithm, determining the class of a sample vector using a sample data.
In k-NN classification, the output is ... | 2,657 | 45 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\ml\knn\README.pt-BR.md | readme | Markdown | # Algoritmo de k-vizinhos mais próximos
_Leia isso em outros idiomas:_
[_English_](README.md)
O **algoritmo de k-vizinhos mais próximos (k-NN)** é um algoritmo de aprendizado de máquina supervisionado. É um algoritmo de classificação, determinando a classe de um vetor de amostra usando dados de amostra.
Na classific... | 2,870 | 45 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\search\binary-search\README.es-ES.md | readme | Markdown | # Búsqueda binaria
_Lea esto en otros idiomas:_
[English](README.md)
[Português brasileiro](README.pt-BR.md).
En informática, la búsqueda binaria, también conocida como búsqueda de medio intervalo
búsqueda, búsqueda logarítmica, o corte binario, es un algoritmo de búsqueda
que encuentra la posición de un valor objeti... | 1,173 | 28 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\search\binary-search\README.md | readme | Markdown | # Binary Search
_Read this in other languages:_
[Português brasileiro](README.pt-BR.md).
[Español](README.es-ES.md).
In computer science, binary search, also known as half-interval
search, logarithmic search, or binary chop, is a search algorithm
that finds the position of a target value within a sorted
array. Binary... | 1,054 | 28 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\search\binary-search\README.pt-BR.md | readme | Markdown | # Busca Binária
_Leia isso em outras línguas:_
[english](README.md).
[Español](README.es-ES.md).
Em ciência da computação, busca binária, também conhecida como busca de meio-intervalo, busca logarítmica ou corte binário, é um algoritmo de pesquisa
que encontra a posição de um elemento alvo dentro de um
vetor ordenado... | 1,110 | 24 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\search\interpolation-search\README.md | readme | Markdown | # Interpolation Search
**Interpolation search** is an algorithm for searching for a key in an array that
has been ordered by numerical values assigned to the keys (key values).
For example we have a sorted array of `n` uniformly distributed values `arr[]`,
and we need to write a function to search for a particular ... | 1,614 | 41 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\search\jump-search\README.md | readme | Markdown | # Jump Search
Like Binary Search, **Jump Search** (or **Block Search**) is a searching algorithm
for sorted arrays. The basic idea is to check fewer elements (than linear search)
by jumping ahead by fixed steps or skipping some elements in place of searching all
elements.
For example, suppose we have an array `arr... | 1,315 | 28 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\search\linear-search\README.md | readme | Markdown | # Linear Search
_Read this in other languages:_
[Português brasileiro](README.pt-BR.md).
In computer science, linear search or sequential search is a
method for finding a target value within a list. It sequentially
checks each element of the list for the target value until a
match is found or until all the element... | 930 | 24 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\search\linear-search\README.pt-BR.md | readme | Markdown | # Busca Linear
_Leia isso em outras línguas:_
[english](README.md).
Na Ciência da Computação, busca linear ou busca sequencial é um método para encontrar um elemento alvo em uma lista.
O algoritmo verifica sequencialmente cada elemento da lista procurando o elemento alvo até ele ser encontrado ou até ter verificado ... | 916 | 20 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sets\cartesian-product\README.md | readme | Markdown | # Cartesian Product
In set theory a Cartesian product is a mathematical operation that returns a set
(or product set or simply product) from multiple sets. That is, for sets A and B,
the Cartesian product A × B is the set of all ordered pairs (a, b)
where a ∈ A and b ∈ B.
Cartesian product `AxB` of two sets `A={x,y... | 551 | 15 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sets\combination-sum\README.md | readme | Markdown | # Combination Sum Problem
Given a **set** of candidate numbers (`candidates`) **(without duplicates)** and
a target number (`target`), find all unique combinations in `candidates` where
the candidate numbers sums to `target`.
The **same** repeated number may be chosen from `candidates` unlimited number
of times.
... | 1,348 | 61 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sets\combinations\README.md | readme | Markdown | # Combinations
When the order doesn't matter, it is a **Combination**.
When the order **does** matter it is a **Permutation**.
**"My fruit salad is a combination of apples, grapes and bananas"**
We don't care what order the fruits are in, they could also be
"bananas, grapes and apples" or "grapes, apples and bananas... | 2,324 | 69 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sets\fisher-yates\README.md | readme | Markdown | # Fisher–Yates shuffle
The Fisher–Yates shuffle is an algorithm for generating a random
permutation of a finite sequence—in plain terms, the algorithm
shuffles the sequence. The algorithm effectively puts all the
elements into a hat; it continually determines the next element
by randomly drawing an element from th... | 693 | 16 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sets\knapsack-problem\README.md | readme | Markdown | # Knapsack Problem
The knapsack problem or rucksack problem is a problem in
combinatorial optimization: Given a set of items, each with
a weight and a value, determine the number of each item to
include in a collection so that the total weight is less
than or equal to a given limit and the total value is as
large... | 3,262 | 70 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sets\longest-common-subsequence\README.md | readme | Markdown | # Longest common subsequence problem
The longest common subsequence (LCS) problem is the problem of finding
the longest subsequence common to all sequences in a set of sequences
(often just two sequences). It differs from the longest common substring
problem: unlike substrings, subsequences are not required to occup... | 1,100 | 26 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sets\longest-increasing-subsequence\README.md | readme | Markdown | # Longest Increasing Subsequence
The longest increasing subsequence problem is to find a subsequence of a
given sequence in which the subsequence's elements are in sorted order,
lowest to highest, and in which the subsequence is as long as possible.
This subsequence is not necessarily contiguous, or unique.
## Co... | 1,318 | 47 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sets\maximum-subarray\README.md | readme | Markdown | # Maximum subarray problem
The maximum subarray problem is the task of finding the contiguous
subarray within a one-dimensional array, `a[1...n]`, of numbers
which has the largest sum, where,


Bubble sort, sometimes referred to as sinking sort, is a
simple sorting algorithm that repeatedly steps through
the list to be sorted, compares each pair of adjacent
items and swaps them if they are in the wrong order
(ascending or descendin... | 1,151 | 26 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\bubble-sort\README.pt-BR.md | readme | Markdown | # Bubble Sort
_Leia isso em outros idiomas:_
[_English_](README.md)
O bubble sort, ou ordenação por flutuação (literalmente "por bolha"), é um algoritmo de ordenação dos mais simples. A ideia é percorrer o vetor diversas vezes, e a cada passagem fazer flutuar para o topo o maior elemento da sequência. Essa movimentaç... | 1,165 | 21 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\bucket-sort\README.md | readme | Markdown | # Bucket Sort
**Bucket sort**, or **bin sort**, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm.
## Algorithm
Bucket sort w... | 1,875 | 36 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\counting-sort\README.md | readme | Markdown | # Counting Sort
_Read this in other languages:_
[_Português_](README.pt-BR.md)
In computer science, **counting sort** is an algorithm for sorting
a collection of objects according to keys that are small integers;
that is, it is an integer sorting algorithm. It operates by
counting the number of objects that have e... | 3,353 | 71 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\counting-sort\README.pt-br.md | readme | Markdown | # Counting Sort
_Leia isso em outros idiomas:_
[_English_](README.md)
Em ciência da computação, **counting sort** é um algoritmo para ordenar
uma coleção de objetos de acordo com chaves que são pequenos inteiros;
ou seja, é um algoritmo de ordenação de inteiros. Ele opera por
contando o número de objetos que têm cada... | 3,697 | 71 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\heap-sort\README.md | readme | Markdown | # Heap Sort
_Read this in other languages:_
[_Português_](README.pt-BR.md)
Heapsort is a comparison-based sorting algorithm.
Heapsort can be thought of as an improved selection
sort: like that algorithm, it divides its input into
a sorted and an unsorted region, and it iteratively
shrinks the unsorted region by extra... | 1,193 | 28 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\heap-sort\README.pt-BR.md | readme | Markdown | # Heap Sort
_Leia isso em outros idiomas:_
[_English_](README.md)
Heapsort é um algoritmo de ordenação baseado em comparação. O Heapsort pode ser pensado como uma seleção aprimorada sort: como esse algoritmo, ele divide sua entrada em uma região classificada e uma região não classificada, e iterativamente encolhe a r... | 1,250 | 21 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\insertion-sort\README.md | readme | Markdown | # Insertion Sort
_Read this in other languages:_
[_Português_](README.pt-BR.md)
Insertion sort is a simple sorting algorithm that builds
the final sorted array (or list) one item at a time.
It is much less efficient on large lists than more
advanced algorithms such as quicksort, heapsort, or merge
sort.

A ordenação por inserção é um algoritmo de ordenação simples que criaa matriz classificada final (ou lista) um item de cada vez.
É muito menos eficiente em grandes listas do que mais algoritmos avançados, como quicksort, heapsort ou merge
ordenar.... | 1,048 | 23 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\merge-sort\README.ko-KR.md | readme | Markdown | # 병합 정렬
컴퓨터과학에서, 병합 정렬(일반적으로 mergesort라고 쓰는)은 효율적이고, 범용적인, 비교 기반의 정렬 알고리즘입니다. 대부분의 구현들은 안정적인 정렬을 만들어내며, 이는 정렬된 산출물에서 동일한 요소들의 입력 순서가 유지된다는 것을 의미합니다. 병합 정렬은 1945년에 John von Neumann이 만든 분할 정복 알고리즘입니다.
병합 정렬의 예시입니다. 우선 리스트를 가장 작은 단위로 나누고(한 개의 요소), 두 개의 인접한 리스트를 정렬하고 병합하기 위해 각 요소와 인접한 리스트를 비교합니다. 마지막으로 모든 요소들은 정렬되고 병합됩니다... | 1,733 | 23 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\merge-sort\README.md | readme | Markdown | # Merge Sort
_Read this in other languages:_
[_한국어_](README.ko-KR.md),
[_Português_](README.pt-BR.md)
In computer science, merge sort (also commonly spelled
mergesort) is an efficient, general-purpose,
comparison-based sorting algorithm. Most implementations
produce a stable sort, which means that the implementation
... | 1,660 | 39 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\merge-sort\README.pt-BR.md | readme | Markdown | # Merge Sort
_Leia isso em outros idiomas:_
[_한국어_](README.ko-KR.md),
[_English_](README.md)
Em ciência da computação, merge sort (também comumente escrito
mergesort) é uma ferramenta eficiente, de propósito geral,
algoritmo de ordenação baseado em comparação. A maioria das implementações
produzir uma classificação e... | 1,829 | 39 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\quick-sort\README.md | readme | Markdown | # Quicksort
_Read this in other languages:_
[_简体中文_](README.zh-CN.md),
[_Português_](README.pt-BR.md)
Quicksort is a divide and conquer algorithm.
Quicksort first divides a large array into two smaller
sub-arrays: the low elements and the high elements.
Quicksort can then recursively sort the sub-arrays
The steps a... | 1,700 | 40 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\quick-sort\README.pt-BR.md | readme | Markdown | # Quicksort
_Leia isso em outros idiomas:_
[_简体中文_](README.zh-CN.md),
[_English_](README.md)
Quicksort é um algoritmo de dividir para conquistar.
Quicksort primeiro divide uma grande matriz em duas menores
submatrizes: os elementos baixos e os elementos altos.
O Quicksort pode então classificar recursivamente as subm... | 1,801 | 40 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\quick-sort\README.zh-CN.md | readme | Markdown | # 快速排序
快速排序是一种分而治之的算法。快速排序首先将一个大数组分成两个较小的子数组:比某个数小的元素和比某个数大的元素。然后快速排序可以递归地对子数组进行排序。
步骤是:
1. 从数组中选择一个元素,称为基点
2. 分区:对数组重新排序,使所有值小于基点的元素都在它左边,而所有值大于基点的元素都在它右边(相等的值可以放在任何一边)。在此分区之后,基点处于其最终位置(左边和右边的中间位置)。这称为分区操作。
3. 递归地将上述步骤应用于左边的数组和右边的数组。
快速排序算法的动画可视化。水平线是基点值。
,
In computer science, **radix sort** is a non-comparative integer sorting
algorithm that sorts data with integer keys by grouping keys by the individual
digits which share the same significant position and value. A positional notation
is requ... | 2,671 | 49 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\radix-sort\README.pt-BR.md | readme | Markdown | # Radix Sort
_Leia isso em outros idiomas:_
[_English_](README.md)
Em ciência da computação, **radix sort** é uma classificação inteira não comparativa
algoritmo que classifica os dados com chaves inteiras agrupando as chaves pelo indivíduo
dígitos que compartilham a mesma posição e valor significativos. Uma notação ... | 3,127 | 49 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\selection-sort\README.md | readme | Markdown | # Selection Sort
_Read this in other languages:_
[_Português_](README.pt-BR.md).
Selection sort is a sorting algorithm, specifically an
in-place comparison sort. It has O(n2) time complexity,
making it inefficient on large lists, and generally
performs worse than the similar insertion sort.
Selection sort is note... | 1,193 | 28 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\selection-sort\README.pt-BR.md | readme | Markdown | # Selection Sort
_Leia isso em outros idiomas:_
[_English_](README.md).
Selection Sort é um algoritmo de ordenação, mais especificamente um algoritmo de ordenação por comparação in-place (requer uma quantidade constante de espaço de memória adicional). Tem complexidade O(n²), tornando-o ineficiente em listas grandes ... | 1,319 | 21 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\shell-sort\README.md | readme | Markdown | # Shellsort
_Read this in other languages:_
[_Português_](README.pt-BR.md).
Shellsort, also known as Shell sort or Shell's method,
is an in-place comparison sort. It can be seen as either a
generalization of sorting by exchange (bubble sort) or sorting
by insertion (insertion sort). The method starts by sorting
p... | 2,779 | 61 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\sorting\shell-sort\README.pt-BR.md | readme | Markdown | # Shellsort
_Leia isso em outros idiomas:_
[_English_](README.md).
Shellsort, também conhecido como Shell sort ou método de Shell,
é uma classificação de comparação in-loco. Pode ser visto tanto como um
generalização da ordenação por troca (bubble sort) ou ordenação
por inserção (ordenação por inserção). O método com... | 2,931 | 61 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\stack\valid-parentheses\README.md | readme | Markdown | # Valid Parentheses Problem
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Every close bracket has a cor... | 1,939 | 45 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\statistics\weighted-random\README.md | readme | Markdown | # Weighted Random

## What is "Weighted Random"
Let's say you have a list of **items**. Item could be anything. For example, we may have a list of fruits and vegetables that you like to eat: `[ '🍌', '🍎', '🥕' ]`.
The list of **weights** represent the weight (or probability, or ... | 6,870 | 144 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\string\hamming-distance\README.md | readme | Markdown | # Hamming Distance
the Hamming distance between two strings of equal length is the
number of positions at which the corresponding symbols are
different. In other words, it measures the minimum number of
substitutions required to change one string into the other, or
the minimum number of errors that could have trans... | 829 | 24 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\string\knuth-morris-pratt\README.md | readme | Markdown | # Knuth–Morris–Pratt Algorithm
The Knuth–Morris–Pratt string searching algorithm (or
KMP algorithm) searches for occurrences of a "word" `W`
within a main "text string" `T` by employing the
observation that when a mismatch occurs, the word itself
embodies sufficient information to determine where the
next match c... | 742 | 20 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\string\levenshtein-distance\README.md | readme | Markdown | # Levenshtein Distance
The Levenshtein distance is a string metric for measuring the
difference between two sequences. Informally, the Levenshtein
distance between two words is the minimum number of
single-character edits (insertions, deletions or substitutions)
required to change one word into the other.
## Defi... | 5,777 | 116 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\string\longest-common-substring\README.md | readme | Markdown | # Longest Common Substring Problem
The longest common substring problem is to find the longest string
(or strings) that is a substring (or are substrings) of two or more
strings.
## Example
The longest common substring of the strings `ABABC`, `BABCA` and
`ABCBA` is string `ABC` of length 3. Other common substring... | 619 | 25 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\string\palindrome\README.md | readme | Markdown | # Palindrome Check
A [Palindrome](https://en.wikipedia.org/wiki/Palindrome) is a string that reads the same forwards and backwards.
This means that the second half of the string is the reverse of the
first half.
## Examples
The following are palindromes (thus would return `TRUE`):
```
- "a"
- "pop" -> p + o + ... | 668 | 30 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\string\rabin-karp\README.md | readme | Markdown | # Rabin Karp Algorithm
In computer science, the Rabin–Karp algorithm or Karp–Rabin algorithm
is a string searching algorithm created by Richard M. Karp and
Michael O. Rabin (1987) that uses hashing to find any one of a set
of pattern strings in a text.
## Algorithm
The Rabin–Karp algorithm seeks to speed up the ... | 2,633 | 57 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\string\regular-expression-matching\README.md | readme | Markdown | # Regular Expression Matching
Given an input string `s` and a pattern `p`, implement regular
expression matching with support for `.` and `*`.
- `.` Matches any single character.
- `*` Matches zero or more of the preceding element.
The matching should cover the **entire** input string (not partial).
**Note**
- `s... | 1,391 | 74 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\string\z-algorithm\README.md | readme | Markdown | # Z Algorithm
The Z-algorithm finds occurrences of a "word" `W`
within a main "text string" `T` in linear time `O(|W| + |T|)`.
Given a string `S` of length `n`, the algorithm produces
an array, `Z` where `Z[i]` represents the longest substring
starting from `S[i]` which is also a prefix of `S`. Finding
`Z` for the... | 2,079 | 63 |
javascript-algorithms | trekhleb/javascript-algorithms | trekhleb | 195,878 | MIT | 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings | src\algorithms\tree\breadth-first-search\README.md | readme | Markdown | # Breadth-First Search (BFS)
Breadth-first search (BFS) is an algorithm for traversing
or searching tree or graph data structures. It starts at
the tree root (or some arbitrary node of a graph, sometimes
referred to as a 'search key') and explores the neighbor
nodes first, before moving to the next level neighbors.
... | 1,183 | 40 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.