Skip to content

Commit 650e309

Browse files
committedAug 6, 2018
Merge branches 'issue-102-rabin-karp-fix' and 'master' of https://github.com/trekhleb/javascript-algorithms into issue-102-rabin-karp-fix
2 parents c4605ea + 7c9601d commit 650e309

File tree

21 files changed

+64
-29
lines changed

21 files changed

+64
-29
lines changed
 

‎README.ko-KR.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ _Read this in other languages:_
4848

4949
## 알고리즘
5050

51-
알고리즘은 어떤 종료의 문제를 풀 수 있는 정확한 방법이며,
51+
알고리즘은 어떤 종류의 문제를 풀 수 있는 정확한 방법이며,
5252
일련의 작업을 정확하게 정의해 놓은 규칙들입니다.
5353

5454
`B` - 입문자, `A` - 숙련자

‎src/algorithms/graph/kruskal/kruskal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function kruskal(graph) {
1010
// It should fire error if graph is directed since the algorithm works only
1111
// for undirected graphs.
1212
if (graph.isDirected) {
13-
throw new Error('Prim\'s algorithms works only for undirected graphs');
13+
throw new Error('Kruskal\'s algorithms works only for undirected graphs');
1414
}
1515

1616
// Init new graph that will contain minimum spanning tree of original graph.

‎src/algorithms/sets/combination-sum/combinationSum.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ function combinationSumRecursive(
1515
) {
1616
if (remainingSum < 0) {
1717
// By adding another candidate we've gone below zero.
18-
// This would mean that last candidate was not acceptable.
18+
// This would mean that the last candidate was not acceptable.
1919
return finalCombinations;
2020
}
2121

2222
if (remainingSum === 0) {
23-
// In case if after adding the previous candidate out remaining sum
24-
// became zero we need to same current combination since it is one
25-
// of the answer we're looking for.
23+
// If after adding the previous candidate our remaining sum
24+
// became zero - we need to save the current combination since it is one
25+
// of the answers we're looking for.
2626
finalCombinations.push(currentCombination.slice());
2727

2828
return finalCombinations;
2929
}
3030

31-
// In case if we haven't reached zero yet let's continue to add all
31+
// If we haven't reached zero yet let's continue to add all
3232
// possible candidates that are left.
3333
for (let candidateIndex = startFrom; candidateIndex < candidates.length; candidateIndex += 1) {
3434
const currentCandidate = candidates[candidateIndex];

‎src/data-structures/bloom-filter/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Bloom Filter
22

3-
A bloom filter is a space-efficient probabilistic
3+
A **bloom filter** is a space-efficient probabilistic
44
data structure designed to test whether an element
55
is present in a set. It is designed to be blazingly
66
fast and use minimal memory at the cost of potential

‎src/data-structures/doubly-linked-list/DoublyLinkedList.js

+10
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ export default class DoublyLinkedList {
213213
return nodes;
214214
}
215215

216+
/**
217+
* @param {*[]} values - Array of values that need to be converted to linked list.
218+
* @return {DoublyLinkedList}
219+
*/
220+
fromArray(values) {
221+
values.forEach(value => this.append(value));
222+
223+
return this;
224+
}
225+
216226
/**
217227
* @param {function} [callback]
218228
* @return {string}

‎src/data-structures/doubly-linked-list/__test__/DoublyLinkedList.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ describe('DoublyLinkedList', () => {
3636
expect(linkedList.toString()).toBe('3,2,1');
3737
});
3838

39+
it('should create linked list from array', () => {
40+
const linkedList = new DoublyLinkedList();
41+
linkedList.fromArray([1, 1, 2, 3, 3, 3, 4, 5]);
42+
43+
expect(linkedList.toString()).toBe('1,1,2,3,3,3,4,5');
44+
});
45+
3946
it('should delete node by value from linked list', () => {
4047
const linkedList = new DoublyLinkedList();
4148

‎src/data-structures/graph/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Graph
22

3-
In computer science, a graph is an abstract data type
3+
In computer science, a **graph** is an abstract data type
44
that is meant to implement the undirected graph and
55
directed graph concepts from mathematics, specifically
66
the field of graph theory

‎src/data-structures/hash-table/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Hash Table
22

3-
In computing, a hash table (hash map) is a data
4-
structure which implements an associative array
5-
abstract data type, a structure that can map keys
6-
to values. A hash table uses a hash function to
3+
In computing, a **hash table** (hash map) is a data
4+
structure which implements an *associative array*
5+
abstract data type, a structure that can *map keys
6+
to values*. A hash table uses a *hash function* to
77
compute an index into an array of buckets or slots,
88
from which the desired value can be found
99

‎src/data-structures/heap/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Heap (data-structure)
22

3-
In computer science, a heap is a specialized tree-based
3+
In computer science, a **heap** is a specialized tree-based
44
data structure that satisfies the heap property described
55
below.
66

‎src/data-structures/linked-list/LinkedList.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export default class LinkedList {
6565

6666
let deletedNode = null;
6767

68-
// If the head must be deleted then make 2nd node to be a head.
68+
// If the head must be deleted then make next node that is differ
69+
// from the head to be a new head.
6970
while (this.head && this.compare.equal(this.head.value, value)) {
7071
deletedNode = this.head;
7172
this.head = this.head.next;
@@ -127,17 +128,17 @@ export default class LinkedList {
127128
* @return {LinkedListNode}
128129
*/
129130
deleteTail() {
131+
const deletedTail = this.tail;
132+
130133
if (this.head === this.tail) {
131134
// There is only one node in linked list.
132-
const deletedTail = this.tail;
133135
this.head = null;
134136
this.tail = null;
135137

136138
return deletedTail;
137139
}
138140

139141
// If there are many nodes in linked list...
140-
const deletedTail = this.tail;
141142

142143
// Rewind to the last node and delete "next" link for the node before the last one.
143144
let currentNode = this.head;
@@ -174,6 +175,16 @@ export default class LinkedList {
174175
return deletedHead;
175176
}
176177

178+
/**
179+
* @param {*[]} values - Array of values that need to be converted to linked list.
180+
* @return {LinkedList}
181+
*/
182+
fromArray(values) {
183+
values.forEach(value => this.append(value));
184+
185+
return this;
186+
}
187+
177188
/**
178189
* @return {LinkedListNode[]}
179190
*/

‎src/data-structures/linked-list/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Linked List
22

3-
In computer science, a linked list is a linear collection
3+
In computer science, a **linked list** is a linear collection
44
of data elements, in which linear order is not given by
55
their physical placement in memory. Instead, each
66
element points to the next. It is a data structure

‎src/data-structures/linked-list/__test__/LinkedList.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ describe('LinkedList', () => {
184184
expect(linkedList.find({ callback: value => value.key === 'test5' })).toBeNull();
185185
});
186186

187+
it('should create linked list from array', () => {
188+
const linkedList = new LinkedList();
189+
linkedList.fromArray([1, 1, 2, 3, 3, 3, 4, 5]);
190+
191+
expect(linkedList.toString()).toBe('1,1,2,3,3,3,4,5');
192+
});
193+
187194
it('should find node by means of custom compare function', () => {
188195
const comparatorFunction = (a, b) => {
189196
if (a.customValue === b.customValue) {

‎src/data-structures/priority-queue/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Priority Queue
22

3-
In computer science, a priority queue is an abstract data type
3+
In computer science, a **priority queue** is an abstract data type
44
which is like a regular queue or stack data structure, but where
55
additionally each element has a "priority" associated with it.
66
In a priority queue, an element with high priority is served before

‎src/data-structures/queue/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Queue
22

3-
In computer science, a queue is a particular kind of abstract data
3+
In computer science, a **queue** is a particular kind of abstract data
44
type or collection in which the entities in the collection are
55
kept in order and the principle (or only) operations on the
66
collection are the addition of entities to the rear terminal

‎src/data-structures/stack/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stack
22

3-
In computer science, a stack is an abstract data type that serves
3+
In computer science, a **stack** is an abstract data type that serves
44
as a collection of elements, with two principal operations:
55

66
* **push**, which adds an element to the collection, and

‎src/data-structures/tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* [Segment Tree](segment-tree) - with min/max/sum range queries examples
77
* [Fenwick Tree](fenwick-tree) (Binary Indexed Tree)
88

9-
In computer science, a tree is a widely used abstract data
9+
In computer science, a **tree** is a widely used abstract data
1010
type (ADT) — or data structure implementing this ADT—that
1111
simulates a hierarchical tree structure, with a root value
1212
and subtrees of children with a parent node, represented as

‎src/data-structures/tree/avl-tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AVL Tree
22

3-
In computer science, an AVL tree (named after inventors
3+
In computer science, an **AVL tree** (named after inventors
44
Adelson-Velsky and Landis) is a self-balancing binary search
55
tree. It was the first such data structure to be invented.
66
In an AVL tree, the heights of the two child subtrees of any

‎src/data-structures/tree/binary-search-tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Binary Search Tree
22

3-
In computer science, binary search trees (BST), sometimes called
3+
In computer science, **binary search trees** (BST), sometimes called
44
ordered or sorted binary trees, are a particular type of container:
55
data structures that store "items" (such as numbers, names etc.)
66
in memory. They allow fast lookup, addition and removal of

‎src/data-structures/tree/red-black-tree/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Red–Black Tree
22

3-
A red–black tree is a kind of self-balancing binary search
3+
A **red–black tree** is a kind of self-balancing binary search
44
tree in computer science. Each node of the binary tree has
55
an extra bit, and that bit is often interpreted as the
66
color (red or black) of the node. These color bits are used
@@ -74,15 +74,15 @@ unlike ordinary binary search trees.
7474

7575
#### Left Right Case (See g, p and x)
7676

77-
![Red Black Tree Balancing](https://www.geeksforgeeks.org/wp-content/uploads/redBlackCase3d.png)
77+
![Red Black Tree Balancing](https://www.geeksforgeeks.org/wp-content/uploads/redBlackCase3b.png)
7878

7979
#### Right Right Case (See g, p and x)
8080

8181
![Red Black Tree Balancing](https://www.geeksforgeeks.org/wp-content/uploads/redBlackCase3c.png)
8282

8383
#### Right Left Case (See g, p and x)
8484

85-
![Red Black Tree Balancing](https://www.geeksforgeeks.org/wp-content/uploads/redBlackCase3c.png)
85+
![Red Black Tree Balancing](https://www.geeksforgeeks.org/wp-content/uploads/redBlackCase3d.png)
8686

8787
## References
8888

‎src/data-structures/tree/segment-tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Segment Tree
22

3-
In computer science, a segment tree also known as a statistic tree
3+
In computer science, a **segment tree** also known as a statistic tree
44
is a tree data structure used for storing information about intervals,
55
or segments. It allows querying which of the stored segments contain
66
a given point. It is, in principle, a static structure; that is,

‎src/data-structures/trie/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Trie
22

3-
In computer science, a trie, also called digital tree and sometimes
3+
In computer science, a **trie**, also called digital tree and sometimes
44
radix tree or prefix tree (as they can be searched by prefixes),
55
is a kind of search tree—an ordered tree data structure that is
66
used to store a dynamic set or associative array where the keys

0 commit comments

Comments
 (0)
Please sign in to comment.