Skip to content

Commit e5bd4b7

Browse files
committed
Merge branch 'master' of github.com:amejiarosario/dsa.js-data-structures-algorithms-javascript
2 parents ad15b5f + cccadf8 commit e5bd4b7

File tree

132 files changed

+18151
-4512
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+18151
-4512
lines changed

.circleci/config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ jobs: # a collection of steps
4646
- store_test_results: # for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
4747
path: test-results.xml
4848

49+
- run:
50+
name: release
51+
command: npm run semantic-release || true
52+
4953
docs:
5054
docker:
5155
- image: circleci/ruby:2.5.3-stretch-node

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = {
1515

1616
// https://eslint.org/docs/rules/no-plusplus
1717
// allows unary operators ++ and -- in the afterthought (final expression) of a for loop.
18-
'no-plusplus': [2, { 'allowForLoopAfterthoughts': true }],
18+
'no-plusplus': [0, { 'allowForLoopAfterthoughts': true }],
19+
'no-continue': [0],
1920

2021
// Allow for..of
2122
'no-restricted-syntax': [0, 'ForOfStatement'],

.node-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10.12.0
1+
12.16.1

CHANGELOG.md

+95-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,77 @@
1+
# [1.10.0](https://github.com/amejiarosario/dsa.js/compare/1.9.0...1.10.0) (2020-07-28)
2+
3+
4+
### Features
5+
6+
* **book/arrays:** add exercises ([bcaf819](https://github.com/amejiarosario/dsa.js/commit/bcaf81919cb889c1209c6d1e577b037047714c05))
7+
8+
# [1.9.0](https://github.com/amejiarosario/dsa.js/compare/1.8.3...1.9.0) (2020-06-30)
9+
10+
11+
### Features
12+
13+
* **heap:** remove by index ([6af937f](https://github.com/amejiarosario/dsa.js/commit/6af937fb380ffcd26558193c1626bdb84b2abe17))
14+
* **linkedList:** takes iterables in the constructor ([1fa875f](https://github.com/amejiarosario/dsa.js/commit/1fa875fd772eb4a45dd9690bea593b513687caca))
15+
16+
## [1.8.3](https://github.com/amejiarosario/dsa.js/compare/1.8.2...1.8.3) (2020-05-24)
17+
18+
19+
### Bug Fixes
20+
21+
* **book/maps:** update space complexity ([0be0176](https://github.com/amejiarosario/dsa.js/commit/0be0176efc121c5608c1a2df25280d6d9c08e6f3))
22+
23+
## [1.8.2](https://github.com/amejiarosario/dsa.js/compare/1.8.1...1.8.2) (2020-05-24)
24+
25+
26+
### Bug Fixes
27+
28+
* **book/hashset:** update hashset space complexity ([0319b29](https://github.com/amejiarosario/dsa.js/commit/0319b29e92a630c5f14d5e3208b72fe536b38f43))
29+
30+
## [1.8.1](https://github.com/amejiarosario/dsa.js/compare/1.8.0...1.8.1) (2020-05-24)
31+
32+
33+
### Bug Fixes
34+
35+
* **book/maps:** update time/space complexity values ([3c4ef75](https://github.com/amejiarosario/dsa.js/commit/3c4ef7555c400828fb89339184294feb7169b215))
36+
37+
# [1.8.0](https://github.com/amejiarosario/dsa.js/compare/1.7.1...1.8.0) (2020-05-23)
38+
39+
40+
### Bug Fixes
41+
42+
* **book/map:** fix typo on maps space complexity ([2f24f57](https://github.com/amejiarosario/dsa.js/commit/2f24f57f989bb97f198bb32f6daa477d6075dc31))
43+
* **hashmap:** improve methods documentation ([f6b47b5](https://github.com/amejiarosario/dsa.js/commit/f6b47b5a6c53126bebbad72ac92da1a594042232))
44+
45+
46+
### Features
47+
48+
* **maps:** implement clear method for hashMap and treeMap ([924c9a7](https://github.com/amejiarosario/dsa.js/commit/924c9a76db91f7df44f7cb38caba3aa9c3f0497f))
49+
50+
## [1.7.1](https://github.com/amejiarosario/dsa.js/compare/1.7.0...1.7.1) (2020-05-20)
51+
52+
53+
### Bug Fixes
54+
55+
* **hashmap:** fix TextEncoder reference ([e13ff88](https://github.com/amejiarosario/dsa.js/commit/e13ff88d7f8f9b7f38844befedc001bc1a4b243f))
56+
57+
# [1.7.0](https://github.com/amejiarosario/dsa.js/compare/1.6.0...1.7.0) (2020-05-16)
58+
59+
60+
### Features
61+
62+
* **heap:** add min/max/median-heaps ([202ca9f](https://github.com/amejiarosario/dsa.js/commit/202ca9f989ddba433b4f591e27bc094640cbbadf))
63+
64+
# [1.6.0](https://github.com/amejiarosario/dsa.js/compare/1.5.0...1.6.0) (2020-05-08)
65+
66+
# [1.5.0](https://github.com/amejiarosario/dsa.js/compare/1.4.0...1.5.0) (2020-03-30)
67+
68+
69+
### Features
70+
71+
* **linkedList:** remove by node ([eac045a](https://github.com/amejiarosario/dsa.js/commit/eac045a6bedd0223a2e8b12225f87c428e6fb66f))
72+
* **lru-cache:** add new implementations ([3e787c6](https://github.com/amejiarosario/dsa.js/commit/3e787c6f9ba9c094272be5ac05b997ce44a359d3))
73+
* **trie:** remove method ([16005f3](https://github.com/amejiarosario/dsa.js/commit/16005f3bf39597759918e34b39d27eb25a5755e7))
74+
175
# Changelog
276

377
All notable changes to this project will be documented in this file.
@@ -13,6 +87,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1387

1488
### Bug Fixes (patch)
1589

90+
## [1.3.9]
91+
92+
### Breaking Changes (major)
93+
94+
### New Features (minor)
95+
96+
### Bug Fixes (patch)
97+
- fix(book): fix table typos [commit](https://github.com/amejiarosario/dsa.js/commit/bc51a7a0c97aea9dea1afa5f8af22c0bed1382d3)
98+
99+
## [1.3.8]
100+
101+
### Breaking Changes (major)
102+
103+
### New Features (minor)
104+
105+
### Bug Fixes (patch)
106+
- fix(book): fix typo, array pop, and BST images [commit](https://github.com/amejiarosario/dsa.js/commit/ac9858348943f9678d116c8076bfa3a3c5362741)
107+
16108
## [1.3.7]
17109

18110
### Breaking Changes (major)
@@ -125,7 +217,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
125217

126218
-
127219

128-
[Unreleased]: https://github.com/amejiarosario/dsa.js/compare/1.3.7...HEAD
220+
[Unreleased]: https://github.com/amejiarosario/dsa.js/compare/1.3.9...HEAD
221+
[1.3.9]: https://github.com/amejiarosario/dsa.js/compare/1.3.8...1.3.9
222+
[1.3.7]: https://github.com/amejiarosario/dsa.js/compare/1.3.7...1.3.8
129223
[1.3.6]: https://github.com/amejiarosario/dsa.js/compare/1.3.6...1.3.7
130224
[1.3.6]: https://github.com/amejiarosario/dsa.js/compare/1.3.5...1.3.6
131225
[1.3.5]: https://github.com/amejiarosario/dsa.js/compare/1.3.4...1.3.5

CONTRIBUTING.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,9 @@ If the commit reverts a previous commit, it should begin with `revert: `, follow
137137
### Type
138138
Must be one of the following:
139139
140-
* **feat**: A new feature
141140
* **fix**: A bug fix
142-
* **docs**: Documentation only changes
143-
* **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
144-
* **ci**: Changes to our CI configuration files and scripts (example scopes: Circle, BrowserStack, SauceLabs)
145-
* **test**: Adding missing tests or correcting existing tests
146-
* **refactor**: A code change that neither fixes a bug nor adds a feature
147-
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
148-
* **perf**: A code change that improves performance
141+
* **feat**: A new feature
142+
* **chore**: Changes to our CI configuration files and scripts (example scopes: Circle, BrowserStack, SauceLabs)
149143
150144
### Scope
151145
The scope should be the name of the npm package affected (as perceived by the person reading the changelog generated from commit messages.
@@ -171,7 +165,7 @@ Just as in the **subject**, use the imperative, present tense: "change" not "cha
171165
The body should include the motivation for the change and contrast this with previous behavior.
172166

173167
### Footer
174-
The footer should contain any information about **Breaking Changes** and is also the place to
168+
The footer should contain any information about **BREAKING CHANGES** and is also the place to
175169
reference GitHub issues that this commit **Closes**.
176170

177171
```

README.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Data Structures and Algorithms in JavaScript
44

5-
[![CircleCI](https://img.shields.io/circleci/build/github/amejiarosario/dsa.js-data-structures-algorithms-javascript/master.svg)](https://circleci.com/gh/amejiarosario/dsa.js-data-structures-and-algorithms-in-javascript) [![NPM version](https://badge.fury.io/js/dsa.js.svg)](https://badge.fury.io/js/dsa.js) [![chat](https://dsajs-slackin.herokuapp.com/badge.svg)](https://dsajs-slackin.herokuapp.com)
5+
[![CircleCI](https://circleci.com/gh/amejiarosario/dsa.js-data-structures-algorithms-javascript.svg?style=shield)](https://app.circleci.com/pipelines/github/amejiarosario/dsa.js-data-structures-algorithms-javascript) [![NPM version](https://badge.fury.io/js/dsa.js.svg)](https://badge.fury.io/js/dsa.js) [![chat](https://dsajs-slackin.herokuapp.com/badge.svg)](https://dsajs-slackin.herokuapp.com)
66

77
> This is the coding implementations of the [DSA.js book](https://books.adrianmejia.com/dsajs-data-structures-algorithms-javascript/) and the repo for the NPM package.
88
@@ -91,7 +91,6 @@ _Note: If you prefer to consume the information more linearly then the [book for
9191

9292
The topics are divided into four main categories as you can see below:
9393

94-
_(You can click on the triangle ⯈ to expand the topics)_
9594

9695
### 📈 [Algorithms Analysis](book/part01-algorithms-analysis.asc)
9796

@@ -103,7 +102,7 @@ _(You can click on the triangle ⯈ to expand the topics)_
103102

104103
<details>
105104
<summary>
106-
Computer Science nuggets without all the mumbo-jumbo
105+
Computer Science nuggets without all the mumbo-jumbo. <i>(Click to expand)</i>
107106
</summary>
108107

109108
---
@@ -120,7 +119,7 @@ _(You can click on the triangle ⯈ to expand the topics)_
120119

121120
<details>
122121
<summary>
123-
Learn how to compare algorithms using Big O notation.
122+
Learn how to compare algorithms using Big O notation. <i>(Click to expand)</i>
124123
</summary>
125124

126125
---
@@ -142,7 +141,7 @@ they take different time to complete.
142141

143142
<details>
144143
<summary>
145-
8 examples to explain with code how to calculate time complexity
144+
8 examples to explain with code how to calculate time complexity. <i>(Click to expand)</i>
146145
</summary>
147146

148147
---
@@ -181,7 +180,7 @@ they take different time to complete.
181180

182181
<details>
183182
<summary>
184-
Understand the ins and outs of the most common data structures.
183+
Understand the ins and outs of the most common data structures. <i>(Click to expand)</i>
185184
</summary>
186185

187186
---
@@ -216,7 +215,7 @@ they take different time to complete.
216215
</details>
217216
<details>
218217
<summary>
219-
When to use an Array or Linked List. Know the tradeoffs.
218+
When to use an Array or Linked List. Know the tradeoffs. <i>(Click to expand)</i>
220219
</summary>
221220

222221
---
@@ -239,7 +238,7 @@ Use Linked Lists when:
239238
</details>
240239
<details>
241240
<summary>
242-
Build a List, Stack, and a Queue.
241+
Build a List, Stack, and a Queue. <i>(Click to expand)</i>
243242
</summary>
244243

245244
---
@@ -264,7 +263,7 @@ Use Linked Lists when:
264263
<blockquote>
265264
<details>
266265
<summary>
267-
Understand one of the most versatile data structure of all: Maps
266+
Understand one of the most versatile data structure of all: Hash Maps. <i>(Click to expand)</i>
268267
</summary>
269268

270269
---
@@ -289,7 +288,7 @@ Also, [learn the difference between the different Maps implementations](book/con
289288

290289
<details>
291290
<summary>
292-
Know the properties of Graphs and Trees.
291+
Know the properties of Graphs and Trees. <i>(Click to expand)</i>
293292
</summary>
294293

295294
---
@@ -391,7 +390,7 @@ From unbalanced BST to balanced BST
391390
<blockquote>
392391
<details>
393392
<summary>
394-
Never get stuck solving a problem with 7 simple steps
393+
Never get stuck solving a problem with 7 simple steps. <i>(Click to expand)</i>
395394
</summary>
396395

397396
---
@@ -414,7 +413,7 @@ Full details [here](book/part04-algorithmic-toolbox.asc)
414413
</details>
415414
<details>
416415
<summary>
417-
Master the most popular sorting algorithms (merge sort, quicksort, insertion sort, etc.)
416+
Master the most popular sorting algorithms (merge sort, quicksort, etc.) <i>(Click to expand)</i>
418417
</summary>
419418

420419
---
@@ -453,7 +452,7 @@ and then discuss efficient sorting algorithms O(n log n) such as:
453452
</details>
454453
<details>
455454
<summary>
456-
Learn different approaches to solve problems such as divide and conquer, dynamic programming, greedy algorithms, and backtracking.
455+
Learn different approaches to solve problems such as divide and conquer, dynamic programming, greedy algorithms, and backtracking. <i>(Click to expand)</i>
457456
</summary>
458457

459458
---
@@ -475,7 +474,7 @@ We are going to discuss the following techniques for solving algorithms problems
475474
## FAQ
476475

477476
<details>
478-
<summary>How would I apply these to my day-to-day work?</summary>
477+
<summary>How would I apply these to my day-to-day work? <i>(Click to expand)</i></summary>
479478
<p>
480479
As a programmer, we have to solve problems every day. If you want to solve problems well, then it's good to know about a broad range of solutions. A lot of times, it's more efficient to learn existing resources than stumble upon the answer yourself. The more tools and practice you have, the better. This book helps you understand the tradeoffs among data structures and reason about algorithms performance.
481480
</p>
@@ -507,11 +506,11 @@ This project is also available in a [book](https://books.adrianmejia.com/dsajs-d
507506

508507
Reach out to me at one of the following places!
509508

510-
- Twitter at <a href="http://twitter.com/amejiarosario" target="_blank">`@amejiarosario`</a>
509+
- Twitter at <a href="http://twitter.com/iAmAdrianMejia" target="_blank">`@iAmAdrianMejia`</a>
511510
- Chat on <a href="https://dsajs-slackin.herokuapp.com" target="_blank">`dsajs.slack.com`</a>
512511

513512
## License
514513

515514
[![License](https://img.shields.io/:license-mit-blue.svg?style=flat-square)](LICENSE)
516515

517-
![](https://data.uxeranalytics.com/image1.png?uxa=github-dsajs)
516+
<!-- ![](https://data.uxeranalytics.com/image1.png?uxa=github-dsajs) -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// brute force: O(nd) | O(1)
2+
function rotLeft(a, d) {
3+
for (let i = 0; i < d; i++) { // O(d)
4+
a.push(a.shift()); // O(n), shift O(n)
5+
}
6+
return a;
7+
}
8+
9+
module.exports = rotLeft;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// modulus for rotations: O(n^2) | O(1)
2+
function rotLeft(a, d) {
3+
const len = a.length;
4+
const rot = d % len;
5+
for (let i = 0; i < rot; i++) { // O(n^2)
6+
a.push(a.shift()); // O(n)
7+
}
8+
return a;
9+
}
10+
11+
module.exports = rotLeft;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// additional space: O(n) | O(n)
2+
function rotLeft(a, d) {
3+
const len = a.length;
4+
const rot = d % len;
5+
const b = [];
6+
for (let i = 0; i < len; i++) { // O(n)
7+
b[i] = a[(rot + i) % len]; // O(1)
8+
}
9+
return b;
10+
}
11+
12+
module.exports = rotLeft;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*eslint-disable */
2+
// npx jest benchmarks/two-sum-implementations/two-sum.spec.js --watch --collectCoverage
3+
const implementations = [
4+
{ name: 1, fn: require('./01-array-rotation') },
5+
{ name: '1a', fn: require('./01a-array-rotation') },
6+
{ name: 2, fn: require('./02-array-rotation') },
7+
];
8+
9+
implementations.forEach(({name, fn}) => {
10+
describe(`Two Sum: ${name}`, () => {
11+
it('should work on worst case', () => {
12+
const rots = 1000;
13+
const array = [1, 2, 3];
14+
expect(fn(array, rots)).toEqual([2,3,1]);
15+
});
16+
});
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Brute force: O(n^2) | O(1)
2+
function twoSum(nums, target) {
3+
for (let i = 0; i < nums.length - 1; i++) { // O(n^2)
4+
for (let j = i + 1; j < nums.length; j++) { // O(n)
5+
if (nums[i] + nums[j] === target) {
6+
return [i, j];
7+
}
8+
}
9+
}
10+
return [];
11+
}
12+
13+
module.exports = twoSum;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Brute force: O(n^2) | O(1)
2+
function twoSum(nums, target) {
3+
for (let i = 0; i < nums.length - 1; i++) { // O(n^2)
4+
const diff = target - nums[i];
5+
const offset = i + 1;
6+
const idx = nums.slice(offset).findIndex((n) => n === diff); // O(n)
7+
const j = offset + idx;
8+
if (idx > -1) return [i, j];
9+
}
10+
return [];
11+
}
12+
13+
module.exports = twoSum;

0 commit comments

Comments
 (0)