Skip to content

Commit 4f5d387

Browse files
committed
Minor fixed. Up to selection sort
1 parent 40d5ca8 commit 4f5d387

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

docs/algorithms.md

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ The solution is guaranteed to give the correct answer all of the time for the sp
4949

5050
Actions are performed from top to bottom.
5151

52-
---
53-
54-
5552
### Computability
5653

5754
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
9491

9592
With:
9693

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
104101

105102

106103
## Modularity
@@ -120,7 +117,7 @@ When you can simplify it (with modules):
120117
y = sum(X)
121118
```
122119

123-
An examples of a function `pay_emplyee`
120+
Examples methods/functions of `pay_employee`
124121

125122
<img src="images/Pasted image 20220426141508.png" alt="Pasted image 20220426141508">
126123

@@ -150,12 +147,14 @@ If you don't pre-compute:
150147

151148
## Steps
152149

150+
The names of these steps are not really important. It's more important to remember how they work
151+
153152
### Selection step *( if )*
154153

155154
A selection step must have these 2 components:
156155

157156
- 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.
159158

160159
The syntax we will use looks like this:
161160

@@ -218,7 +217,7 @@ go outside
218217

219218
### BEGIN/END
220219

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
222221

223222
```js
224223
IF it is raining
@@ -246,7 +245,7 @@ go outside
246245

247246
### Numbered steps
248247

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
250249

251250
```js
252251
Step 1: IF it is not raining GOTO step 4
@@ -268,7 +267,8 @@ Loop for a fixed `n` amount of times.
268267
`n` can be assigned during algorithm, it does not need to be known before starting.
269268

270269
```js
271-
get a bag DO 6 TIMES
270+
get a bag
271+
DO 6 TIMES
272272
{
273273
pick up a doughnut put it in the bag
274274
}
@@ -280,7 +280,7 @@ put the bag on the shelf
280280

281281
### Conditional iteration
282282

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
284284

285285
```js
286286
WHILE (condition)
@@ -290,53 +290,57 @@ WHILE (condition)
290290
```
291291

292292
Conditional iteration includes the following:
293+
293294
- `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
300299

301300
### Collection iterations
302301

303302
Iterate over collection such as a list with a buffer variable
304303

305304
```js
306-
FOR i IN arr(alphabet)
305+
FOR i IN list(alphabet)
307306
{
308-
PRINT i
307+
PRINT i // (1)
309308
}
310-
311-
>>> abcdef...
312309
```
313310

311+
1. Outputs something like `abcdef...`
312+
314313
---
315314

316315
## Variables
317316

318317
Assigned via:
319318

320319
- $x := y$
321-
- $x = y$ (Unconventional and discouraged)
322320
- $x \leftarrow y$
321+
- $x = y$ (Unconventional and discouraged for pseudocode)
322+
323323

324-
See [Variables](computer-science.md#variables)
324+
See [Computer Science > Variables](computer-science.md#variables)
325325

326326
---
327327

328328

329329
## Famous problems
330330

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
332336

333337
### Travelling salesmen problem
334338

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*
336340

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
338342

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))
340344
341345

342346
!!! note "Game"
@@ -379,21 +383,21 @@ Big $O$ notation:
379383
Selection sort goes through the whole list, finding the smallest item and moving it to the front.
380384

381385
Order:
386+
382387
1. Sort through and find smallest item
383388
- Move that item to the front
384389
2. Sort through the array from second element
385390
- Check every item to find the next smallest element
386391
3. Add the element in front of the first smallest element
387392
4. Continue this on the next element for the rest of the list.
388393

389-
Comparisons of:
390-
*Best and worst case*
394+
Comparisons of:[^selection-sort-time]
391395

392-
$$O(n^2)$$
396+
$$O(n^2)$$
393397

394-
Swaps of:
398+
Swaps are counted with: $O(n)$
395399

396-
$$O(n)$$
400+
[^selection-sort-time]: Best and worst case have the same complexity
397401

398402
### Quick Sort
399403

0 commit comments

Comments
 (0)