You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/algorithms.md
+41-37Lines changed: 41 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,9 +49,6 @@ The solution is guaranteed to give the correct answer all of the time for the sp
49
49
50
50
Actions are performed from top to bottom.
51
51
52
-
---
53
-
54
-
55
52
### Computability
56
53
57
54
A problem is computable if it is able to be [modelled](#models-of-computation) on a Turing machine (or equivalent), and solved with unlimited resources in finite time.
@@ -94,13 +91,13 @@ How do we effectively communicate the design of our Algorithms to others for sol
94
91
95
92
With:
96
93
97
-
- Narratives – descriptions / essays
98
-
- Process Flows – diagrams/graphs/flowcharts
99
-
- Scenario analysis – giving possible interpretations / alternative developments
100
-
- System maps – groups information together in hierarchies
101
-
- Concept Maps – shows relationships between connected entity
102
-
- Prototypes – make a smaller model of the overall problem
103
-
- Specifications – details of what criteria need to be met
94
+
- Narratives - descriptions / essays
95
+
- Process Flows - diagrams/graphs/flowcharts
96
+
- Scenario analysis - giving possible interpretations / alternative developments
97
+
- System maps - groups information together in hierarchies
98
+
- Concept Maps - shows relationships between connected entity
99
+
- Prototypes - make a smaller model of the overall problem
100
+
- Specifications - details of what criteria need to be met
104
101
105
102
106
103
## Modularity
@@ -120,7 +117,7 @@ When you can simplify it (with modules):
The names of these steps are not really important. It's more important to remember how they work
151
+
153
152
### Selection step *( if )*
154
153
155
154
A selection step must have these 2 components:
156
155
157
156
- A block of steps that may or may not be followed (such as make your lunch, and
158
-
- A [condition](#conditions), i.e. a **statement that can either be true or false** (such as you have an Algorithms class today), which determines whether the block of steps should be followed. The block should be followed if the statement is true.
157
+
- A [condition](#conditions), i.e. a **statement that can either be true or false** (such as "you have an Algorithms class today"), which determines whether the block of steps should be followed. The block should be followed if the statement is true.
159
158
160
159
The syntax we will use looks like this:
161
160
@@ -218,7 +217,7 @@ go outside
218
217
219
218
### BEGIN/END
220
219
221
-
BEGIN and END markers are used to define the start and end of blocks
220
+
BEGIN and END markers are ussually used to define the start and end of blocks in psuedocode
222
221
223
222
```js
224
223
IF it is raining
@@ -246,7 +245,7 @@ go outside
246
245
247
246
### Numbered steps
248
247
249
-
This method is old and outdated. It is not really used in any modern programming languages or algorithms. It doesn't even define blocks.
248
+
This method is old and outdated. It is not really used in any modern programming languages or algorithms. It doesn't even define blocks. You might see something like this in assembly though
250
249
251
250
```js
252
251
Step 1:IF it is not raining GOTO step 4
@@ -268,7 +267,8 @@ Loop for a fixed `n` amount of times.
268
267
`n` can be assigned during algorithm, it does not need to be known before starting.
269
268
270
269
```js
271
-
get a bag DO6TIMES
270
+
get a bag
271
+
DO6TIMES
272
272
{
273
273
pick up a doughnut put it in the bag
274
274
}
@@ -280,7 +280,7 @@ put the bag on the shelf
280
280
281
281
### Conditional iteration
282
282
283
-
Loop while ([condition](#conditions)). The loop runs while a condition is met
283
+
Loop while ([condition](#conditions)) is true. The loop runs while a condition is met and checks the condition before it runs the first time, and at the end of each iteration
284
284
285
285
```js
286
286
WHILE (condition)
@@ -290,53 +290,57 @@ WHILE (condition)
290
290
```
291
291
292
292
Conditional iteration includes the following:
293
+
293
294
-`DO ... WHILE`
294
-
- "Testing at end"
295
-
- "Repeat until" (reverse bool)
296
-
- Do loop once, then continue while condition is met.
297
-
-`WHILE`
298
-
- "Testing at end"
299
-
- Do loop while condition is true.
295
+
- Same as a while loop, but assume the condition is true for the first rum
296
+
297
+
-`REPEAT UNTIL`
298
+
- Run while condition is false. Ussually skips inital condition check like a `DO WHILE` loop
300
299
301
300
### Collection iterations
302
301
303
302
Iterate over collection such as a list with a buffer variable
304
303
305
304
```js
306
-
FOR i INarr(alphabet)
305
+
FOR i INlist(alphabet)
307
306
{
308
-
PRINT i
307
+
PRINT i// (1)
309
308
}
310
-
311
-
>>> abcdef...
312
309
```
313
310
311
+
1. Outputs something like `abcdef...`
312
+
314
313
---
315
314
316
315
## Variables
317
316
318
317
Assigned via:
319
318
320
319
- $x := y$
321
-
- $x = y$ (Unconventional and discouraged)
322
320
- $x \leftarrow y$
321
+
- $x = y$ (Unconventional and discouraged for pseudocode)
322
+
323
323
324
-
See [Variables](computer-science.md#variables)
324
+
See [Computer Science > Variables](computer-science.md#variables)
325
325
326
326
---
327
327
328
328
329
329
## Famous problems
330
330
331
-
There are problems documented everywhere in this page. I just needed a spot to put TSP
331
+
There are problems documented everywhere in this site. This location will detail ones that are not assiciated with other sections
332
+
333
+
!!! note
334
+
335
+
> TODO Please add links to other problems here
332
336
333
337
### Travelling salesmen problem
334
338
335
-
[There are $\frac{!(n-1)}{2}$ possible routes](https://youtu.be/GiDsjIBOVoA?t=194) for a [complete graph](graphs.md#complete-graphs) input. The division of two is to eliminate the other half of paths that go in the reverse order
339
+
*How does a salesman get to `n` houses along a route in a single round trip [Hamiltonian Circuit](graphs.md#hamiltonian-circuit)in the shortest distance possible*
336
340
337
-
> The number of different Hamiltonian cycles in a complete undirected graph on n vertices is $\frac{(n-1)!}{2}$ and in a complete directed graph on n vertices is $(n– 1)!$. These counts assume that cycles that are the same apart from their starting point are not counted separately. ([source](https://en.wikipedia.org/wiki/Hamiltonian_path#Properties))
341
+
[There are $\frac{!(n-1)}{2}$ possible routes](https://youtu.be/GiDsjIBOVoA?t=194) for a [complete graph](graphs.md#complete-graphs) input. The division of two is to eliminate the other half of paths that go in the reverse order
338
342
339
-
Also, I'm putting this here as well:
343
+
> The number of different Hamiltonian cycles in a complete undirected graph on n vertices is $\frac{(n-1)!}{2}$ and in a complete directed graph on n vertices is $(n- 1)!$. These counts assume that cycles that are the same apart from their starting point are not counted separately. ([source](https://en.wikipedia.org/wiki/Hamiltonian_path#Properties))
340
344
341
345
342
346
!!! note "Game"
@@ -379,21 +383,21 @@ Big $O$ notation:
379
383
Selection sort goes through the whole list, finding the smallest item and moving it to the front.
380
384
381
385
Order:
386
+
382
387
1. Sort through and find smallest item
383
388
- Move that item to the front
384
389
2. Sort through the array from second element
385
390
- Check every item to find the next smallest element
386
391
3. Add the element in front of the first smallest element
387
392
4. Continue this on the next element for the rest of the list.
388
393
389
-
Comparisons of:
390
-
*Best and worst case*
394
+
Comparisons of:[^selection-sort-time]
391
395
392
-
$$O(n^2)$$
396
+
$$O(n^2)$$
393
397
394
-
Swaps of:
398
+
Swaps are counted with: $O(n)$
395
399
396
-
$$O(n)$$
400
+
[^selection-sort-time]: Best and worst case have the same complexity
0 commit comments