Skip to content

[pull] master from amejiarosario:master #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 251 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
251 commits
Select commit Hold shift + click to select a range
c1eda1d
Merge pull request #27 from monners/master
amejiarosario Aug 11, 2019
69afe33
change the stable properties
archanaserver Aug 16, 2019
3cb3cec
Merge pull request #28 from archanaserver/patch-1
amejiarosario Aug 16, 2019
98f0dfb
release: 1.3.4
amejiarosario Aug 16, 2019
b5aae35
fix typo
gerasimov Aug 19, 2019
3356e1f
Merge pull request #29 from gerasimov/patch-1
amejiarosario Aug 19, 2019
1fa9341
fix(tree-rotations): prevent losing nodes
amejiarosario Aug 23, 2019
ebb7be8
release: 1.3.5
amejiarosario Aug 23, 2019
72e3d68
style: fix eslint issue
amejiarosario Aug 23, 2019
d8ce2f5
update deps
amejiarosario Aug 23, 2019
8096f7c
release: 1.3.6
amejiarosario Aug 23, 2019
48fe6f3
Merge pull request #31 from amejiarosario/update-deps
amejiarosario Aug 23, 2019
98e2c03
fix(avl-tree): balance was not working properly
amejiarosario Aug 27, 2019
01ad65d
release: 1.3.7
amejiarosario Aug 27, 2019
22d0fb2
Merge pull request #34 from amejiarosario/beblueblue-question
amejiarosario Aug 27, 2019
2f202c1
fix yml file
amejiarosario Oct 15, 2019
c57cbfd
Update yaml file
amejiarosario Oct 17, 2019
06ef72a
Update README.md
bhagatapoorva Oct 31, 2019
8c0eca0
Merge pull request #36 from bhagatapoorva/master
amejiarosario Oct 31, 2019
f625d93
add examples
amejiarosario Nov 26, 2019
49d083b
fix lint errors
amejiarosario Nov 26, 2019
5628a27
Merge pull request #37 from amejiarosario/new-examples
amejiarosario Nov 26, 2019
ad15b5f
improve merge sort example
amejiarosario Jan 7, 2020
ac98583
fix(book): fix typo, array pop, and BST images
mdribera Feb 11, 2020
b9a41ba
Merge pull request #39 from mdribera/fix-typo-array-pop-and-bst-images
amejiarosario Feb 12, 2020
6f4585a
bump to 1.3.8
amejiarosario Feb 12, 2020
a53915f
fix(docs): fix typo for heaps
amejiarosario Feb 12, 2020
bb3ad9a
Merge pull request #40 from amejiarosario/version-bump
amejiarosario Feb 12, 2020
c7cb9fd
update twitter handler
amejiarosario Feb 12, 2020
6fbd551
docs: update twitter handler
amejiarosario Feb 12, 2020
bbfeb93
Merge pull request #41 from amejiarosario/fix-tw-handler
amejiarosario Feb 12, 2020
535afe6
subset/powerset problem
amejiarosario Mar 18, 2020
382872f
Merge branch 'master' of github.com:amejiarosario/dsa.js-data-structu…
amejiarosario Mar 18, 2020
bc51a7a
fix(book): fix table typos
amejiarosario Mar 19, 2020
2521d1e
docs: add new changelog and exercises
amejiarosario Mar 19, 2020
bbe69dd
Merge pull request #42 from amejiarosario/fix-table
amejiarosario Mar 19, 2020
a0e0fd8
feat(trie): implement trie data structure
amejiarosario Mar 22, 2020
524670e
simplify backtracking algorithm
amejiarosario Mar 22, 2020
19ff1f0
initial updates
Mar 23, 2020
9c36253
style(book): better wording for table
amejiarosario Mar 23, 2020
18b699e
bump version
amejiarosario Mar 23, 2020
a36179f
Merge pull request #45 from amejiarosario/v-tank/fix-suggestions
amejiarosario Mar 23, 2020
16005f3
feat(trie): remove method
amejiarosario Mar 22, 2020
eac045a
feat(linkedList): remove by node
amejiarosario Mar 27, 2020
3e787c6
feat(lru-cache): add new implementations
amejiarosario Mar 27, 2020
a81f6e1
feat(trie): remove method
amejiarosario Mar 22, 2020
e31cc62
feat(trie): feature complete
amejiarosario Mar 27, 2020
715cd95
build: add cz-changelog
amejiarosario Mar 29, 2020
e8c01e4
build(build): install husky and commitizen
amejiarosario Mar 29, 2020
efd4e29
:wrench: chore (build) Automate git commit messages
amejiarosario Mar 29, 2020
7da7a46
:wrench: chore (build) semantic release
amejiarosario Mar 29, 2020
03a420d
:wrench: chore (build):
amejiarosario Mar 29, 2020
fd8aa2e
:wrench: chore (ci): improve ci
amejiarosario Mar 30, 2020
696fc42
:wrench: chore (docs): simplify contributing
amejiarosario Mar 30, 2020
d671882
Merge pull request #46 from amejiarosario/feature/auto-changelog
amejiarosario Mar 30, 2020
9d25b28
:wrench: chore (ci): format tags
amejiarosario Mar 30, 2020
567c110
Merge pull request #47 from amejiarosario/automate-releases
amejiarosario Mar 30, 2020
965fbd1
Merge pull request #43 from amejiarosario/feature/trie
amejiarosario Mar 30, 2020
43041ad
:wrench: chore (build): automate changelog creation
amejiarosario Mar 30, 2020
93543c4
Merge pull request #48 from amejiarosario/automate-changelog-creation
amejiarosario Mar 30, 2020
e8ca8b7
Merge branch 'master' into feature/lru-cache
amejiarosario Mar 30, 2020
76854c6
Merge pull request #49 from amejiarosario/feature/lru-cache
amejiarosario Mar 30, 2020
bcc81b4
:bookmark: chore(release): 1.5.0
semantic-release-bot Mar 30, 2020
64a4a4f
chore(lab): add new exercises
amejiarosario May 6, 2020
874f3eb
:sparkles: feat (heap): Add Heap implementation (PriorityQueue) (#51)
amejiarosario May 8, 2020
a4b87e8
:wrench: chore (ci): adjust semantic-release (#52)
amejiarosario May 8, 2020
419fd11
chore(semantic-release): fix matchers
amejiarosario May 8, 2020
7279e5c
:wrench: chore (readme): update ci link
amejiarosario May 8, 2020
f4d0670
Merge pull request #53 from amejiarosario/chore/sematic-release
amejiarosario May 8, 2020
28da0e1
:bookmark: chore(release): 1.6.0
semantic-release-bot May 8, 2020
202ca9f
feat(heap): add min/max/median-heaps
amejiarosario May 16, 2020
1bb097d
chore(docs): add comments
amejiarosario May 16, 2020
7e19bdc
Merge branch 'master' into chore/sematic-release
amejiarosario May 16, 2020
517fec4
Merge pull request #54 from amejiarosario/chore/sematic-release
amejiarosario May 16, 2020
142c301
:bookmark: chore(release): 1.7.0
semantic-release-bot May 16, 2020
c253938
Better hash function
nuintun May 20, 2020
6974354
Merge pull request #56 from nuintun/patch-1
amejiarosario May 20, 2020
e13ff88
fix(hashmap): fix TextEncoder reference
amejiarosario May 20, 2020
a24c0d7
Merge pull request #57 from amejiarosario/hotfix/hashmap
amejiarosario May 20, 2020
8ea61ce
:bookmark: chore(release): 1.7.1
semantic-release-bot May 20, 2020
f6b47b5
fix(hashmap): improve methods documentation
amejiarosario May 23, 2020
924c9a7
feat(maps): implement clear method for hashMap and treeMap
amejiarosario May 23, 2020
2f24f57
fix(book/map): fix typo on maps space complexity
amejiarosario May 23, 2020
b5c7426
Merge pull request #58 from amejiarosario/feature/hashmap
amejiarosario May 23, 2020
7284619
:bookmark: chore(release): 1.8.0
semantic-release-bot May 23, 2020
3c4ef75
fix(book/maps): update time/space complexity values
amejiarosario May 24, 2020
0412eeb
Merge pull request #59 from amejiarosario/hotfix/hashmap
amejiarosario May 24, 2020
81c5f0d
:bookmark: chore(release): 1.8.1
semantic-release-bot May 24, 2020
0319b29
fix(book/hashset): update hashset space complexity
amejiarosario May 24, 2020
0344298
Merge pull request #61 from amejiarosario/hotfix/hashmap
amejiarosario May 24, 2020
aac8160
:bookmark: chore(release): 1.8.2
semantic-release-bot May 24, 2020
0be0176
fix(book/maps): update space complexity
amejiarosario May 24, 2020
63fd518
Merge pull request #62 from amejiarosario/hotfix/hashmap
amejiarosario May 24, 2020
f484075
:bookmark: chore(release): 1.8.3
semantic-release-bot May 24, 2020
288ff77
chore(book-quicksort): update time complexities
amejiarosario May 25, 2020
75f8d11
chore(benchmarks): new files for benchmarks
amejiarosario May 25, 2020
f3fe049
chore(book/sorting): fix bubble sort reference
amejiarosario May 25, 2020
9874647
Merge pull request #63 from amejiarosario/hotfix/sorting
amejiarosario May 26, 2020
1fa875f
feat(linkedList): takes iterables in the constructor
amejiarosario Jun 30, 2020
6af937f
feat(heap): remove by index
amejiarosario Jun 30, 2020
a93ac1b
chore(lab): add exercises
amejiarosario Jun 30, 2020
7e17577
Merge pull request #64 from amejiarosario/improvements
amejiarosario Jun 30, 2020
c7e5c31
:bookmark: chore(release): 1.9.0
semantic-release-bot Jun 30, 2020
3f99c56
chore(lab): add new exercises and fix comment:wq
amejiarosario Jul 9, 2020
8cabf9c
Merge pull request #65 from amejiarosario/new-exercises
amejiarosario Jul 10, 2020
bcaf819
feat(book/arrays): add exercises
amejiarosario Jul 28, 2020
6b33bc8
Merge pull request #66 from amejiarosario/feat/chapter-exercises
amejiarosario Jul 28, 2020
482bee0
:bookmark: chore(release): 1.10.0
semantic-release-bot Jul 28, 2020
cccadf8
chore: remove uxa
amejiarosario Aug 6, 2020
e5bd4b7
Merge branch 'master' of github.com:amejiarosario/dsa.js-data-structu…
amejiarosario Aug 19, 2020
3901188
chore(sorting): clean up variables
amejiarosario Aug 19, 2020
2fab838
add config test
amejiarosario Aug 20, 2020
4d75825
chore(jest): fix commands
amejiarosario Aug 20, 2020
b5a00dd
feat(book:array): add solutions for interview questions
amejiarosario Aug 20, 2020
996f7aa
chore(vscode): set colors
amejiarosario Aug 20, 2020
ca119f2
feat(book): add appendix D with interview question solutions
amejiarosario Aug 20, 2020
57960e2
fix(book): multiple broken links and bump epub version
amejiarosario Aug 21, 2020
5935b95
feat(book/array): add max subarray questions and solution
amejiarosario Aug 21, 2020
6ab8bc4
feat(book/array): add stock questions and solution
amejiarosario Aug 21, 2020
dbdef21
fix(book): workaround for c++ issue in asciidoc
amejiarosario Aug 22, 2020
9b356d9
Merge pull request #67 from amejiarosario/feat/add-exercises-solutions
amejiarosario Aug 22, 2020
e573929
:bookmark: chore(release): 1.11.0
semantic-release-bot Aug 22, 2020
f125511
chore(build): dockerfile
amejiarosario Aug 24, 2020
5466f28
Merge branch 'master' into chore/build-changes
amejiarosario Aug 24, 2020
738d6f3
chore(build): add Dockerfile
amejiarosario Aug 24, 2020
69f284d
chore(build): use jest config
amejiarosario Aug 24, 2020
db10bf7
chore(build): update ruby version
amejiarosario Aug 24, 2020
d3faa71
chore(build): remove deprecated dep
amejiarosario Aug 24, 2020
44fb6a2
Merge pull request #68 from amejiarosario/chore/build-changes
amejiarosario Aug 24, 2020
ca4bf45
feat(book/exercises): interview q&a for linked lists and stacks (#69)
amejiarosario Aug 26, 2020
06bd3f6
Revert "(book/exercises): interview q&a for linked lists and stacks (…
amejiarosario Aug 26, 2020
4cdfbf5
:bookmark: chore(release): 1.12.0
semantic-release-bot Aug 26, 2020
3bb86fd
feat(book/exercises): interview q&a for linked lists and stacks
amejiarosario Aug 26, 2020
3373f63
Merge pull request #71 from amejiarosario/revert-70-revert-69-feat/li…
amejiarosario Aug 26, 2020
263c9dc
:bookmark: chore(release): 1.13.0
semantic-release-bot Aug 26, 2020
04aa9db
feat(queue): add front, back and peek methods
amejiarosario Aug 28, 2020
9a88766
feat(book/queue): add solution for queue question
amejiarosario Aug 28, 2020
77d4596
feat(book/queue): add recent counter questions and solution
amejiarosario Aug 29, 2020
1f01baf
feat(book/questions): add where the interview questions have been seen
amejiarosario Aug 29, 2020
29b8dc8
chore(book): improve grammar
amejiarosario Aug 31, 2020
c1a8f8e
feat(book/questions): add examples
amejiarosario Aug 31, 2020
40d6b64
Merge pull request #72 from amejiarosario/feat/queue-interview-questions
amejiarosario Aug 31, 2020
e2f4af0
:bookmark: chore(release): 1.14.0
semantic-release-bot Aug 31, 2020
464417e
fix(book/solutions): fix missing solutions
amejiarosario Sep 1, 2020
068dd9c
feat(book/bt): add binary tree diameter problem
amejiarosario Sep 1, 2020
28346a4
feat(book/binary-tree): add right side view exercise and solution
amejiarosario Sep 2, 2020
bcb4c28
feat(BinaryTreeNode): add BinaryTreeNode.from
amejiarosario Sep 2, 2020
86201fb
chore(book/exercises): bst exercises after traversals
amejiarosario Sep 2, 2020
d07458d
Merge pull request #73 from amejiarosario/feat/tree-problems
amejiarosario Sep 2, 2020
1bfe522
:bookmark: chore(release): 1.15.0
semantic-release-bot Sep 2, 2020
d18186b
feat(book/hashmap): add exercises and solutions
amejiarosario Sep 3, 2020
2def4dc
Merge pull request #74 from amejiarosario/feat/hashmap-exercises
amejiarosario Sep 3, 2020
641b338
:bookmark: chore(release): 1.16.0
semantic-release-bot Sep 3, 2020
f40dc63
feat(book/set): add questions and solutions
amejiarosario Sep 4, 2020
75aa67a
chore(book/questions): improve function documentation
amejiarosario Sep 4, 2020
802e9d3
Merge pull request #75 from amejiarosario/feat/set-questions
amejiarosario Sep 4, 2020
8a92ba0
:bookmark: chore(release): 1.17.0
semantic-release-bot Sep 4, 2020
6a83cf8
feat(book/graph): add schedule exercise and solution
amejiarosario Sep 5, 2020
6b0e671
Merge pull request #76 from amejiarosario/feat/graph-questions
amejiarosario Sep 7, 2020
f248e42
:bookmark: chore(release): 1.18.0
semantic-release-bot Sep 7, 2020
3a2a24f
feat(book/pq): add exercise with pq and dijkstra
amejiarosario Sep 8, 2020
827177f
feat(heap): add error handling for heaps
amejiarosario Sep 8, 2020
edf8808
feat(pq): improves docs and usability of priority queues
amejiarosario Sep 8, 2020
c211644
Merge pull request #78 from amejiarosario/feat/priority-queue-exercise-2
amejiarosario Sep 8, 2020
65e302b
:bookmark: chore(release): 2.0.0
semantic-release-bot Sep 8, 2020
fdb8bd8
feat(book/sorting): add questions and solutions
amejiarosario Sep 11, 2020
cba73a1
update kindlegen
amejiarosario Sep 11, 2020
56e8823
Merge pull request #79 from amejiarosario/feat/sorting-questions
amejiarosario Sep 11, 2020
57b6eb9
:bookmark: chore(release): 2.1.0
semantic-release-bot Sep 11, 2020
b956708
chore(book): improves grammar
amejiarosario Sep 11, 2020
06d75d8
Merge pull request #80 from amejiarosario/feat/sorting-questions
amejiarosario Sep 12, 2020
69fa96b
chore: new exercise
amejiarosario Sep 22, 2020
2e77826
chore: placeholder for exercises
amejiarosario Sep 27, 2020
68c73d4
feat(book/big-o): add new chapter on how to determine big o from code.
amejiarosario Sep 29, 2020
dec47fb
Merge pull request #81 from amejiarosario/feat/revision-part-one
amejiarosario Sep 29, 2020
29f374a
:bookmark: chore(release): 2.2.0
semantic-release-bot Sep 29, 2020
1392938
Update introduction.asc
dahalnischal Oct 2, 2020
e679993
Merge pull request #83 from amejiarosario/feat/divide-and-conquer-exe…
amejiarosario Oct 2, 2020
4505eb6
fix(book): add introduction
amejiarosario Oct 2, 2020
db19ea9
Merge pull request #84 from amejiarosario/patch-2
amejiarosario Oct 2, 2020
b047c23
:bookmark: chore(release): 2.2.1
semantic-release-bot Oct 2, 2020
249de5d
feat(treeMap): get last entry (highest value)
amejiarosario Oct 3, 2020
3b079c0
Merge pull request #85 from amejiarosario/feat/tree-map-improvements
amejiarosario Oct 3, 2020
1b2d612
:bookmark: chore(release): 2.3.0
semantic-release-bot Oct 3, 2020
1287f29
Update CONTRIBUTING.md
PokhrelAnish Oct 4, 2020
9175b62
Update CONTRIBUTING.md
PokhrelAnish Oct 4, 2020
f5169b5
chore: add examples to contributing
amejiarosario Oct 4, 2020
8135449
chore: improves docs grammar
amejiarosario Oct 4, 2020
f7ebb75
Merge pull request #87 from amejiarosario/PokhrelAnish/master
amejiarosario Oct 4, 2020
04836cd
fix(book/array): improve examples and grammar
amejiarosario Oct 2, 2020
8c7b7be
feat(book/array): add array patterns for solving problems
amejiarosario Oct 17, 2020
8fa2746
feat(book/array): sliding window pattern
amejiarosario Oct 19, 2020
603afc2
Merge pull request #88 from amejiarosario/feat/arrays
amejiarosario Oct 19, 2020
273a9dc
:bookmark: chore(release): 2.4.0
semantic-release-bot Oct 19, 2020
4ba6fe0
chore(book/array): improve exercises
amejiarosario Oct 19, 2020
dc47b76
Merge pull request #89 from amejiarosario/feat/arrays
amejiarosario Oct 19, 2020
f7b8d59
feat(book/hashmap): add code examples and patterns
amejiarosario Oct 22, 2020
edf11d9
Merge pull request #91 from amejiarosario/feat/hashmap
amejiarosario Oct 22, 2020
0d7a14b
:bookmark: chore(release): 2.5.0
semantic-release-bot Oct 22, 2020
7659ac6
chore(docs): improve comments here and there
amejiarosario Oct 23, 2020
fcf3db6
fix(linkedlist): rename indexOf to getIndex to make it clearer
amejiarosario Oct 23, 2020
ba110e2
fix(linkedlist): refactored methods and improve book images and
amejiarosario Oct 23, 2020
2c8d383
Merge pull request #92 from amejiarosario/feat/linkedlist
amejiarosario Oct 23, 2020
0e12523
:bookmark: chore(release): 2.5.1
semantic-release-bot Oct 23, 2020
0f13f90
feat(book): add chapter numbers
amejiarosario Oct 25, 2020
8cd126d
feat(book/linkedlist): linked lists techniques and common patterns
amejiarosario Oct 27, 2020
571834a
fix(test): refactor tests
amejiarosario Oct 28, 2020
22972c3
Merge pull request #93 from amejiarosario/feat/linkedlist
amejiarosario Oct 28, 2020
bd9e1e4
:bookmark: chore(release): 2.6.0
semantic-release-bot Oct 28, 2020
c1cf57a
fix(book/set): split Set chapter into Hash Set and Tree Set for better
amejiarosario Oct 30, 2020
2b96f00
feat(book/linkedlist): add applications
amejiarosario Oct 30, 2020
6c39aae
chore(book): improve grammar of various chapters
amejiarosario Oct 30, 2020
b3167f9
feat(book): show companies asked questions
amejiarosario Oct 30, 2020
1fced28
Merge pull request #94 from amejiarosario/feat/set-improvements
amejiarosario Oct 30, 2020
b3039ab
:bookmark: chore(release): 2.7.0
semantic-release-bot Oct 30, 2020
38a4178
fix(book): update company names
amejiarosario Dec 2, 2020
d70aec2
Merge pull request #95 from amejiarosario/fix/update-companies
amejiarosario Dec 2, 2020
96cc1cb
:bookmark: chore(release): 2.7.1
semantic-release-bot Dec 2, 2020
b2a82c0
Rename fibonacci-dynamic-programming (fix typo)
knoxknox Dec 16, 2020
ded0a70
fix(book): Rename fibonacci-dynamic-programming
knoxknox Dec 16, 2020
5b0d703
Merge pull request #97 from amejiarosario/fix/typo
amejiarosario Dec 17, 2020
7dd9df8
Merge pull request #96 from knoxknox/fix-naming
amejiarosario Dec 17, 2020
65b6edd
:bookmark: chore(release): 2.7.2
semantic-release-bot Dec 17, 2020
c137930
fix(book/hashmap): exercise example and add tests
amejiarosario Dec 22, 2020
c7c7947
fix(book/graph): add comments for runtimes using hashset implementations
amejiarosario Dec 22, 2020
1d75301
fix(book/bst): better wording
amejiarosario Dec 22, 2020
436848d
fixes format
amejiarosario Dec 22, 2020
4350fca
Merge pull request #98 from amejiarosario/fix/sam-findings
amejiarosario Dec 22, 2020
3c32d0e
:bookmark: chore(release): 2.7.3
semantic-release-bot Dec 22, 2020
6b9a4e8
fix(bst): some typos on the code
amejiarosario Jan 9, 2021
2090ea2
:bookmark: chore(release): 2.7.4
semantic-release-bot Jan 9, 2021
1812da7
Update README.md
amejiarosario Feb 11, 2021
cec3b04
chore(graph): fix typo
amejiarosario May 18, 2021
d350da8
fix(bst): on duplicates values the same node is returned
amejiarosario May 24, 2021
1c05026
Merge pull request #100 from amejiarosario/fix/nadhem-findings
amejiarosario May 24, 2021
03bafbb
:bookmark: chore(release): 2.7.5
semantic-release-bot May 24, 2021
e03875d
Update tree-intro.asc
eraygundogmus Sep 13, 2021
9243b24
Merge pull request #104 from eraygundogmus/patch-1
amejiarosario Sep 23, 2021
5ac3cd9
Update quick-sort.asc
ivanji Nov 9, 2021
02d9f48
Merge pull request #107 from ivanji/patch-2
amejiarosario Nov 14, 2021
ccfcfe6
fix(graph): minor typo in bfs code documentation
onethirtyfive Nov 27, 2021
438e8dd
Merge pull request #111 from onethirtyfive/fix-graph-bfs-documentation
amejiarosario Nov 30, 2021
ae41553
:bookmark: chore(release): 2.7.6
semantic-release-bot Nov 30, 2021
5b49d8a
fix(runtimes/02-binary-search):fixes binary search iterative
gabrielastelescu May 19, 2022
cde6e8a
Update heap.js
Balaji1202 May 29, 2022
c9249d3
chore(binary-search): consolidate test for multiple implementations
amejiarosario Dec 10, 2022
41205d6
Merge pull request #113 from gabrielastelescu/binary-search-iterative
amejiarosario Dec 10, 2022
c20acfb
Merge pull request #114 from Balaji1202/patch-1
amejiarosario Dec 20, 2022
fefb06a
Fix return of unshift method
caiquecastro Dec 26, 2022
844644d
Merge pull request #117 from caiquecastro/patch-1
amejiarosario Dec 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 42 additions & 35 deletions book/content/part01/algorithms-analysis.asc

Large diffs are not rendered by default.

78 changes: 41 additions & 37 deletions book/content/part01/big-o-examples.asc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ endif::[]

=== Big O examples

There are many kinds of algorithms. Most of them fall into one of the eight time complexities that we are going to explore in this chapter.
There are many kinds of algorithms. Most of them fall into one of the eight-time complexities that we will explore in this chapter.

.Eight Running Time Complexities You Should Know
- Constant time: _O(1)_
Expand All @@ -22,9 +22,10 @@ We are going to provide examples for each one of them.
Before we dive in, here’s a plot with all of them.

.CPU operations vs. Algorithm runtime as the input size grows
image::image5.png[CPU time needed vs. Algorithm runtime as the input size increases]
// image::image5.png[CPU time needed vs. Algorithm runtime as the input size increases]
image::big-o-running-time-complexity.png[CPU time needed vs. Algorithm runtime as the input size increases]

The above chart shows how the running time of an algorithm is related to the amount of work the CPU has to perform. As you can see O(1) and O(log n) are very scalable. However, O(n^2^) and worst can make your computer run for years [big]#😵# on large datasets. We are going to give some examples so you can identify each one.
The above chart shows how the algorithm's running time is related to the work the CPU has to perform. As you can see, O(1) and O(log n) is very scalable. However, O(n^2^) and worst can convert your CPU into a furnace 🔥 for massive inputs.

[[constant]]
==== Constant
Expand Down Expand Up @@ -53,13 +54,13 @@ As you can see in both examples (array and linked list), if the input is a colle
==== Logarithmic
(((Logarithmic)))
(((Runtime, Logarithmic)))
Represented in Big O notation as *O(log n)*, when an algorithm has this running time it means that as the size of the input grows the number of operations grows very slowly. Logarithmic algorithms are very scalable. One example is the *binary search*.
Represented in Big O notation as *O(log n)*, when an algorithm has this running time, it means that as the input size grows, the number of operations grows very slowly. Logarithmic algorithms are very scalable. One example is the *binary search*.
indexterm:[Runtime, Logarithmic]

[[logarithmic-example]]
===== Searching on a sorted array

The binary search only works for sorted lists. It starts searching for an element on the middle of the array and then it moves to the right or left depending if the value you are looking for is bigger or smaller.
The binary search only works for sorted lists. It starts searching for an element in the middle of the array, and then it moves to the right or left depending on if the value you are looking for is bigger or smaller.

// image:image7.png[image,width=528,height=437]

Expand All @@ -68,15 +69,15 @@ The binary search only works for sorted lists. It starts searching for an elemen
include::{codedir}/runtimes/02-binary-search.js[tag=binarySearchRecursive]
----

This binary search implementation is a recursive algorithm, which means that the function `binarySearchRecursive` calls itself multiple times until the solution is found. The binary search splits the array in half every time.
This binary search implementation is a recursive algorithm, which means that the function `binarySearchRecursive` calls itself multiple times until the program finds a solution. The binary search splits the array in half every time.

Finding the runtime of recursive algorithms is not very obvious sometimes. It requires some tools like recursion trees or the https://adrianmejia.com/blog/2018/04/24/analysis-of-recursive-algorithms/[Master Theorem]. The `binarySearch` divides the input in half each time. As a rule of thumb, when you have an algorithm that divides the data in half on each call you are most likely in front of a logarithmic runtime: _O(log n)_.
Finding the runtime of recursive algorithms is not very obvious sometimes. It requires some tools like recursion trees or the https://adrianmejia.com/blog/2018/04/24/analysis-of-recursive-algorithms/[Master Theorem]. The `binarySearch` divides the input in half each time. As a rule of thumb, when you have an algorithm that divides the data in half on each call, you are most likely in front of a logarithmic runtime: _O(log n)_.

[[linear]]
==== Linear
(((Linear)))
(((Runtime, Linear)))
Linear algorithms are one of the most common runtimes. It’s represented as *O(n)*. Usually, an algorithm has a linear running time when it iterates over all the elements in the input.
Linear algorithms are one of the most common runtimes. Their Big O representation is *O(n)*. Usually, an algorithm has a linear running time when it visits every input element a fixed number of times.

[[linear-example]]
===== Finding duplicates in an array using a map
Expand All @@ -91,19 +92,19 @@ include::{codedir}/runtimes/03-has-duplicates.js[tag=hasDuplicates]
----

.`hasDuplicates` has multiple scenarios:
* *Best-case scenario*: first two elements are duplicates. It only has to visit two elements.
* *Best-case scenario*: the first two elements are duplicates. It only has to visit two elements and return.
* *Worst-case scenario*: no duplicates or duplicates are the last two. In either case, it has to visit every item in the array.
* *Average-case scenario*: duplicates are somewhere in the middle of the collection. Only half of the array will be visited.
* *Average-case scenario*: duplicates are somewhere in the middle of the collection.

As we learned before, the big O cares about the worst-case scenario, where we would have to visit every element on the array. So, we have an *O(n)* runtime.

Space complexity is also *O(n)* since we are using an auxiliary data structure. We have a map that in the worst case (no duplicates) it will hold every word.
Space complexity is also *O(n)* since we are using an auxiliary data structure. We have a map that, in the worst case (no duplicates), it will hold every word.

[[linearithmic]]
==== Linearithmic
(((Linearithmic)))
(((Runtime, Linearithmic)))
An algorithm with a linearithmic runtime is represented as _O(n log n)_. This one is important because it is the best runtime for sorting! Let’s see the merge-sort.
You can represent linearithmic algorithms as _O(n log n)_. This one is important because it is the best runtime for sorting! Let’s see the merge-sort.

[[linearithmic-example]]
===== Sorting elements in an array
Expand All @@ -117,7 +118,7 @@ The ((Merge Sort)), like its name indicates, has two functions merge and sort. L
----
include::{codedir}/algorithms/sorting/merge-sort.js[tag=splitSort]
----
<1> If the array only has two elements we can sort them manually.
<1> If the array only has two elements, we can sort them manually.
<2> We divide the array into two halves.
<3> Merge the two parts recursively with the `merge` function explained below

Expand All @@ -134,15 +135,15 @@ The merge function combines two sorted arrays in ascending order. Let’s say th
.Mergesort visualization. Shows the split, sort and merge steps
image::image11.png[Mergesort visualization,width=500,height=600]

How do we obtain the running time of the merge sort algorithm? The mergesort divides the array in half each time in the split phase, _log n_, and the merge function join each splits, _n_. The total work is *O(n log n)*. There are more formal ways to reach this runtime, like using the https://adrianmejia.com/blog/2018/04/24/analysis-of-recursive-algorithms/[Master Method] and https://www.cs.cornell.edu/courses/cs3110/2012sp/lectures/lec20-master/lec20.html[recursion trees].
How do we obtain the running time of the merge sort algorithm? The merge-sort divides the array in half each time in the split phase, _log n_, and the merge function join each splits, _n_. The total work is *O(n log n)*. There are more formal ways to reach this runtime, like using the https://adrianmejia.com/blog/2018/04/24/analysis-of-recursive-algorithms/[Master Method] and https://www.cs.cornell.edu/courses/cs3110/2012sp/lectures/lec20-master/lec20.html[recursion trees].

[[quadratic]]
==== Quadratic
(((Quadratic)))
(((Runtime, Quadratic)))
Running times that are quadratic, O(n^2^), are the ones to watch out for. They usually don’t scale well when they have a large amount of data to process.
Quadratic running times, O(n^2^), are the ones to watch out for. They usually don’t scale well when they have a large amount of data to process.

Usually they have double-nested loops, where each one visits all or most elements in the input. One example of this is a naïve implementation to find duplicate words on an array.
Usually, they have double-nested loops, where each one visits all or most elements in the input. One example of this is a naïve implementation to find duplicate words on an array.

[[quadratic-example]]
===== Finding duplicates in an array (naïve approach)
Expand All @@ -165,34 +166,37 @@ Let’s say you want to find a duplicated middle name in a phone directory book
==== Cubic
(((Cubic)))
(((Runtime, Cubic)))
Cubic *O(n^3^)* and higher polynomial functions usually involve many nested loops. An example of a cubic algorithm is a multi-variable equation solver (using brute force):
Cubic *O(n^3^)* and higher polynomial functions usually involve many nested loops. An example of a cubic algorithm is a multi-variable equation solver (using brute force) or finding three elements on an array that add up to a given number.

[[cubic-example]]
===== Solving a multi-variable equation
===== 3 Sum

Lets say we want to find the solution for this multi-variable equation:
Let's say you want to find 3 items in an array that add up to a target number. One brute force solution would be to visit every possible combination of 3 elements and add them up to see if they are equal to target.

_3x + 9y + 8z = 79_

A naïve approach to solve this will be the following program:

//image:image13.png[image,width=528,height=448]

.Naïve implementation of multi-variable equation solver
[source, javascript]
----
include::{codedir}/runtimes/06-multi-variable-equation-solver.js[tag=findXYZ]
function threeSum(nums, target = 0) {
const ans = [];

for(let i = 0; i < nums.length -2; i++)
for(let j = i + 1; j < nums.length - 1; j++)
for(let k = j + 1; k < nums.length; k++)
if (nums[i] + nums[j] + nums[k] === target)
ans.push([nums[i], nums[j], nums[k]]);

return ans;
}
----

WARNING: This is just an example, there are better ways to solve multi-variable equations.
As you can see, three nested loops usually translate to O(n^3^). If we had four nested loops (4sum), it would be O(n^4^) and so on. A runtime in the form of _O(n^c^)_, where _c > 1_, we refer to this as a *polynomial runtime*.

As you can see three nested loops usually translates to O(n^3^). If you have a four variable equation and four nested loops it would be O(n^4^) and so on. When we have a runtime in the form of _O(n^c^)_, where _c > 1_, we refer to this as a *polynomial runtime*.
NOTE: You can improve the runtime of 3sum from _O(n^3^)_ to _O(n^2^)_, if we sort items first and then use one loop and two pointers to find the solutions.

[[exponential]]
==== Exponential
(((Exponential)))
(((Runtime, Exponential)))
Exponential runtimes, O(2^n^), means that every time the input grows by one the number of operations doubles. Exponential programs are only usable for a tiny number of elements (<100) otherwise it might not finish in your lifetime. [big]#💀#
Exponential runtimes, _O(2^n^)_, means that every time the input grows by one, the number of operations doubles. Exponential programs are only usable for a tiny number of elements (<100); otherwise, it might not finish in your lifetime. [big]#💀#

Let’s do an example.

Expand All @@ -209,21 +213,21 @@ Finding all distinct subsets of a given set can be implemented as follows:
include::{codedir}/runtimes/07-sub-sets.js[tag=snippet]
----
<1> Base case is empty element.
<2> For each element from the input append it to the results array.
<2> For each element from the input, append it to the results array.
<3> The new results array will be what it was before + the duplicated with the appended element.

//.The way this algorithm generates all subsets is:
//1. The base case is an empty element (line 13). E.g. ['']
//2. For each element from the input append it to the results array (line 16)
//2. For each element from the input, append it to the results array (line 16)
//3. The new results array will be what it was before + the duplicated with the appended element (line 17)

Every time the input grows by one the resulting array doubles. That’s why it has an *O(2^n^)*.
Every time the input grows by one, the resulting array doubles. That’s why it has an *O(2^n^)*.

[[factorial]]
==== Factorial
(((Factorial)))
(((Runtime, Factorial)))
Factorial runtime, O(n!), is not scalable at all. Even with input sizes of ~10 elements, it will take a couple of seconds to compute. It’s that slow! [big]*🍯🐝*
The factorial runtime, `O(n!)`, is not scalable at all. Even with input sizes of ~10 elements, it will take a couple of seconds to compute. It’s that slow! [big]*🍯🐝*

.Factorial
****
Expand All @@ -240,7 +244,7 @@ A factorial is the multiplication of all the numbers less than itself down to 1.
===== Getting all permutations of a word
(((Permutations)))
(((Words permutations)))
One classic example of an _O(n!)_ algorithm is finding all the different words that can be formed with a given set of letters.
One classic example of an _O(n!)_ algorithm is finding all the different words formed with a given set of letters.

.Word's permutations
// image:image15.png[image,width=528,height=377]
Expand All @@ -251,7 +255,7 @@ include::{codedir}/runtimes/08-permutations.js[tag=snippet]

As you can see in the `getPermutations` function, the resulting array is the factorial of the word length.

Factorial starts very slow, and quickly becomes uncontrollable. A word size of just 11 characters would take a couple of hours in most computers!
Factorial starts very slow and quickly becomes unmanageable. A word size of just 11 characters would take a couple of hours in most computers!
[big]*🤯*

==== Summary
Expand All @@ -265,7 +269,7 @@ We went through 8 of the most common time complexities and provided examples for
|===
|Big O Notation
|Name
|Example(s)
| example (s)

|O(1)
|<>
Expand Down
Loading