├── .gitignore
├── README.md
└── TechPrep - Part I Foundations
└── Javascript
└── V1.0
├── Arrays
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── arrays-L0-SLN.js
│ │ ├── arrays-L0.js
│ │ ├── arrays-L1-SLN.js
│ │ └── arrays-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── arrayTests-L0.js
│ │ └── arrayTests-L1.js
├── README-L0.html
├── README-L0.md
├── README-L1.html
├── README-L1.md
├── README.html
└── README.md
├── Binary
├── .gitignore
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── binary-L0-SLN.js
│ │ ├── binary-L0.js
│ │ ├── binary-L1-SLN.js
│ │ └── binary-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── binaryTests-L0.js
│ │ └── binaryTests-L1.js
├── README-L0.html
├── README-L0.md
├── README-L1.html
├── README-L1.md
├── README.html
├── README.md
└── questions.js
├── Complexity
└── Intro to Complexity Analysis (new).pdf
├── Graphs
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── graphs-L0-SLN.js
│ │ ├── graphs-L0.js
│ │ ├── graphs-L1-SLN.js
│ │ └── graphs-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── graphTests-L0.js
│ │ └── graphTests-L1.js
├── README-L0.md
├── README-L1.md
├── README.md
└── assets
│ ├── graph1.png
│ ├── graph2.png
│ ├── graph3.png
│ ├── graph4.png
│ ├── graph_ex1.png
│ ├── graph_ex2.png
│ ├── graph_ex3.png
│ ├── graph_ex4.png
│ ├── graph_ex5.png
│ └── graph_ex6.png
├── HashTables
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── hashtables-L0-SLN.js
│ │ ├── hashtables-L0.js
│ │ ├── hashtables-L1-SLN.js
│ │ └── hashtables-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── hashTableTests-L0.js
│ │ └── hashTableTests-L1.js
├── README-L0.md
├── README-L1.md
├── README.md
└── assets
│ └── HashTable-Wikipedia.png
├── LinkedLists
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── linkedLists-L0-SLN.js
│ │ ├── linkedLists-L0.js
│ │ ├── linkedLists-L1-SLN.js
│ │ ├── linkedLists-L1.js
│ │ ├── linkedLists-L2-SLN.js
│ │ ├── linkedLists-L2.js
│ │ ├── linkedLists-L3-SLN.js
│ │ └── linkedLists-L3.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ ├── testRunner2-SLN.html
│ ├── testRunner2.html
│ ├── testRunner3-SLN.html
│ ├── testRunner3.html
│ └── tests
│ │ ├── linkedListTests-L0.js
│ │ ├── linkedListTests-L1.js
│ │ ├── linkedListTests-L2.js
│ │ └── linkedListTests-L3.js
├── README-L0.html
├── README-L0.md
├── README-L1.html
├── README-L1.md
├── README-L2.html
├── README-L2.md
├── README-L3.md
├── README.html
└── README.md
├── Queues
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── consoleHook
│ │ │ └── consoleHook.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── queues-L0-SLN.js
│ │ ├── queues-L0.js
│ │ ├── queues-L1-SLN.js
│ │ └── queues-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── queueTests-L0.js
│ │ └── queueTests-L1.js
├── README-L0.md
├── README-L1.md
└── README.md
├── Recursion
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── consoleHook
│ │ │ └── consoleHook.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── recursion-L0-SLN.js
│ │ ├── recursion-L0.js
│ │ ├── recursion-L1-SLN.js
│ │ └── recursion-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── recursionTests-L0.js
│ │ └── recursionTests-L1.js
├── README-L0.html
├── README-L0.md
├── README-L1.html
├── README-L1.md
├── README.html
└── README.md
├── Searching
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── consoleHook
│ │ │ └── consoleHook.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── searching-L0-SLN.js
│ │ ├── searching-L0.js
│ │ ├── searching-L1-SLN.js
│ │ └── searching-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── searchingTests-L0.js
│ │ └── searchingTests-L1.js
├── README-L0.md
├── README-L1.md
└── README.md
├── Sets
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── consoleHook
│ │ │ └── consoleHook.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── sets-L0-SLN.js
│ │ ├── sets-L0.js
│ │ ├── sets-L1-SLN.js
│ │ └── sets-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── setTests-L0.js
│ │ └── setTests-L1.js
├── README-L0.md
├── README-L1.md
└── README.md
├── Sorting
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── consoleHook
│ │ │ └── consoleHook.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── sorting-L0-SLN.js
│ │ ├── sorting-L0.js
│ │ ├── sorting-L1-SLN.js
│ │ └── sorting-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── sortingTests-L0.js
│ │ └── sortingTests-L1.js
├── README-L0.md
├── README-L1.md
├── README.md
└── assets
│ ├── bubbleSort.png
│ ├── insertionSort.png
│ ├── mergeSort.gif
│ ├── selectionSort.png
│ ├── sortComparison.png
│ └── stableVsUnstableSorts.png
├── Stacks
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── consoleHook
│ │ │ └── consoleHook.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── stacks-L0-SLN.js
│ │ ├── stacks-L0.js
│ │ ├── stacks-L1-SLN.js
│ │ └── stacks-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── stackTests-L0.js
│ │ └── stackTests-L1.js
├── README-L0.md
├── README-L1.md
└── README.md
├── Trees
├── ES6
│ ├── lib
│ │ ├── chai
│ │ │ └── chai-4.1.2.js
│ │ ├── consoleHook
│ │ │ └── consoleHook.js
│ │ ├── jquery
│ │ │ └── jquery-3.3.1.js
│ │ ├── mocha
│ │ │ ├── mocha.css
│ │ │ └── mocha.js
│ │ ├── require
│ │ │ └── require.js
│ │ └── underscore
│ │ │ └── underscore-1.8.3.js
│ ├── src
│ │ ├── trees-L0-SLN.js
│ │ ├── trees-L0.js
│ │ ├── trees-L1-SLN.js
│ │ └── trees-L1.js
│ ├── testRunner0-SLN.html
│ ├── testRunner0.html
│ ├── testRunner1-SLN.html
│ ├── testRunner1.html
│ └── tests
│ │ ├── treeTests-L0.js
│ │ └── treeTests-L1.js
├── README-L0.md
├── README-L1.md
├── README.md
└── assets
│ └── family_tree.jpeg
└── Vectors
├── ES6
├── lib
│ ├── chai
│ │ └── chai-4.1.2.js
│ ├── consoleHook
│ │ └── consoleHook.js
│ ├── jquery
│ │ └── jquery-3.3.1.js
│ ├── mocha
│ │ ├── mocha.css
│ │ └── mocha.js
│ ├── require
│ │ └── require.js
│ └── underscore
│ │ └── underscore-1.8.3.js
├── src
│ ├── vectors-L0-SLN.js
│ ├── vectors-L0.js
│ ├── vectors-L1-SLN.js
│ ├── vectors-L1.js
│ ├── vectors-L2-SLN.js
│ ├── vectors-L2.js
│ ├── vectors-L3-SLN.js
│ └── vectors-L3.js
├── testRunner0-SLN.html
├── testRunner0.html
├── testRunner1-SLN.html
├── testRunner1.html
├── testRunner2-SLN.html
├── testRunner2.html
├── testRunner3-SLN.html
├── testRunner3.html
└── tests
│ ├── vectorTests-L0.js
│ ├── vectorTests-L1.js
│ ├── vectorTests-L2.js
│ └── vectorTests-L3.js
├── README-L0.html
├── README-L0.md
├── README-L1.html
├── README-L1.md
├── README-L2.html
├── README-L2.md
├── README-L3.html
├── README-L3.md
├── README.html
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Node template
3 | # Logs
4 | logs
5 | *.log
6 | npm-debug.log*
7 | yarn-debug.log*
8 | yarn-error.log*
9 |
10 | # Runtime data
11 | pids
12 | *.pid
13 | *.seed
14 | *.pid.lock
15 |
16 | # Directory for instrumented libs generated by jscoverage/JSCover
17 | lib-cov
18 |
19 | # Coverage directory used by tools like istanbul
20 | coverage
21 |
22 | # nyc test coverage
23 | .nyc_output
24 |
25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26 | .grunt
27 |
28 | # Bower dependency directory (https://bower.io/)
29 | bower_components
30 |
31 | # node-waf configuration
32 | .lock-wscript
33 |
34 | # Compiled binary addons (https://nodejs.org/api/addons.html)
35 | build/Release
36 |
37 | # Dependency directories
38 | node_modules/
39 | jspm_packages/
40 |
41 | # Typescript v1 declaration files
42 | typings/
43 |
44 | # Optional npm cache directory
45 | .npm
46 |
47 | # Optional eslint cache
48 | .eslintcache
49 |
50 | # Optional REPL history
51 | .node_repl_history
52 |
53 | # Output of 'npm pack'
54 | *.tgz
55 |
56 | # Yarn Integrity file
57 | .yarn-integrity
58 |
59 | # dotenv environment variables file
60 | .env
61 |
62 | # next.js build output
63 | .next
64 |
65 |
66 | # Solution Files
67 | #*SLN.js
68 | #*SLN.html
69 |
70 | # Jetbrains Files
71 | .idea
72 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Welcome to Algorithm Academy
2 |
3 | It started before the summer of 2016. A couple friends were experiencing difficulty interviewing and
4 | one was soon to interview for a senior dev role at Uber, and another as a developer at facebook and
5 | were trying to figure out why.
6 |
7 | I started http://algoacad.me as a way to personally mentor people one-on-one through the interview
8 | process and http://bootcamped.com to mentor groups. The process is the same, and the material is
9 | the same. The Data Structures portion contained in this repo is how I walk people through problem
10 | solving and detect their weaknesses and help overcome them. It's not designed for the primary
11 | purpose of learning (alghough it has that characteristic), it is designed so I can figure out what
12 | parts of the technical interview need to be fixed. As such it might be more thorough than you are
13 | used to.
14 |
15 | I will continue to mentor people and use the material here. I initially wanted it to be open source
16 | but wanted to test it first.
17 |
18 | This was designed to be paired with mentoring, not necessary as a self-learning machanism.
19 |
20 | When I mentor people, I typically follow a schedule that looks resembles the following (for Part 1):
21 |
22 | ---
23 | ```
24 | Week 1
25 | Day 1:
26 | * Introductions
27 | * Expectations
28 | * Algorithms
29 | * Complexity
30 | * Looping & Array Warmpups
31 |
32 | Day 2:
33 | * Arrays & Dynamic Arrays I
34 | * Dyanamic Arrays II
35 |
36 | Day 3:
37 | * Review
38 | * Abstractions Module
39 | * Exceptions & Errors Module
40 | * Dynamic Array III
41 |
42 | Day 4:
43 | * Review
44 | * Linked List Warmup
45 | * Linked Lists I
46 | * Linked Lists II
47 |
48 | Day 5: Review
49 | * Review
50 | * Doubly Linked List Warmp
51 | * Linked Lists III
52 | * Linked Lists IV - Challenges
53 |
54 |
55 | Week 2
56 | Day 1:
57 | * Review
58 | * Stacks
59 | * Queues
60 |
61 | Day 2:
62 | * Review
63 | * Stacks & Queues Challenges
64 |
65 | Day 3:
66 | * Review
67 | * Sets I
68 | * Sets II
69 |
70 | Day 4:
71 | * Review
72 | * Hash Tables I
73 |
74 | Day 5:
75 | * Review
76 | * Hash Tables II
77 |
78 | Week 3
79 | Day 1:
80 | * Review
81 | * Recursion I
82 |
83 | Day 2:
84 | * Review
85 | * Recursion II
86 |
87 | Day 3:
88 | * Review
89 | * Sorting I
90 |
91 | Day 4:
92 | * Review
93 | * Sorting II
94 |
95 | Day 5:
96 | * Review
97 | * Searching I
98 |
99 | Week 4
100 | Day 1:
101 | * Review
102 | * Trees
103 |
104 | Day 2:
105 | * Review
106 | * Binary Search Trees I
107 |
108 | Day 3:
109 | * Review
110 | * Binary Search Trees II
111 |
112 | Day 4:
113 | * Review
114 | * Graphs I
115 |
116 | Day 5:
117 | * Review
118 | * Graphs II
119 | ```
120 |
121 | The progression assumes that comfort with arrays will lead to comfort with Dynamic
122 | Arrays because of similar coding dynamics, and the comfort with dynamic arrays and Linked
123 | Lists will lead to comfort with HashTables because either can be used as the storage
124 | mechanism, and so on.
125 |
126 | My audience was mostly Javascript programmers but I also mentored programmers with a Java,
127 | Python, and C# background and everything worked fine. The only difference is the automated
128 | tests and reference code use Javascript.
129 |
130 | I open source this because my mentoring is not about algorithms, anyway. As someone who has
131 | overseen 200 person developer teams, CEO'd and CTO'd, I have a knack for what we're looking
132 | for when hiring. When I mentor its more of a troubleshooting exercise to figure out where in
133 | the process from writing the resume, to salary negotiation, the problem is and fix it. Everyone
134 | grinded LeetCode but some still had struggles there or with systems design. This is the component
135 | that focused on algorithms.
136 |
137 |
138 |
139 |
140 | I hope you find this to be helpful during your preparation for interviews.
141 |
142 |
143 | [My LinkedIn](https://linkedin.com/in/bullockshawn)
144 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Arrays/ES6/lib/mocha/mocha.css:
--------------------------------------------------------------------------------
1 | @charset "utf-8";
2 |
3 | body {
4 | font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
5 | padding: 60px 50px;
6 | }
7 |
8 | #mocha ul, #mocha li {
9 | margin: 0;
10 | padding: 0;
11 | }
12 |
13 | #mocha ul {
14 | list-style: none;
15 | }
16 |
17 | #mocha h1, #mocha h2 {
18 | margin: 0;
19 | }
20 |
21 | #mocha h1 {
22 | margin-top: 15px;
23 | font-size: 1em;
24 | font-weight: 200;
25 | }
26 |
27 | #mocha h1 a {
28 | text-decoration: none;
29 | color: inherit;
30 | }
31 |
32 | #mocha h1 a:hover {
33 | text-decoration: underline;
34 | }
35 |
36 | #mocha .suite .suite h1 {
37 | margin-top: 0;
38 | font-size: .8em;
39 | }
40 |
41 | .hidden {
42 | display: none;
43 | }
44 |
45 | #mocha h2 {
46 | font-size: 12px;
47 | font-weight: normal;
48 | cursor: pointer;
49 | }
50 |
51 | #mocha .suite {
52 | margin-left: 15px;
53 | }
54 |
55 | #mocha .test {
56 | margin-left: 15px;
57 | overflow: hidden;
58 | }
59 |
60 | #mocha .test.pending:hover h2::after {
61 | content: '(pending)';
62 | font-family: arial;
63 | }
64 |
65 | #mocha .test.pass.medium .duration {
66 | background: #C09853;
67 | }
68 |
69 | #mocha .test.pass.slow .duration {
70 | background: #B94A48;
71 | }
72 |
73 | #mocha .test.pass::before {
74 | content: '✓';
75 | font-size: 12px;
76 | display: block;
77 | float: left;
78 | margin-right: 5px;
79 | color: #00d6b2;
80 | }
81 |
82 | #mocha .test.pass .duration {
83 | font-size: 9px;
84 | margin-left: 5px;
85 | padding: 2px 5px;
86 | color: white;
87 | -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
88 | -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
89 | box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
90 | -webkit-border-radius: 5px;
91 | -moz-border-radius: 5px;
92 | -ms-border-radius: 5px;
93 | -o-border-radius: 5px;
94 | border-radius: 5px;
95 | }
96 |
97 | #mocha .test.pass.fast .duration {
98 | display: none;
99 | }
100 |
101 | #mocha .test.pending {
102 | color: #0b97c4;
103 | }
104 |
105 | #mocha .test.pending::before {
106 | content: '◦';
107 | color: #0b97c4;
108 | }
109 |
110 | #mocha .test.fail {
111 | color: #c00;
112 | }
113 |
114 | #mocha .test.fail pre {
115 | color: black;
116 | }
117 |
118 | #mocha .test.fail::before {
119 | content: '✖';
120 | font-size: 12px;
121 | display: block;
122 | float: left;
123 | margin-right: 5px;
124 | color: #c00;
125 | }
126 |
127 | #mocha .test pre.error {
128 | color: #c00;
129 | max-height: 300px;
130 | overflow: auto;
131 | }
132 |
133 | #mocha .test pre {
134 | display: block;
135 | float: left;
136 | clear: left;
137 | font: 12px/1.5 monaco, monospace;
138 | margin: 5px;
139 | padding: 15px;
140 | border: 1px solid #eee;
141 | border-bottom-color: #ddd;
142 | -webkit-border-radius: 3px;
143 | -webkit-box-shadow: 0 1px 3px #eee;
144 | -moz-border-radius: 3px;
145 | -moz-box-shadow: 0 1px 3px #eee;
146 | }
147 |
148 | #mocha .test h2 {
149 | position: relative;
150 | }
151 |
152 | #mocha .test a.replay {
153 | position: absolute;
154 | top: 3px;
155 | right: 0;
156 | text-decoration: none;
157 | vertical-align: middle;
158 | display: block;
159 | width: 15px;
160 | height: 15px;
161 | line-height: 15px;
162 | text-align: center;
163 | background: #eee;
164 | font-size: 15px;
165 | -moz-border-radius: 15px;
166 | border-radius: 15px;
167 | -webkit-transition: opacity 200ms;
168 | -moz-transition: opacity 200ms;
169 | transition: opacity 200ms;
170 | opacity: 0.3;
171 | color: #888;
172 | }
173 |
174 | #mocha .test:hover a.replay {
175 | opacity: 1;
176 | }
177 |
178 | #mocha-report.pass .test.fail {
179 | display: none;
180 | }
181 |
182 | #mocha-report.fail .test.pass {
183 | display: none;
184 | }
185 |
186 | #mocha-error {
187 | color: #c00;
188 | font-size: 1.5 em;
189 | font-weight: 100;
190 | letter-spacing: 1px;
191 | }
192 |
193 | #mocha-stats {
194 | position: fixed;
195 | top: 15px;
196 | right: 10px;
197 | font-size: 12px;
198 | margin: 0;
199 | color: #888;
200 | }
201 |
202 | #mocha-stats .progress {
203 | float: right;
204 | padding-top: 0;
205 | }
206 |
207 | #mocha-stats em {
208 | color: black;
209 | }
210 |
211 | #mocha-stats a {
212 | text-decoration: none;
213 | color: inherit;
214 | }
215 |
216 | #mocha-stats a:hover {
217 | border-bottom: 1px solid #eee;
218 | }
219 |
220 | #mocha-stats li {
221 | display: inline-block;
222 | margin: 0 5px;
223 | list-style: none;
224 | padding-top: 11px;
225 | }
226 |
227 | #mocha-stats canvas {
228 | width: 40px;
229 | height: 40px;
230 | }
231 |
232 | code .comment { color: #ddd }
233 | code .init { color: #2F6FAD }
234 | code .string { color: #5890AD }
235 | code .keyword { color: #8A6343 }
236 | code .number { color: #2F6FAD }
237 |
238 | @media screen and (max-device-width: 480px) {
239 | body {
240 | padding: 60px 0px;
241 | }
242 |
243 | #stats {
244 | position: absolute;
245 | }
246 | }
247 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Arrays/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Arrays — Introduction & Warmups
5 |
6 |
7 |
8 |
9 |
10 |
11 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Arrays/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Arrays — Introduction & Warmups
5 |
6 |
7 |
8 |
9 |
10 |
11 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Arrays/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Arrays — Level 1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Arrays/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Arrays — Level 1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Arrays/README-L0.md:
--------------------------------------------------------------------------------
1 | # Arrays — Introduction
2 |
3 |
4 | ###### Overview
5 |
6 | This warmup and introduction is meant to help acquaint you with loops and arrays. It's not a quiz,
7 | but meant more as exposure to different ways to manipulate arrays and loops. Some of these questions
8 | may look familiar: they are. They are drawn from the same question bank as your admissions interview.
9 | That's our starting point.
10 |
11 |
12 | ###### NOTES
13 |
14 | * Do not use built-in array functions or helpers like map, reduce, etc (push/pop are okay)
15 | * Solve the problem using only direct loops and such
16 |
17 |
18 | ###### This Exercise
19 |
20 | Open [arrays-L0.js](ES6/src/arrays-L0.js) and follow the prompts below to complete the exercise. Use
21 | the [testRunner0.html](ES6/tests/testRunner0.html) file to run the tests and view your progress.
22 |
23 |
24 | ###### Objective
25 |
26 | Complete the following exercises:
27 |
28 | 1. Generate a Range I
29 | 2. Generate a Range II
30 | 3. Generate a Range III
31 | 4. Generate a Range IV
32 | 5. Generate Multiples of 5
33 | 6. Generate Multiples of 3 I
34 | 7. Generate Multiples of 3 II
35 | 8. Generate Multiples of 3 III
36 | 9. Generate Multiples of Either 3 or 5
37 | 10. Surprise Me!
38 | 11. Combine Two Arrays
39 | 12. Does Array Contain Value?
40 | 13. Temperature I
41 | 14. Temperature II
42 | 15. At Odds!
43 |
44 |
45 | ###### Primary Learning Goals
46 |
47 | * Warm up with different kinds of loops (for, while, do)
48 | * Warm up with different directions to iterate (forward, backwards) and count iterations (count by 1, -1, other than 1)
49 | * Warm up to reading and understand the prompt
50 | * Warm up to writing and calling functions (with or without parameters)
51 | * Warm up to understanding how the rest of this workshop runs tests
52 |
53 |
54 | ###### BONUS:
55 |
56 | 1. Multiples of 3 And 5
57 | 2. Generate Multiples of Range V
58 | 3. Generate Multiples of Range VI
59 | 4. Count Multiples of Range
60 | 5. Combine Two Arrays, Interleaved I
61 | 6. Combine Two Arrays, Interleaved II
62 |
63 |
64 | ###### Critical Whiteboard Skills
65 |
66 | * Understand the question, solve only what's asked
67 | * If something isn't clear, ask clarifying questions
68 | * Do not add requirements or over think it. These aren't trick questions
69 |
70 |
71 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Arrays/README-L1.md:
--------------------------------------------------------------------------------
1 | # Arrays — Introduction
2 |
3 |
4 | ###### Overview
5 |
6 | Arrays are efficient for random access. They are also the most common data structure,
7 | being built into nearly every programming language. The following exercises should
8 | serve as a glorious warm-up to the next few topics. The mechanics that you explore
9 | will become actual solutions to many of the exercises through the rest of this
10 | program.
11 |
12 |
13 | ###### Edge Cases
14 |
15 | * What to do when you have more elements than capacity
16 | * Out of bounds conditions. Array bounds is the set of all valid elements. Anything < 0 or >= length is out of bounds
17 |
18 |
19 | ###### NOTES
20 |
21 | * Do not use built-in array functions or helpers like map, reduce, etc.
22 | * Solve the problem using only direct loops and such
23 |
24 |
25 | ###### This Exercise
26 |
27 | Open [arrays-L1.js](ES6/src/arrays-L1.js) and follow the prompts below to complete the exercise. Use
28 | the [testRunner1.html](ES6/tests/testRunner1.html) file to run the tests and view your progress.
29 |
30 |
31 | ###### Objective
32 |
33 | Complete the following exercises:
34 |
35 | 1. Fill any array with value, zero if none provided, return original array
36 | 2. Return the sum of all values in any array
37 | 3. Return the average value of any array
38 | 4. Return the median of any array that has both an odd and even number of values
39 | 5. Return the index the value specified, or null if not found
40 | 6. Return index of nth last odd in any array, 1 being the fist, etc., null = not found
41 | 7. Select the subrange of an array into a new array
42 | 8. Select a range of values in any array, return the average of the values of the range
43 | 9. Copy contents of one array to another. Do not use any built-in functions.
44 | 10. Swap two elements in an array. Return the same array passed in. Do not use any built-in functions.
45 | 11. Copy smaller array into larger array
46 |
47 |
48 | ###### BONUS:
49 |
50 | * N/A
51 |
52 |
53 | ###### Critical Whiteboard Skills
54 |
55 | * Understand the question, solve only what's asked
56 | * If something isn't clear, ask clarifying questions
57 | * Do not add requirements or over think it. These aren't trick questions
58 |
59 |
60 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Arrays/README.md:
--------------------------------------------------------------------------------
1 | # Arrays
2 |
3 |
4 | #### Arrays - Introduction
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Arrays - Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Node template
3 | # Logs
4 | logs
5 | *.log
6 | npm-debug.log*
7 | yarn-debug.log*
8 | yarn-error.log*
9 |
10 | # Runtime data
11 | pids
12 | *.pid
13 | *.seed
14 | *.pid.lock
15 |
16 | # Directory for instrumented libs generated by jscoverage/JSCover
17 | lib-cov
18 |
19 | # Coverage directory used by tools like istanbul
20 | coverage
21 |
22 | # nyc test coverage
23 | .nyc_output
24 |
25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26 | .grunt
27 |
28 | # Bower dependency directory (https://bower.io/)
29 | bower_components
30 |
31 | # node-waf configuration
32 | .lock-wscript
33 |
34 | # Compiled binary addons (https://nodejs.org/api/addons.html)
35 | build/Release
36 |
37 | # Dependency directories
38 | node_modules/
39 | jspm_packages/
40 |
41 | # Typescript v1 declaration files
42 | typings/
43 |
44 | # Optional npm cache directory
45 | .npm
46 |
47 | # Optional eslint cache
48 | .eslintcache
49 |
50 | # Optional REPL history
51 | .node_repl_history
52 |
53 | # Output of 'npm pack'
54 | *.tgz
55 |
56 | # Yarn Integrity file
57 | .yarn-integrity
58 |
59 | # dotenv environment variables file
60 | .env
61 |
62 | # next.js build output
63 | .next
64 |
65 |
66 | # Solution Files
67 | #*SLN.js
68 | #*SLN.html
69 |
70 | # Questions
71 | #questions.js
72 |
73 | # Jetbrains Files
74 | .idea
75 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/ES6/src/binary-L0-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/ES6/src/binary-L0.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Binary — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Binary — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Binary — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Binary — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/ES6/tests/binaryTests-L0.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Binary/ES6/tests/binaryTests-L0.js
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/README-L0.md:
--------------------------------------------------------------------------------
1 | # Binary — Introduction
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 | Open [binary-L0.js](ES6/src/binary-L0.js) and follow the prompts below to complete the exercise. Use
19 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
20 |
21 |
22 | ###### Objective
23 |
24 |
25 |
26 | ###### Critical Whiteboard Skills
27 |
28 |
29 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Binary/README.md:
--------------------------------------------------------------------------------
1 | # Binary
2 |
3 |
4 | #### Binary — Introduction (coming soon)
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Binary — Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
15 |
16 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Complexity/Intro to Complexity Analysis (new).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Complexity/Intro to Complexity Analysis (new).pdf
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/src/graphs-L0-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | class Graph {
5 | constructor() {
6 | this.vertices = [];
7 | this.edges = [];
8 |
9 | this.vertexCount = 0;
10 | this.edgeCount = 0;
11 | }
12 |
13 |
14 |
15 | addVertex(vertex) {
16 | this.vertices.push(vertex);
17 | this.edges[vertex] = [];
18 |
19 | this.vertexCount += 1;
20 | }
21 |
22 |
23 |
24 | addEdge(v1, v2, directed = false) {
25 | this.edges[v1].push(v2);
26 |
27 | if (!directed) {
28 | this.edges[v2].push(v1);
29 | }
30 |
31 | this.edgeCount += 1;
32 | }
33 |
34 |
35 |
36 | removeVertex(vertex) {
37 | let index = this.vertices.indexOf(vertex);
38 |
39 | if (index >= 0) {
40 | this.vertices.splice(index, 1);
41 | }
42 |
43 | while(this.edges[vertex].length) {
44 | let v = this.edges[vertex].pop();
45 | this.removeEdge(v, vertex);
46 | }
47 | }
48 |
49 |
50 |
51 | removeEdge(v1, v2) {
52 | let iv1 = this.edges[v1] ? this.edges[v1].indexOf(v2) : -1;
53 | let iv2 = this.edges[v2] ? this.edges[v2].indexOf(v2) : -1;
54 |
55 | if (~iv1) {
56 | this.edges[v1].splice(iv1, 1);
57 | this.edgeCount -= 1;
58 | }
59 |
60 | if (~iv2) {
61 | this.edges[v2].splice(iv2, 1);
62 | }
63 | }
64 |
65 |
66 |
67 | contains(vertex) {
68 | return this.vertices.indexOf(vertex) >= 0;
69 | }
70 |
71 |
72 |
73 | traverseDFS(vertex, callback) {
74 | if (this.vertices.indexOf(vertex) < 0) {
75 | throw new Error("Vertex not found.");
76 | }
77 |
78 | let visited = [];
79 |
80 | let dfs = (vertex, visited, callback) => {
81 | visited[vertex] = true;
82 |
83 | if (this.edges[vertex] != undefined) {
84 | callback(vertex);
85 | }
86 |
87 | for (let i=0; i -1; i--) {
108 | if (!visited[this.edges[currentVertex][i]]) {
109 | stackList.push(this.edges[currentVertex][i]);
110 | visited[this.edges[currentVertex][i]] = true;
111 | }
112 | }
113 | console.log(currentVertex, stackList);
114 | }
115 | }
116 |
117 |
118 |
119 | findPath(from, to) {
120 | if(this.vertices.indexOf(from) < 0) {
121 | return null;
122 | }
123 |
124 | let queue = [];
125 | queue.push(from);
126 |
127 | let visited = [];
128 | visited[from] = true;
129 |
130 | let paths = [];
131 |
132 | while(queue.length) {
133 | let vertex = queue.shift();
134 |
135 | for(let i=0; i ");
158 | };
159 |
160 |
161 |
162 | toString() {
163 | let result = (this.vertices.map(function(vertex) {
164 | return (vertex + ' -> ' + this.edges[vertex].join(', ')).trim();
165 | }, this).join(' | '));
166 |
167 | return result;
168 | }
169 | } // class Graph { ...
170 |
171 | return Graph;
172 | };
173 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/src/graphs-L0.js:
--------------------------------------------------------------------------------
1 | let L0 = function() {
2 |
3 | class Graph {
4 | constructor() {
5 | this.vertices = [];
6 | this.edges = [];
7 |
8 | this.vertexCount = 0;
9 | this.edgeCount = 0;
10 | }
11 |
12 |
13 |
14 | addVertex(vertex) {
15 | // Your code here
16 | this.vertices.push(vertex);
17 | this.vertexCount++;
18 | }
19 |
20 |
21 |
22 | addEdge(v1, v2, directed = false) {
23 | // Your code here
24 | this.vertices.push([v1, v2], [v2, v1]);
25 | this.edgeCount++;
26 | }
27 |
28 |
29 |
30 | removeVertex(vertex) {
31 | // Your code here
32 | for(let i = 0; i < this.vertices.length; i++){
33 | if( this.vertices[i] === vertex ){
34 | this.vertices.slice(i, 1);
35 | }
36 | }
37 | this.vertexCount--;
38 | }
39 |
40 |
41 |
42 | removeEdge(v1, v2) {
43 | // Your code here
44 | for(let i = 0; i < this.edges.length; i++){
45 | let tuple = this.edges[i];
46 | if( tuple[0] === v1 && tuple[1] === v2 ){
47 | this.edges.slice(i, 1);
48 | }
49 | }
50 | this.edgeCount--;
51 |
52 | }
53 |
54 |
55 |
56 | contains(vertex) {
57 | // Your code here
58 | for(let i = 0; i < this.vertices.length; i++){
59 | if( this.vertices[i] === vertex ){
60 | return true;
61 | }
62 | }
63 | return false;
64 | }
65 |
66 |
67 |
68 | traverseDFS(vertex, callback) {
69 | // Your code here
70 | }
71 |
72 |
73 |
74 | findPath(from, to) {
75 | // Your code here
76 | }
77 |
78 |
79 |
80 | toString() {
81 | if (this.edges && this.edges.length > 0) {
82 | return this.edges.toString();
83 | }
84 |
85 | return "";
86 |
87 | // let result = (this.vertices.map(function(vertex) {
88 | // return (vertex + ' -> ' + this.edges[vertex].join(', ')).trim();
89 | // }, this).join(' | '));
90 | //
91 | // return result;
92 | }
93 | } // class Graph { ...
94 |
95 | return Graph;
96 | };
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/src/graphs-L1-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/src/graphs-L1.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 |
4 | };
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Graphs — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Graphs — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Graphs — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Graphs — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/tests/graphTests-L0.js:
--------------------------------------------------------------------------------
1 |
2 | describe("Graphs — Introduction", () => {
3 | let Graph;
4 | let graph;
5 |
6 | before(() => {
7 | Graph = L0();
8 | graph = new Graph();
9 | });
10 |
11 | describe("Initialize", () => {
12 | it("graph should not be null", () => {
13 | expect(graph).to.not.equal(null);
14 | });
15 | });
16 |
17 | describe("Use the graph", () => {
18 | it("TEST NOT COMPLETE OR PROPER AT THIS POINT", () => {
19 | var graph = new Graph();
20 | graph.addVertex(1);
21 | graph.addVertex(2);
22 | graph.addVertex(3);
23 | graph.addVertex(4);
24 | graph.addVertex(5);
25 | graph.addVertex(6);
26 | let output = graph.toString(); // 1 -> | 2 -> | 3 -> | 4 -> | 5 -> | 6 ->
27 | console.log(output);
28 | graph.addEdge(1, 2);
29 | graph.addEdge(1, 5);
30 | graph.addEdge(2, 3);
31 | graph.addEdge(2, 5);
32 | graph.addEdge(3, 4);
33 | graph.addEdge(4, 5);
34 | graph.addEdge(4, 6);
35 | output = graph.toString(); // 1 -> 2, 5 | 2 -> 1, 3, 5 | 3 -> 2, 4 | 4 -> 3, 5, 6 | 5 -> 1, 2, 4 | 6 -> 4
36 |
37 | let verticeCount = graph.vertexCount; // 6
38 | let edgeCount = graph.edgeCount; // 7;
39 |
40 | output = "";
41 | graph.traverseDFS(1, (vertex) => { output += vertex; }); // => 1 2 3 4 5 6
42 |
43 | try {
44 | output = "";
45 | graph.traverseDFS(0, (vertex) => { output += vertex; }); // => "Vertex not found" error
46 | }
47 | catch (e) {
48 | output = e.message;
49 | }
50 |
51 |
52 | output = "path from 6 to 1:" + graph.findPath(6, 1).toString(); // => 6-4-5-1
53 | output = "path from 3 to 5:" + graph.findPath(3, 5).toString(); // => 3-2-5
54 |
55 | graph.removeEdge(1, 2);
56 | graph.removeEdge(4, 5);
57 | graph.removeEdge(10, 11);
58 |
59 | output = "graph edges:" + graph.edgeCount; // => 5
60 | output = "path from 6 to 1:" + graph.findPath(6, 1).toString(); // => 6-4-3-2-5-1
61 |
62 | graph.addEdge(1, 2);
63 | graph.addEdge(4, 5);
64 |
65 | output = "graph vertices:" + graph.vertexCount; // => 7
66 | output = "path from 6 to 1:" + graph.findPath(6, 1).toString(); // => 6-4-5-1
67 |
68 | graph.removeVertex(5);
69 |
70 | output = "graph vertices:" + graph.vertexCount; // => 5
71 | output = "graph edges:" + graph.edgeCount; // => 4
72 |
73 | output = "path from 6 to 1:" + graph.findPath(6, 1); // => 6-4-3-2-1
74 | });
75 | });
76 | });
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/ES6/tests/graphTests-L1.js:
--------------------------------------------------------------------------------
1 |
2 | describe("Graphs — Part I", () => {
3 |
4 | });
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/README-L1.md:
--------------------------------------------------------------------------------
1 | # Graphs — Part I
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [graphs-L0.js](ES6/src/graphs-L0.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 |
26 |
27 | ###### BONUS:
28 |
29 |
30 |
31 | ###### Critical Whiteboard Skills
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/README.md:
--------------------------------------------------------------------------------
1 | # Graphs
2 |
3 |
4 | #### Graphs — Introduction (coming soon)
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Graphs — Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
15 |
16 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph1.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph2.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph3.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph4.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex1.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex2.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex3.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex4.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex5.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Graphs/assets/graph_ex6.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/src/hashtables-L0-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/src/hashtables-L0.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/src/hashtables-L1-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 | class HashTable {
4 | constructor(capacity) {
5 | this.capacity = capacity || 4;
6 | this.table = new Array(this.capacity);
7 | this.length = 0;
8 | }
9 |
10 |
11 | // HINT: Algorithm of adding an item
12 | //
13 | // Compute numeric hash of the key into bucketIndex
14 | // Read table based on bucketIndex
15 | // Was it previously filled?
16 | // No? Create a new bucket
17 | // yes? Add entry to it
18 | // Any collisions? based on key
19 | // No? Insert value
20 | // Yes? Replace value
21 | // Resize the storage if necessary (advanced)
22 | //
23 | set(key, value) {
24 | let bucketIndex = this.hasher(key);
25 | let bucket
26 | = this.table[bucketIndex]
27 | = this.table[bucketIndex] || [];
28 |
29 | let foundExistingEntry = false;
30 |
31 | for (let i = 0; i < bucket.length; i++) {
32 | let entry = bucket[i];
33 |
34 | if (entry[0] === key) {
35 | entry[1] = value;
36 | foundExistingEntry = true;
37 | }
38 | }
39 |
40 | if (!foundExistingEntry) {
41 | bucket.push([key, value]);
42 | this.length++;
43 |
44 | if (this.length >= this.capacity * 0.75) {
45 | this.rehash(this.capacity * 2);
46 | }
47 | }
48 |
49 | return this;
50 | }
51 |
52 |
53 | // Algorithm of a get (sometimes called a retrieve)
54 | //
55 | // Compute numeric hash of the key into bucketIndex
56 | // does numeric key exist in bucket? based on index
57 | // No? Do nothing
58 | // does value exist in entries? based on key
59 | // No? Do nothing
60 | // Yes? return value
61 | //
62 | get(key) {
63 | let bucketIndex = this.hasher(key);
64 | let bucket = this.table[bucketIndex];
65 |
66 | if (!bucket) {
67 | return null;
68 | }
69 |
70 | for (let i = 0; i < bucket.length; i++) {
71 | let entry = bucket[i];
72 |
73 | if (entry[0] === key) {
74 | return entry[1];
75 | }
76 | }
77 |
78 | return null;
79 | }
80 |
81 |
82 | // Algorithm of a remove
83 | //
84 | // Compute numeric hash of the key into bucketIndex
85 | // does numeric key exist in bucket? based on index
86 | // No? Do nothing
87 | // does value exist in entries? based on key
88 | // No? Do nothing
89 | // Yes? remove it, return old value
90 | //
91 | remove(key) {
92 | var bucketIndex = this.hasher(key);
93 | var bucket = this.table[bucketIndex];
94 |
95 | if (!bucket) {
96 | return null;
97 | }
98 |
99 | for (let i = 0; i < bucket.length; i++) {
100 | let tuple = bucket[i];
101 |
102 | if (tuple[0] === key) {
103 | bucket.splice(i, 1);
104 | this.length--;
105 |
106 | if (this.length < this.capacity * 0.25) {
107 | this.rehash(this.capacity / 2);
108 | }
109 | return tuple[1];
110 | }
111 | }
112 | }
113 |
114 |
115 |
116 | toString() {
117 | return this.table.toString();
118 | }
119 |
120 |
121 |
122 | hasher(key) {
123 | return key.toString().length % this.capacity;
124 | }
125 |
126 |
127 |
128 | rehash(newCapacity) {
129 | let table = this.table;
130 |
131 | this.capacity = newCapacity;
132 | this.length = 0;
133 | this.table = [];
134 |
135 | table.forEach(function(bucket) {
136 | if (!bucket) {
137 | return;
138 | }
139 | for (let i = 0; i < bucket.length; i++) {
140 | let entry = bucket[i];
141 | this.set(entry[0], entry[1]);
142 | }
143 | }.bind(this));
144 | }
145 | }
146 |
147 |
148 | return HashTable;
149 | };
150 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/src/hashtables-L1.js:
--------------------------------------------------------------------------------
1 | let L1 = function() {
2 | class HashTable {
3 | constructor(capacity) {
4 | this.capacity = capacity || 4;
5 | this.table = new Array(this.capacity);
6 | this.length = 0;
7 | }
8 |
9 | // HINT: Algorithm of adding an item
10 | //
11 | // Compute numeric hash of the key into bucketIndex
12 | // Read table based on bucketIndex
13 | // Was it previously filled?
14 | // No? Create a new bucket
15 | // yes? Add entry to it
16 | // Any collisions? based on key
17 | // No? Insert value
18 | // Yes? Replace value
19 | // Resize the storage if necessary (advanced)
20 |
21 | set(key, value) {
22 | let bucketIndex = this.hasher(key);
23 | let bucket = this.table[bucketIndex];
24 |
25 | if (!bucket) {
26 | bucket = [];
27 | this.table[bucketIndex] = bucket;
28 | }
29 |
30 | let override = false;
31 |
32 | for (let i = 0; i < bucket.length; i++) {
33 | let entry = bucket[i];
34 |
35 | if (entry[0] === key) {
36 | entry[1] = value;
37 | override = true;
38 | }
39 | }
40 |
41 | if (!override) {
42 | bucket.push([key, value]);
43 | this.length++;
44 |
45 | if (this.length >= this.capacity * 0.75) {
46 | this.rehash(this.capacity * 2);
47 | }
48 | }
49 |
50 | return this;
51 | }
52 |
53 | get(key) {
54 | // Your code here
55 | let bucketIndex = this.hasher(key);
56 | let bucket = this.table[bucketIndex];
57 |
58 | for (let index = 0; index < bucket.length; index++) {
59 | if (bucket[index][0] == key) {
60 | return bucket[index][1];
61 | }
62 | }
63 |
64 | return null;
65 | }
66 |
67 | remove(key) {
68 | // Your code here
69 | let bucketIndex = this.hasher(key);
70 | let bucket = this.table[bucketIndex];
71 |
72 | for (let index = 0; index < bucket.length; index++) {
73 | if (bucket[index][0] == key) {
74 | bucket.splice(index, 1);
75 | this.length--;
76 | break;
77 | }
78 | }
79 |
80 | return null;
81 | }
82 |
83 | toString() {
84 | // Your code here
85 | }
86 |
87 | hasher(key) {
88 | return key.toString().length % this.capacity;
89 | }
90 |
91 | rehash(newCapacity) {
92 | // Your code here
93 | }
94 | }
95 |
96 | return HashTable;
97 | };
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hash Tables — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hash Tables — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hash Tables - Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hash Tables - Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/tests/hashTableTests-L0.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/tests/hashTableTests-L0.js
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/ES6/tests/hashTableTests-L1.js:
--------------------------------------------------------------------------------
1 |
2 | describe("Hash Tables - Part I", () => {
3 | let HashTable;
4 | let hashTable;
5 |
6 | before(() => {
7 | HashTable = L1();
8 | hashTable = new HashTable();
9 | });
10 |
11 |
12 | describe("Initialize", () => {
13 | it("hashTable should not be null", () => {
14 | expect(hashTable).to.not.equal(null);
15 | });
16 |
17 | it("hashTable.table should exist", () => {
18 | expect(hashTable.table).to.exist;
19 | });
20 |
21 | it("hashTable.length should be 0", () => {
22 | expect(hashTable.length).to.equal(0);
23 | });
24 |
25 | it("hashTable.capacity should be 4", () => {
26 | expect(hashTable.capacity).to.equal(4);
27 | });
28 | });
29 |
30 | describe("Add the first item", () => {
31 | before(() => {
32 | hashTable.set("8472", "Elvis Presley");
33 | });
34 |
35 | it("hashTable.length should be 1", () => {
36 | expect(hashTable.length).to.equal(1);
37 | });
38 |
39 | it("hashTable.get(`8472`) should return `Elvis Presley`", () => {
40 | expect(hashTable.get("8472")).to.equal("Elvis Presley");
41 | });
42 | });
43 |
44 | describe("Retrieve a value that doesn't exist", () => {
45 | it("hashTable.get(`1000`) should return null", () => {
46 | expect(hashTable.get(1000)).to.equal(null);
47 | });
48 | });
49 |
50 | describe("Add 1 more", () => {
51 | before(() => {
52 | hashTable.set("876", "James Hetfield");
53 | });
54 |
55 | it("hashTable.length should be 2", () => {
56 | expect(hashTable.length).to.equal(2);
57 | });
58 |
59 | it("hashTable.get(`876`) should return `James Hetfield`", () => {
60 | expect(hashTable.get("876")).to.equal("James Hetfield");
61 | });
62 | });
63 |
64 | describe("Remove 1.", () => {
65 | let removed;
66 |
67 | before(() => {
68 | removed = hashTable.remove("876");
69 | });
70 |
71 | it("The entry removed should be `James Hetfield`", () => {
72 | removed = "James Hetfield";
73 | });
74 |
75 | it("hashTable.length should be 1", () => {
76 | expect(hashTable.length).to.equal(1);
77 | });
78 | });
79 |
80 | describe("Add `James Hetfield` back", () => {
81 | before(() => {
82 | hashTable.set("876", "James Hetfield");
83 | });
84 |
85 | it("hashTable.length should be 2", () => {
86 | expect(hashTable.length).to.equal(2);
87 | });
88 |
89 | it("hashTable.get(`876`) should return `James Hetfield`", () => {
90 | expect(hashTable.get("876")).to.equal("James Hetfield");
91 | });
92 | });
93 |
94 | describe("Force a collision", () => {
95 | before(() => {
96 | hashTable.set("9555", "Ozzy Osbourne");
97 | });
98 |
99 | it("hashTable.length should be 3", () => {
100 | expect(hashTable.length).to.equal(3);
101 | });
102 |
103 | it("hashTable.get(`9555`) should return `Ozzy Osbourne`", () => {
104 | expect(hashTable.get("9555")).to.equal("Ozzy Osbourne");
105 | });
106 |
107 | it("Ozzy and James are a collision", () => {
108 | expect(hashTable.table[4].toString()).to.equal("8472,Elvis Presley,9555,Ozzy Osbourne");
109 | });
110 | });
111 |
112 |
113 | describe("BONUS: A rehash triggered with the addition of Ozzy", () => {
114 | it("hashTable.capacity should be 8", () => {
115 | expect(hashTable.capacity).to.equal(8);
116 | });
117 | });
118 |
119 | describe("BONUS: toString()", () => {
120 | it("hashTable.toString() returns the contents as string", () => {
121 | expect(hashTable.toString()).to.be.a("string");
122 | });
123 | });
124 | });
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/README-L0.md:
--------------------------------------------------------------------------------
1 | # Hash Tables — Warmups
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [hashtables-L0.js](ES6/src/hashtables-L0.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 |
26 |
27 | ###### BONUS:
28 |
29 |
30 |
31 | ###### Critical Whiteboard Skills
32 |
33 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/README-L1.md:
--------------------------------------------------------------------------------
1 | # Hash Tables — Part I
2 |
3 |
4 | ###### Overview
5 |
6 | Hash Tables are extremely useful in computer science (and technical interviews). They
7 | allow us to gain the advantages of array-like random access but with non-integers
8 | instead -- or when the storage array is smaller than the number of possible index keys
9 | we will potentially need. A Hash Table is a specialized data structure that uses a
10 | key as input and computes an index from it, to be used as an array index for improved
11 | random access (than linear).
12 |
13 | Most programming languages provide some kind of Hash Table by default, and
14 | Javascript is no exception. Objects in Javascript are Hash Tables so there usually
15 | won't be any reason to recreate one in Javascript unless you need a non-default
16 | behavior. In this challenge we are going make a good Hash Table without simply
17 | wrapping over a Javascript object.
18 |
19 | There are a few necessary components to a Hash Table:
20 |
21 | 1. An array that usually offers more limited storage capacity than there will be keys
22 | filling it
23 | 2. A _hash function_ that will transform the key into an index for the array
24 | 3. A _collision_ resolver to deal with multiple different keys that both result
25 | in the same index
26 |
27 | Internal format of a HashTable looks like this:
28 |
29 | ```
30 |
31 | this.table = []
32 | this.length;
33 |
34 | |<----------------- Table --------------------->| Array
35 | |<---- Bucket ----->| ... ... Array of Arrays
36 | |<->| Entry ... ... ... ...
37 | [[[k,v], [k,v], [k,v]], [[k,v], [k,v]], [[k,v]]] Array of [key, value]
38 |
39 | ```
40 |
41 | A more graphical view of a Hash Table below:
42 |
43 | 
44 |
45 |
46 | ###### Edge Cases
47 |
48 | * Table size is too small for the number of items
49 | * When multiple keys hash to the same bucket and produce a collision
50 | * Knowing when to resize a mutable hash table. Many texts suggest rehashing
51 | when the load factor (number of buckets filled) reaches ~80% or when the
52 | average collisions reaches a threshold (5 collisions on average across the
53 | lookups or inserts). See [Hash Table Design](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.5908)
54 |
55 |
56 | ###### NOTES
57 |
58 | * We will only be using strings as a key for this exercise. Do not attempt
59 | or consider any other type of key
60 | * Do not simply pass-through to a Javascript object. Use an array for storage.
61 |
62 |
63 | ###### This Exercise
64 |
65 |
66 | Open [hashtables-L0.js](ES6/src/hashtables-L0.js) and follow the prompts below to complete the exercise. Use
67 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
68 |
69 |
70 | ###### Objective
71 |
72 | Your objective is to create a Hash Table with the following features:
73 |
74 | 1. HashTable class
75 | 2. .hasher() hash function to convert key into index
76 | 3. .set() function to add or set entries
77 | 4. .get() function to get entries
78 | 5. Collision resolution using the _chaining_ technique
79 | 6. .remove() function to remove entries
80 |
81 | ###### BONUS:
82 |
83 | 1. .toString() function to print everything to the console
84 | 2. .rehash() function to expand the key space
85 | 3. Must rehash (resize) when needed
86 |
87 |
88 | ###### Critical Whiteboard Skills
89 |
90 | * Hash Table questions will be more about using a Hash Table to solve unrelated
91 | problems, not so much about imlementing a Hash Table
92 | * Recognizing when a Hash Table can reduce a complexity class (E.G., eliminate a
93 | loop).
94 | * Knowing when to use a Hash Table vs an array or other data structure
95 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/README.md:
--------------------------------------------------------------------------------
1 | # Hash Tables
2 |
3 |
4 | #### Hash Tables — Introduction (coming soon)
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Hash Tables — Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
15 |
16 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/assets/HashTable-Wikipedia.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/HashTables/assets/HashTable-Wikipedia.png
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/src/linkedLists-L1-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 | class Node {
4 | constructor(data) {
5 | this.data = data;
6 | this.next = null;
7 | }
8 | }
9 |
10 | class SinglyLinkedList {
11 | constructor() {
12 | this.head = null;
13 | this.tail = null;
14 | }
15 |
16 |
17 |
18 | add(index, data) {
19 | let node = new Node(data);
20 | if (!index) {
21 | node.next = this.head;
22 | this.head = node;
23 |
24 | if (this.tail == null) {
25 | this.tail = node;
26 | }
27 | }
28 | else {
29 | let prev = this.get(index-1);
30 |
31 | node.next = prev.next;
32 | prev.next = node;
33 |
34 | if (prev == this.tail) {
35 | this.tail = node;
36 | }
37 | }
38 |
39 | return node;
40 | }
41 |
42 |
43 |
44 | get(index) {
45 | let node = this.head;
46 | let count = 0;
47 |
48 | while (count++ < index && node != null) {
49 | node = node.next;
50 | }
51 |
52 | return node;
53 | }
54 |
55 |
56 |
57 | remove(index) {
58 | let result;
59 | if (!index) {
60 | result = this.head;
61 | this.head = this.head.next;
62 |
63 | if (result == this.tail) {
64 | this.tail = this.head;
65 | }
66 |
67 | return result;
68 | }
69 |
70 | let node = this.get(index-1);
71 | result = node.next;
72 | node.next = node.next.next;
73 |
74 | if (result == this.tail) {
75 | this.tail = node;
76 | }
77 |
78 | return result;
79 | }
80 |
81 |
82 |
83 | find(data) {
84 | let node = this.head;
85 | let pos = 0;
86 |
87 | while (node != null) {
88 | if (node.data === data) {
89 | return { "position": pos, "node": node };
90 | }
91 |
92 | node = node.next;
93 | pos += 1;
94 | }
95 |
96 | return null;
97 | }
98 |
99 |
100 |
101 | toArray() {
102 | let result = [];
103 |
104 | let node = this.head;
105 | while (node != null) {
106 | result.push(node.data);
107 | node = node.next;
108 | }
109 |
110 | return result;
111 | }
112 | }
113 |
114 | return [SinglyLinkedList, Node];
115 | };
116 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/src/linkedLists-L1.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 | class Node {
4 | constructor(data) {
5 | this.data = data;
6 | this.next = null;
7 | }
8 | }
9 |
10 | class SinglyLinkedList {
11 | constructor() {
12 | this.head = null;
13 | this.tail = null;
14 | }
15 |
16 |
17 |
18 | add(index, data) {
19 | // Your code here
20 | }
21 |
22 |
23 |
24 | get(index) {
25 | // Your code here
26 | }
27 |
28 |
29 |
30 | remove(index) {
31 | // Your code here
32 | }
33 |
34 |
35 |
36 | find(data) {
37 | // Your code here
38 | }
39 |
40 |
41 |
42 | toArray() {
43 | // Your code here
44 | }
45 | }
46 |
47 | return [SinglyLinkedList, Node];
48 | };
49 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/src/linkedLists-L2-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L2 = function() {
3 | class Node {
4 | constructor(data) {
5 | this.data = data;
6 | this.next = null;
7 | this.prev = null;
8 | }
9 | }
10 |
11 | class DoublyLinkedList {
12 | constructor() {
13 | this.head = null;
14 | this.tail = null;
15 | }
16 |
17 |
18 |
19 | add(data) {
20 | let node = new Node(data);
21 | if (!this.head) {
22 | this.head = node;
23 | this.tail = node;
24 | }
25 | else {
26 | node.previous = this.tail;
27 | this.tail.next = node;
28 | this.tail = node;
29 | }
30 | return node;
31 | }
32 |
33 |
34 |
35 | insertBefore(index, data) {
36 | let node = new Node(data);
37 | if (!index) {
38 | node.next = this.head;
39 | this.head.prev = node;
40 |
41 | if (this.head === this.tail) {
42 | this.tail = node;
43 | }
44 |
45 | this.head = node;
46 | }
47 | else {
48 | let current = this.get(index);
49 | let prev = current.prev;
50 | let next = current.next;
51 |
52 | node.next = current;
53 | current.prev = node;
54 | prev.next = node;
55 | node.prev = prev;
56 | }
57 |
58 | return node;
59 | }
60 |
61 |
62 |
63 | insertAfter(index, data) {
64 | let node = new Node(data);
65 | if (!index) {
66 | if (!this.tail) {
67 | this.head = node;
68 | this.tail = node;
69 | }
70 | else {
71 | this.tail.next = node;
72 | node.prev = this.tail;
73 | }
74 | }
75 | else {
76 | let current = this.get(index);
77 | let next = current.next;
78 |
79 | node.next = next;
80 | if (next) {
81 | next.prev = node;
82 | }
83 | current.next = node;
84 | node.prev = current;
85 | }
86 |
87 | return node;
88 | }
89 |
90 |
91 | get(index) {
92 | let node = this.head;
93 | let count = 0;
94 |
95 | while (count++ < index && node != null) {
96 | node = node.next;
97 | }
98 |
99 | return node;
100 | }
101 |
102 |
103 | set(index, data) {
104 | let node = this.get(index);
105 | if (node) {
106 | node.data = data;
107 | }
108 | }
109 |
110 |
111 | remove(index) {
112 | let result;
113 |
114 | result = this.get(index);
115 | if (!index) {
116 | if (this.head === this.tail) {
117 | this.head = null;
118 | this.tail = null;
119 | }
120 | else {
121 | this.head = this.head.next;
122 | }
123 | }
124 | else {
125 | let prev = result.prev;
126 | let next = result.next;
127 |
128 | prev.next = next;
129 | if (result !== this.tail) {
130 | next.prev = prev;
131 | }
132 | else {
133 | this.tail = prev;
134 | }
135 | }
136 |
137 | return result;
138 | }
139 |
140 |
141 |
142 | find(data) {
143 | let node = this.head;
144 | let pos = 0;
145 |
146 | while (node != null) {
147 | if (node.data === data) {
148 | return { "position": pos, "node": node };
149 | }
150 |
151 | node = node.next;
152 | pos += 1;
153 | }
154 |
155 | return null;
156 | }
157 |
158 |
159 |
160 | contains(data) {
161 | let node = this.head;
162 | let count = 0;
163 |
164 | while (node != null) {
165 | if (node.data === data) {
166 | count += 1;
167 | }
168 |
169 | node = node.next;
170 | }
171 |
172 | return count;
173 | }
174 |
175 |
176 |
177 | toArray() {
178 | let result = [];
179 |
180 | let node = this.head;
181 | while (node != null) {
182 | result.push(node.data);
183 | node = node.next;
184 | }
185 |
186 | return result;
187 | }
188 | }
189 |
190 | return [DoublyLinkedList, Node];
191 | };
192 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/src/linkedLists-L2.js:
--------------------------------------------------------------------------------
1 |
2 | let L2 = function() {
3 | class Node {
4 | constructor(data) {
5 | this.data = data;
6 | this.next = null;
7 | this.prev = null;
8 | }
9 | }
10 |
11 | class DoublyLinkedList {
12 | constructor() {
13 | this.head = null;
14 | this.tail = null;
15 | }
16 |
17 |
18 |
19 | add(data) {
20 | // Your code here
21 | }
22 |
23 |
24 |
25 | insertBefore(index, data) {
26 | // Your code here
27 | }
28 |
29 |
30 |
31 | insertAfter(index, data) {
32 | // Your code here
33 | }
34 |
35 |
36 | get(index) {
37 | // Your code here
38 | }
39 |
40 |
41 | set(index, data) {
42 | // Your code here
43 | }
44 |
45 |
46 | remove(index) {
47 | // Your code here
48 | }
49 |
50 |
51 |
52 | find(data) {
53 | // Your code here
54 | }
55 |
56 |
57 |
58 | contains(data) {
59 | // Your code here
60 | }
61 |
62 |
63 |
64 | toArray() {
65 | // Your code here
66 | }
67 | }
68 |
69 | return [DoublyLinkedList, Node];
70 | };
71 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/src/linkedLists-L3-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 | class Node {
4 | constructor(data) {
5 | this.data = data;
6 | this.next = null;
7 | }
8 | }
9 |
10 | class SinglyLinkedList {
11 | constructor() {
12 | this.head = new Node(null, null);
13 | this.tail = null;
14 | }
15 |
16 |
17 | append(data) {
18 | let node = new Node(data);
19 |
20 | this.tail.next = node;
21 | this.tail = node;
22 |
23 | return node;
24 | }
25 |
26 |
27 |
28 | insertFirst(data) {
29 | let node = new Node(data, this.head.next);
30 | this.head.next = node;
31 |
32 | return node;
33 | }
34 |
35 |
36 |
37 | insert(index, data) {
38 | let node = new Node(data);
39 | let prev = this.head;
40 |
41 | while (index > 0 && prev.next) {
42 | prev = prev.next;
43 | }
44 |
45 | node.next = prev.next;
46 | prev.next = node;
47 |
48 | if (!node.next) {
49 | this.tail = node;
50 | }
51 |
52 | return node;
53 | }
54 |
55 |
56 |
57 | get(index) {
58 | let node = this.head.next;
59 | let count = 0;
60 |
61 | while (count++ < index && node.next !== this.tail) {
62 | node = node.next;
63 | }
64 |
65 | return node;
66 | }
67 |
68 |
69 |
70 | remove(index) {
71 | let result;
72 |
73 |
74 |
75 | return result;
76 | }
77 |
78 |
79 |
80 | find(data) {
81 | let node = this.head.next;
82 | let pos = 0;
83 |
84 | while (node.next != this.tail) {
85 | if (node.data === data) {
86 | return { "position": pos, "node": node };
87 | }
88 |
89 | node = node.next;
90 | pos += 1;
91 | }
92 |
93 | return null;
94 | }
95 |
96 |
97 |
98 | toArray() {
99 | let result = [];
100 |
101 | let node = this.head.next;
102 | while (node.next !== this.tail) {
103 | result.push(node.data);
104 | node = node.next;
105 | }
106 |
107 | return result;
108 | }
109 | }
110 |
111 | return [SinglyLinkedList, Node];
112 | };
113 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/src/linkedLists-L3.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 | class Node {
4 | constructor(data) {
5 | this.data = data;
6 | this.next = null;
7 | }
8 | }
9 |
10 | class SinglyLinkedList {
11 | constructor() {
12 | this.head = null;
13 | this.tail = null;
14 | }
15 |
16 |
17 |
18 | add(index, data) {
19 | // Your code here
20 | }
21 |
22 |
23 |
24 | get(index) {
25 | // Your code here
26 | }
27 |
28 |
29 |
30 | remove(index) {
31 | // Your code here
32 | }
33 |
34 |
35 |
36 | find(data) {
37 | // Your code here
38 | }
39 |
40 |
41 |
42 | toArray() {
43 | // Your code here
44 | }
45 | }
46 |
47 | return [SinglyLinkedList, Node];
48 | };
49 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linked Lists — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linked Lists — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linked Lists — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linked Lists — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/testRunner2-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linked Lists — Part II
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/testRunner2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linked Lists — Part II
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/testRunner3-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linked Lists — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/ES6/testRunner3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linked Lists — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/README-L0.md:
--------------------------------------------------------------------------------
1 | # Linked Lists - Part 0 | Introduction & Warmups
2 |
3 |
4 | ###### Overview
5 |
6 | A Linked List node is nothing more than a structure with some data and a reference
7 | to the next node. It has no direct way to access any previous nodes. That's what
8 | make it a favorite among interviewers.
9 |
10 | There are 3 main concerns with Linked Lists:
11 |
12 | ```text
13 | HEAD : the first node
14 | TAIL : the last node
15 | MIDDLE: everything else
16 | ```
17 |
18 | If an add or remove operation can use the HEAD or TAIL then we can gain special
19 | optimizations by not having to find the previous node as we must with any middle
20 | operation.
21 |
22 | For any middle node operation, we must locate the previous node first.
23 |
24 | As such, we can visual a Linked List like this:
25 |
26 | ```text
27 | SECTION: HEAD MIDDLE MIDDLE TAIL
28 | STRUCTURE: NULL -> [Data, Next] --> [Data, Next] --> [Data, Next] --> [Data, Next] -> NULL
29 | META: (Prev) (Prev) (Prev)
30 | META (Index): 0 1 2 3
31 | ```
32 |
33 | For any middle or tail node, there's always a previous node but there's no way to
34 | directly know what it is, it has to be _found_.
35 |
36 |
37 | ###### NOTES
38 |
39 | * DO NOTE COPY AND PASTE any code. Complete each warmup by writing the necessary code
40 | (again if you already wrote it before).
41 |
42 |
43 | ###### This Exercise
44 |
45 | Open [linkedLists-L0.js](ES6/src/linkedLists-L0.js) and follow the prompts below to complete the exercise. Use
46 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
47 |
48 |
49 | ###### Objective
50 |
51 | Complete the following exercises:
52 |
53 | 1. Write a function that creates and returns a new node.
54 | 2. Write a function that creates and returns a new node. If its the first node, then
55 | set first to it.
56 | 3. Write a function that creates a new node and makes it the first node in the list.
57 | 4. Write a function that creates a new node and makes it the second node in the list.
58 | 5. Extend the previous functions to set the last as-necessary.
59 | 6. Write a function that creates a new node and always appends it to the end.
60 | 7. Write a function that removes the first node.
61 | 8. Write a function that removes the second node in the list.
62 | 9. Write a function that returns any node in the list.
63 | 10. Write a function that returns the previous node.
64 | 11. Write a function that removes the last node in the list.
65 | 12. Write a function that inserts a new node at any position in the list.
66 | 13. Write a function that removes any node in the list.
67 | 14. Write a function that creates an array of all the data in the list and returns the array.
68 |
69 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/README-L1.md:
--------------------------------------------------------------------------------
1 | # Linked Lists — Part II
2 |
3 |
4 | ###### Overview
5 |
6 | In this exercise, we are going to implement and operate on a Singly Linked List. This will help
7 | to illuminate some of the workings of a Linked List and help set the foundation for the next
8 | few challenges. One of the trickiest parts of working with a Linked List isn't finding a node,
9 | but having to manipulate the next pointers in the correct sequence and not having easy access
10 | to the previous node. The standard Linked List does not provide a way for a given node to
11 | access any previous node. Having access to the previous node (if any) is a critical part of
12 | manipulating Linked Lists.
13 |
14 |
15 | ###### Edge Cases
16 |
17 | Doubly Linked Lists will have similar edge cases as other sequential structures, namely:
18 |
19 | * What to do with an empty list
20 | * What to do when adding or working with the first node
21 | * What to do when adding or working with the last node
22 | * What to do when adding or working with any middle node
23 |
24 | A visual view of Linked List below:
25 |
26 | ##### Example 1
27 | ```
28 | Head | Middle ... ... | Tail
29 | [ h ] -> [ m1 ] -> [ m2 ] -> ... [ mn ] -> [ t ] -> null
30 |
31 | Pos: 0 1 2 n-2 n-1
32 | ```
33 |
34 | ##### Example 2
35 |
36 | ```
37 | Head/Tail
38 | [ Node ] -> null
39 |
40 | Pos: 0
41 | ```
42 |
43 | ##### Example 3
44 |
45 | ```
46 | Head/Tail
47 | null
48 |
49 | Pos: none
50 | ```
51 |
52 |
53 | ###### NOTES
54 |
55 | * A Head refers to the first node, and a Tail refers to the last node.
56 | * error conditions
57 |
58 |
59 | ###### This Exercise
60 |
61 | Open [linkedLists-L1.js](ES6/src/linkedLists-L1.js) and follow the prompts below to complete the exercise. Use
62 | the [testRunner1.html](ES6/testRunner1.html) file to run the tests and view your progress.
63 |
64 |
65 | ###### Objective
66 |
67 | Your objective is to implement a Singly Linked List by completing the following:
68 |
69 | 1. Declare head and tail variables
70 | 2. .add() function to add a node at the given position and return the new node
71 | 3. .get() function to find a node at the given position
72 | 4. .find() function to find and return the following structure { position, node }
73 | 5. .remove() function to remove the node at the given position and return it
74 | 6. .toArray() function to return an array of all linked lists value in the same sequence
75 | as they appear in the linked list
76 |
77 |
78 | ###### Critical Whiteboard Skills
79 |
80 | Some of the most important muscle-memory skills to have on a whiteboard when working with
81 | Linked Lists are:
82 |
83 | * Iterating through the list looking for a value
84 | * Iterating through a list to find the node at some position
85 | * Finding the previous node
86 | * Knowing which operations are O(1) and which aren't and implementing accordingly
87 |
88 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/README-L2.md:
--------------------------------------------------------------------------------
1 | # Linked Lists — Part II
2 |
3 |
4 | ###### Overview
5 |
6 | Doubly Linked Lists are similar to Singly Linked Lists but with one super important
7 | enhancement: the addition of a `previous` pointer that allows direct access to the
8 | node before it.
9 |
10 |
11 |
12 | ###### Edge Cases
13 |
14 | Doubly Linked Lists will have similar edge cases as other sequential structures, namely:
15 |
16 | * What to do with an empty list
17 | * What to do when adding or working with the first node
18 | * What to do when adding or working with the last node
19 | * What to do when adding or working with any middle node
20 |
21 | A visual view of a Doubly Linked List below:
22 |
23 | ##### Example 1
24 | ```
25 | Head | Middle ... ... | Tail
26 | [ h ] -> [ m1 ] -> [ m2 ] -> ... [ mn ] -> [ t ] -> null
27 | null <- [ ] <- [ ] <- [ ] <- ... [ ] <- [ ]
28 | Pos: 0 1 2 n-2 n-1
29 | ```
30 |
31 | ##### Example 2
32 |
33 | ```
34 | Head/Tail
35 | [ Node ] -> null
36 | null <- [ ]
37 | Pos: 0
38 | ```
39 |
40 | ##### Example 3
41 |
42 | ```
43 | Head/Tail
44 | null
45 |
46 | Pos: none
47 | ```
48 |
49 |
50 | ###### This Exercise
51 |
52 | Open [linkedLists-L2.js](ES6/src/linkedLists-L2.js) and follow the prompts below to complete the exercise. Use
53 | the [testRunner2.html](ES6/testRunner2.html) file to run the tests and view your progress.
54 |
55 |
56 | ###### NOTES
57 |
58 | * A Head refers to the first node, and a Tail refers to the last node.
59 | * error conditions
60 |
61 |
62 | ###### Objective
63 |
64 | Your objective is to implement a Doubly Linked List by completing the following:
65 |
66 | 1. Implement Node class
67 | 2. Implement DoublyLinkedList class
68 | 3. Declare head and tail variables
69 | 4. .add() function to add a new node at the end
70 | 5. .insertAfter() function to insert data after a node (0/null for tail position)
71 | 6. .insertBefore() function to insert data before a node (0/null for head position)
72 | 7. .remove() function to remove data at position (0/null for head)
73 | 8. .get() function to return data at position indicated
74 | 9. .set() function to change existing data at position indicated
75 | 10. .find() function to find and return the following structure { position, node }
76 | 11. .contains() function to return the number of occurrences of a value in the list, 0 for none.
77 |
78 |
79 | ###### Critical Whiteboard Skills
80 |
81 | Some of the most important muscle-memory skills to have on a whiteboard when working with
82 | Linked Lists are:
83 |
84 | * Iterating through the list looking for a value
85 | * Iterating through a list to find the node at some position
86 | * Finding the previous node
87 | * Knowing which operations are O(1) and which aren't and implementing accordingly
88 |
89 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/README-L3.md:
--------------------------------------------------------------------------------
1 | # Linked Lists — Part II
2 |
3 |
4 | ###### Overview
5 |
6 | Doubly Linked Lists are similar to Singly Linked Lists but with one super important
7 | enhancement: the addition of a `previous` pointer that allows direct access to the
8 | node before it.
9 |
10 |
11 |
12 | ###### Edge Cases
13 |
14 | Doubly Linked Lists will have similar edge cases as other sequential structures, namely:
15 |
16 | * What to do with an empty list
17 | * What to do when adding or working with the first node
18 | * What to do when adding or working with the last node
19 | * What to do when adding or working with any middle node
20 |
21 | A visual view of a Doubly Linked List below:
22 |
23 | ##### Example 1
24 | ```
25 | Head | Middle ... ... | Tail
26 | [ h ] -> [ m1 ] -> [ m2 ] -> ... [ mn ] -> [ t ] -> null
27 | null <- [ ] <- [ ] <- [ ] <- ... [ ] <- [ ]
28 | Pos: 0 1 2 n-2 n-1
29 | ```
30 |
31 | ##### Example 2
32 |
33 | ```
34 | Head/Tail
35 | [ Node ] -> null
36 | null <- [ ]
37 | Pos: 0
38 | ```
39 |
40 | ##### Example 3
41 |
42 | ```
43 | Head/Tail
44 | null
45 |
46 | Pos: none
47 | ```
48 |
49 |
50 | ###### This Exercise
51 |
52 | Open [linkedLists-L2.js](ES6/src/linkedLists-L2.js) and follow the prompts below to complete the exercise. Use
53 | the [testRunner2.html](ES6/testRunner2.html) file to run the tests and view your progress.
54 |
55 |
56 | ###### NOTES
57 |
58 | * A Head refers to the first node, and a Tail refers to the last node.
59 | * error conditions
60 |
61 |
62 | ###### Objective
63 |
64 | Your objective is to implement a Doubly Linked List by completing the following:
65 |
66 | 1. Implement Node class
67 | 2. Implement DoublyLinkedList class
68 | 3. Declare head and tail variables
69 | 4. .add() function to add a new node at the end
70 | 5. .insertAfter() function to insert data after a node (0/null for tail position)
71 | 6. .insertBefore() function to insert data before a node (0/null for head position)
72 | 7. .remove() function to remove data at position (0/null for head)
73 | 8. .get() function to return data at position indicated
74 | 9. .set() function to change existing data at position indicated
75 | 10. .find() function to find and return the following structure { position, node }
76 | 11. .contains() function to return the number of occurrences of a value in the list, 0 for none.
77 |
78 |
79 | ###### Critical Whiteboard Skills
80 |
81 | Some of the most important muscle-memory skills to have on a whiteboard when working with
82 | Linked Lists are:
83 |
84 | * Iterating through the list looking for a value
85 | * Iterating through a list to find the node at some position
86 | * Finding the previous node
87 | * Knowing which operations are O(1) and which aren't and implementing accordingly
88 |
89 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/LinkedLists/README.md:
--------------------------------------------------------------------------------
1 | d# Linked Lists
2 |
3 |
4 | #### Linked Lists — Introduction
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Linked Lists — Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
15 |
16 | #### Linked Lists — Level 2
17 |
18 | Open and complete [README-L2.md](README-L2.md)
19 |
20 |
21 | #### Linked Lists — Level 3
22 |
23 | Open and complete [README-L3.md](README-L3.md)
24 |
25 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/lib/consoleHook/consoleHook.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | function consoleHook_initialize() {
5 | let output = [];
6 | let _cl_ = console.log;
7 |
8 | console.log = function(value) {
9 | output.push(value);
10 | _cl_(value);
11 | };
12 |
13 | return {
14 | read: function() {
15 | return output.shift();
16 | },
17 |
18 | bufferLength: function() {
19 | return output.length;
20 | },
21 |
22 | flush: function() {
23 | output = [];
24 | },
25 |
26 | terminate: function() {
27 | console.log = _cl_;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/src/queues-L0-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/src/queues-L0.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/src/queues-L1-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/src/queues-L1.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 |
4 | };
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Queues — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Queues — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Queues — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Queues — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/tests/queueTests-L0.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/tests/queueTests-L0.js
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/ES6/tests/queueTests-L1.js:
--------------------------------------------------------------------------------
1 |
2 | describe("Queues - Part I", () => {
3 |
4 | });
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/README-L0.md:
--------------------------------------------------------------------------------
1 | # Queues — Introductions
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [queues-L0.js](ES6/src/queues-L0.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 |
26 |
27 | ###### BONUS:
28 |
29 |
30 |
31 | ###### Critical Whiteboard Skills
32 |
33 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/README-L1.md:
--------------------------------------------------------------------------------
1 | # Queues — Part I
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [queues-L1.js](ES6/src/queues-L1.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner1.html](ES6/testRunner1.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 |
26 |
27 | ###### BONUS:
28 |
29 |
30 |
31 | ###### Critical Whiteboard Skills
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Queues/README.md:
--------------------------------------------------------------------------------
1 | # Queues
2 |
3 |
4 | #### Queues — Introductions (coming soon)
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Queues — Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
15 |
16 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/ES6/lib/consoleHook/consoleHook.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | function consoleHook_initialize() {
5 | let output = [];
6 | let _cl_ = console.log;
7 |
8 | console.log = function(value) {
9 | output.push(value);
10 | _cl_(value);
11 | };
12 |
13 | return {
14 | read: function() {
15 | return output.shift();
16 | },
17 |
18 | bufferLength: function() {
19 | return output.length;
20 | },
21 |
22 | flush: function() {
23 | output = [];
24 | },
25 |
26 | terminate: function() {
27 | console.log = _cl_;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Recursion — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Recursion - Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Recursion — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Recursion — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/ES6/tests/recursionTests-L0.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | describe("Recursion - Introduction", () => {
4 | let code;
5 | let util;
6 |
7 | before(() => {
8 | code = new L0();
9 | });
10 |
11 | beforeEach(() => {
12 | util = consoleHook_initialize();
13 | });
14 |
15 | afterEach(() => {
16 | util.terminate();
17 | });
18 |
19 |
20 | it("1. Count from 1 to N.", () => {
21 | code.from1ToN(5);
22 |
23 | expect(util.read()).to.equal(1);
24 | expect(util.read()).to.equal(2);
25 | expect(util.read()).to.equal(3);
26 | expect(util.read()).to.equal(4);
27 | expect(util.read()).to.equal(5);
28 | });
29 |
30 |
31 | it("2. Count from N to 1.", () => {
32 | code.fromNTo1(5);
33 |
34 | expect(util.read()).to.equal(5);
35 | expect(util.read()).to.equal(4);
36 | expect(util.read()).to.equal(3);
37 | expect(util.read()).to.equal(2);
38 | expect(util.read()).to.equal(1);
39 | });
40 |
41 |
42 | it("3. Count from X to Y.", () => {
43 | code.fromXtoY(5, 10);
44 |
45 | expect(util.read()).to.equal(5);
46 | expect(util.read()).to.equal(6);
47 | expect(util.read()).to.equal(7);
48 | expect(util.read()).to.equal(8);
49 | expect(util.read()).to.equal(9);
50 | expect(util.read()).to.equal(10);
51 | });
52 |
53 |
54 | it("4. Count Length of Array.", () => {
55 | let result = code.getLengthOfArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
56 | expect(result).to.equal(10);
57 | });
58 |
59 |
60 | it("5. Calculate sum of array of numbers.", () => {
61 | let result = code.sumOfArray([1,2,3,4]);
62 | expect(result).to.equal(10);
63 | });
64 |
65 |
66 | it("6. Calculate the average of array of numbers.", () => {
67 | let result = code.averageOfArray([23, 17, 23, 42, 8, 2, 73, 101, 83, 92]);
68 | expect(result).to.equal(46.4);
69 | });
70 |
71 |
72 | it("7. Calculate the sum of all even values in an array.", () => {
73 | let result = code.sumOfEvens([1,2,3,4,5,6,7,8]);
74 | expect(result).to.equal(20);
75 | });
76 |
77 |
78 | it("8. Return the number of digits in a number.", () => {
79 | let result = code.numberOfDigits(13028);
80 | expect(result).to.equal(5);
81 | });
82 |
83 |
84 | it("9. Return whether a number contains another number.", () => {
85 | let result = code.nContainsK(13250, 5);
86 | expect(result).to.equal(true);
87 |
88 | result = code.nContainsK(13250, 4);
89 | expect(result).to.equal(false);
90 | });
91 |
92 |
93 | it("10. Return the X to the power of Y.", () => {
94 | let result = code.power(2, 4);
95 | expect(result).to.equal(16);
96 | });
97 | });
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/ES6/tests/recursionTests-L1.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | describe("Recursion - Part II", () => {
4 | let code;
5 | let util;
6 |
7 | before(() => {
8 | code = new L1();
9 | });
10 |
11 | beforeEach(() => {
12 | util = consoleHook_initialize();
13 | });
14 |
15 | afterEach(() => {
16 | util.terminate();
17 | });
18 |
19 |
20 | it("1. Reverse an Integer.", () => {
21 | expect(code.reverseInt(233445)).to.equal(544332);
22 | });
23 |
24 |
25 | it ("2. Convert an integer to a binary string.", () => {
26 | expect(code.intToBinary(7)).to.equal("111");
27 | expect(code.intToBinary(16)).to.equal("10000");
28 | expect(code.intToBinary(10)).to.equal("1010");
29 | expect(code.intToBinary(37)).to.equal("100101");
30 | });
31 |
32 |
33 | it("3. Format any number with commas.", () => {
34 | expect(code.intWithCommas(123)).to.equal("123");
35 | expect(code.intWithCommas(1940)).to.equal("1,940");
36 | expect(code.intWithCommas(2930194)).to.equal("2,930,194");
37 | });
38 |
39 |
40 | it("4. Write N number of Xs on same line.", () => {
41 | expect(code.logLineWithNXs(3)).to.equal("XXX");
42 | expect(code.logLineWithNXs(5)).to.equal("XXXXX");
43 | });
44 |
45 |
46 | it("5. Print a triangle with the number lines indicated by N.", () => {
47 | let depth = 5;
48 |
49 | code.logTriangle(depth);
50 |
51 | let line;
52 |
53 | for (let i=0; i {
62 | let depth = 5;
63 |
64 | code.logTriangleUpsideDown(depth);
65 |
66 | let line;
67 |
68 | for (let i=depth; i>0; i--) {
69 | line = util.read();
70 |
71 | expect(line.length).to.equal(i);
72 | }
73 | });
74 |
75 |
76 | it("7. Write a recursive function that reverses an array in-place.", () => {
77 | expect(code.reverseArray([1,2,3,4,5,6])).to.eql([6,5,4,3,2,1]);
78 | });
79 |
80 |
81 | it("8. Write a recursive function to determine if two arrays are equal.", () => {
82 | let input1 = [1234567];
83 | let input2 = [1234567];
84 | let input3 = [7654321];
85 | let input4 = [32];
86 |
87 | expect(code.areArraysEqual(input1, input2, input1.length, input2.length)).to.equal(true);
88 | expect(code.areArraysEqual(input1, input3, input1.length, input3.length)).to.equal(false);
89 | expect(code.areArraysEqual(input1, input4, input1.length, input4.length)).to.equal(false);
90 | expect(code.areArraysEqual([], [], 0, 0)).to.equal(true);
91 | });
92 |
93 |
94 | it("9. Write a recursive function that returns the index of the max value in an array of numbers.", () => {
95 | expect(code.maxValueInArray([1,2,5,2,5,2,19,5,2], 9)).to.equal(6);
96 | });
97 |
98 |
99 | it("10. Write a recursive function that returns whether an array of number is sorted.", () => {
100 | expect(code.isArraySorted([1,2,3,4,5,6], 5)).to.equal(true);
101 | expect(code.isArraySorted([1,2,3,5,4,6], 5)).to.equal(false);
102 | });
103 |
104 | it("11. Write a recursive function to fill a pre-allocated array with increasing numbers from 1 to n.", () => {
105 | let input = new Array(6);
106 |
107 | expect(code.fillArrayIncreasing(input, input.length)).to.eql([1,2,3,4,5,6]);
108 | });
109 |
110 | it("12. Write a recursive function to determine if an array is palindrome.", () => {
111 | expect(code.isPalindrome([1,2,3,4,3,2,1])).to.equal(true);
112 | expect(code.isPalindrome([1,2,3,3,2,1])).to.equal(true);
113 | expect(code.isPalindrome([1,2,3,1,2,3])).to.equal(false);
114 | });
115 |
116 | it("13. Write a recursive function to flatten an array of array of numbers.", () => {
117 | let input = [1,2,[3,4,[5,6,7]]];
118 | let output = code.flattenArray(input);
119 |
120 | expect(output).to.eql([1,2,3,4,5,6,7]);
121 | });
122 | });
123 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/README-L1.md:
--------------------------------------------------------------------------------
1 | # Recursion — Part I
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [recursion-L1.js](ES6/src/recursion-L1.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner1.html](ES6/testRunner1.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 | Complete the following exercises. You may use the Helper Function technique.
26 |
27 | 1. Write a recursive function that prints the digits of an integer in reverse order.
28 | 2. Write a recursive function to convert an integer to a binary string.
29 | 3. Write a recursive function that formats any positive integer with commas
30 | 4. Write a recursive function to return a string with the number of "X"s indicated by n
31 | 5. Write a recursive function to print a left-aligned triangle with the number of lines indicated by n
32 | 6. Write a recursive function to print a left-aligned triangle upside down with the number of lines indicated by n
33 | 7. Write a recursive function to reverse an array in-place
34 | 8. Write a recursive function to determine if two arrays are equal
35 | 9. Write a recursive function that will return the position of the largest element in an array
36 | 10. Write a recursive function to determine if array is sorted (in increasing order)
37 | 11. Write a recursive function to fill a pre-allocated array with increasing numbers from 1 to n
38 | 12. Write a recursive function to determine if an array is palindrome
39 | 13. Write a recursive function to flatten an array
40 |
41 |
42 | ###### BONUS:
43 |
44 | * After solving these with the Helper Function technique, try again usin the Pure Recursion
45 | technique.
46 | * After that, try L0 again using Pure Recursion.
47 |
48 | ###### Critical Whiteboard Skills
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Recursion/README.md:
--------------------------------------------------------------------------------
1 | # Recursion
2 |
3 |
4 | #### Recursion — Introduction
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Recursion — Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
15 |
16 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/lib/consoleHook/consoleHook.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | function consoleHook_initialize() {
5 | let output = [];
6 | let _cl_ = console.log;
7 |
8 | console.log = function(value) {
9 | output.push(value);
10 | _cl_(value);
11 | };
12 |
13 | return {
14 | read: function() {
15 | return output.shift();
16 | },
17 |
18 | bufferLength: function() {
19 | return output.length;
20 | },
21 |
22 | flush: function() {
23 | output = [];
24 | },
25 |
26 | terminate: function() {
27 | console.log = _cl_;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/src/searching-L0-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/src/searching-L0.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/src/searching-L1-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/src/searching-L1.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 |
4 | };
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Searching - Warmups
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Searching - Warmups
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Searching - Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Searching - Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/tests/searchingTests-L0.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/tests/searchingTests-L0.js
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/ES6/tests/searchingTests-L1.js:
--------------------------------------------------------------------------------
1 |
2 | describe("Searching - Part I", () => {
3 |
4 | });
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/README-L0.md:
--------------------------------------------------------------------------------
1 | # Searching — Introduction
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [searching-L0.js](ES6/src/searching-L0.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 |
26 |
27 | ###### BONUS:
28 |
29 |
30 |
31 | ###### Critical Whiteboard Skills
32 |
33 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/README-L1.md:
--------------------------------------------------------------------------------
1 | # Sorting — Part I
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [searching-L0.js](ES6/src/searching-L0.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 |
26 |
27 | ###### BONUS:
28 |
29 |
30 |
31 | ###### Critical Whiteboard Skills
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Searching/README.md:
--------------------------------------------------------------------------------
1 | # Searching
2 |
3 |
4 | #### Searching — Introduction (coming soon)
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Searching — Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
15 |
16 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/lib/consoleHook/consoleHook.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | function consoleHook_initialize() {
5 | let output = [];
6 | let _cl_ = console.log;
7 |
8 | console.log = function(value) {
9 | output.push(value);
10 | _cl_(value);
11 | };
12 |
13 | return {
14 | read: function() {
15 | return output.shift();
16 | },
17 |
18 | bufferLength: function() {
19 | return output.length;
20 | },
21 |
22 | flush: function() {
23 | output = [];
24 | },
25 |
26 | terminate: function() {
27 | console.log = _cl_;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/src/sets-L0-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/src/sets-L0.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/src/sets-L1-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/src/sets-L1.js:
--------------------------------------------------------------------------------
1 |
2 | let L1 = function() {
3 |
4 | };
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/testRunner0-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Sets — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/testRunner0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Sets — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/testRunner1-SLN.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Sets — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/testRunner1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Sets — Part I
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/tests/setTests-L0.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmacademy/AlgoAcademy/ff97aa52eafc790b3517491079c24712bc9048c1/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/tests/setTests-L0.js
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/ES6/tests/setTests-L1.js:
--------------------------------------------------------------------------------
1 |
2 | describe("Sets - Part I", () => {
3 |
4 | });
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/README-L0.md:
--------------------------------------------------------------------------------
1 | # Sets — Introduction
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [sets-L0.js](ES6/src/sets-L0.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner0.html](ES6/testRunner0.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 |
26 |
27 | ###### BONUS:
28 |
29 |
30 |
31 | ###### Critical Whiteboard Skills
32 |
33 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/README-L1.md:
--------------------------------------------------------------------------------
1 | # Sets — Part I
2 |
3 |
4 | ###### Overview
5 |
6 |
7 |
8 | ###### Edge Cases
9 |
10 |
11 |
12 | ###### NOTES
13 |
14 |
15 |
16 | ###### This Exercise
17 |
18 |
19 | Open [sets-L1.js](ES6/src/sets-L1.js) and follow the prompts below to complete the exercise. Use
20 | the [testRunner1.html](ES6/testRunner1.html) file to run the tests and view your progress.
21 |
22 |
23 | ###### Objective
24 |
25 |
26 |
27 | ###### BONUS:
28 |
29 |
30 |
31 | ###### Critical Whiteboard Skills
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sets/README.md:
--------------------------------------------------------------------------------
1 | # Sets
2 |
3 |
4 | #### Sets — Introduction (coming soon)
5 |
6 | Let's do a few warm-ups.
7 |
8 | Open and complete [README-L0.md](README-L0.md)
9 |
10 |
11 | #### Sets — Level 1
12 |
13 | Open and complete [README-L1.md](README-L1.md)
14 |
15 |
16 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sorting/ES6/lib/consoleHook/consoleHook.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | function consoleHook_initialize() {
5 | let output = [];
6 | let _cl_ = console.log;
7 |
8 | console.log = function(value) {
9 | output.push(value);
10 | _cl_(value);
11 | };
12 |
13 | return {
14 | read: function() {
15 | return output.shift();
16 | },
17 |
18 | bufferLength: function() {
19 | return output.length;
20 | },
21 |
22 | flush: function() {
23 | output = [];
24 | },
25 |
26 | terminate: function() {
27 | console.log = _cl_;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sorting/ES6/src/sorting-L0-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = {
3 |
4 | };
5 |
6 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sorting/ES6/src/sorting-L0.js:
--------------------------------------------------------------------------------
1 |
2 | let L0 = function() {
3 |
4 | };
5 |
--------------------------------------------------------------------------------
/TechPrep - Part I Foundations/Javascript/V1.0/Sorting/ES6/src/sorting-L1-SLN.js:
--------------------------------------------------------------------------------
1 |
2 | class L1 {
3 | bubbleSort(input) {
4 | if (!input || !input.length) {
5 | return input;
6 | }
7 |
8 | let length = input.length;
9 | let count = 0;
10 |
11 | for (let pass=0; pass input[i+1]) {
14 | [input[i], input[i+1]] = [input[i+1], input[i]];
15 | count += 1;
16 | }
17 | }
18 | }
19 |
20 | return [input, count];
21 | }
22 |
23 |
24 |
25 | bubbleSortOptimized(input) {
26 | if (!input || !input.length) {
27 | return input;
28 | }
29 |
30 | let length = input.length;
31 | let count = 0;
32 |
33 | for (let pass=0; pass input[i+1]) {
38 | [input[i], input[i+1]] = [input[i+1], input[i]];
39 | sorted = false;
40 | count += 1;
41 | }
42 | }
43 |
44 | if (sorted) {
45 | break;
46 | }
47 | }
48 |
49 | return [input, count];
50 | }
51 |
52 |
53 |
54 | selectionSort(input) {
55 | let count = 0;
56 |
57 | for(var i = 0; i < input.length; i++, count++) {
58 | var min = i;
59 |
60 | for(var j = i+1; j < input.length; j++) {
61 | if(input[j] < input[min]) {
62 | min = j;
63 | count++;
64 | }
65 | }
66 |
67 | [input[i], input[min]] = [input[min], input[i]];
68 | }
69 |
70 | return [input, count];
71 | }
72 |
73 |
74 |
75 | insertionSort(input) {
76 | let length = input.length;
77 | let count = 0;
78 |
79 | for (let i=1; i=0 && input[j] > temp; j--) {
84 | input[j+1] = input[j];
85 | count++;
86 | }
87 |
88 | input[j+1] = temp;
89 | }
90 |
91 | return [input, count];
92 | }
93 |
94 |
95 |
96 | mergeSort(input) {
97 | if(input.length == 1 ) {
98 | return input;
99 | }
100 |
101 | let mid = input.length / 2;
102 | let left = input.slice(0, mid);
103 | let right = input.slice(mid);
104 |
105 | left = this.mergeSort(left);
106 | right = this.mergeSort(right);
107 |
108 | return this.merge(left, right);
109 | }
110 |
111 |
112 |
113 | merge(left, right) {
114 | let result=[];
115 | let leftIndex=0;
116 | let rightIndex=0;
117 |
118 | while(leftIndexright[rightIndex]) {
120 | result.push(right[rightIndex]);
121 | rightIndex++;
122 | }
123 | else {
124 | result.push(left[leftIndex]);
125 | leftIndex++;
126 | }
127 | }
128 |
129 | while(leftIndex input[i+1]) {
14 | [input[i], input[i+1]] = [input[i+1], input[i]];
15 | count += 1;
16 | }
17 | }
18 | }
19 |
20 | return [input, count];
21 | }
22 |
23 |
24 | bubbleSortOptimized(input) {
25 | if (!input || !input.length) {
26 | return input;
27 | }
28 |
29 | let length = input.length;
30 | let count = 0;
31 |
32 | for (let pass=0; pass input[i+1]) {
35 | [input[i], input[i+1]] = [input[i+1], input[i]];
36 | count += 1;
37 | }
38 | }
39 | }
40 |
41 | return [input, count];
42 | }
43 |
44 |
45 | selectionSort(input) {
46 | let count = 0;
47 |
48 | for(var i = 0; i < input.length; i++, count++) {
49 | var min = i;
50 |
51 | for(var j = i+1; j < input.length; j++) {
52 | if(input[j] < input[min]) {
53 | min = j;
54 | count++;
55 | }
56 | }
57 |
58 | [input[i], input[min]] = [input[min], input[i]];
59 | }
60 |
61 | return [input, count];
62 | }
63 |
64 |
65 | insertionSort(input) {
66 | let length = input.length;
67 | let count = 0;
68 |
69 | for (let i=1; i=0 && input[j] > temp; j--) {
74 | input[j+1] = input[j];
75 | count++;
76 | }
77 |
78 | input[j+1] = temp;
79 | }
80 |
81 | return [input, count];
82 | }
83 |
84 |
85 | mergeSort(input) {
86 | if(input.length == 1 ) {
87 | return input;
88 | }
89 |
90 | let mid = input.length / 2;
91 | let left = input.slice(0, mid);
92 | let right = input.slice(mid);
93 |
94 | left = this.mergeSort(left);
95 | right = this.mergeSort(right);
96 |
97 | return this.merge(left, right);
98 | }
99 |
100 |
101 | merge(left, right) {
102 | let result=[];
103 | let leftIndex=0;
104 | let rightIndex=0;
105 |
106 | while(leftIndexright[rightIndex]) {
108 | result.push(right[rightIndex]);
109 | rightIndex++;
110 | }
111 | else {
112 | result.push(left[leftIndex]);
113 | leftIndex++;
114 | }
115 | }
116 |
117 | while(leftIndex
2 |
3 |
4 | Sorting — Introduction
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |