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
+60-63Lines changed: 60 additions & 63 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,6 @@ icon: material/code-tags
4
4
5
5
# Algorithms
6
6
7
-
!!! danger
8
-
9
-
This is a work in progress. Some information may be incorrect or outdated
10
-
11
7
---
12
8
13
9
@@ -340,7 +336,7 @@ There are problems documented everywhere in this site. This location will detail
340
336
341
337
[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
342
338
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))
339
+
> 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))
344
340
345
341
346
342
!!! note "Game"
@@ -401,12 +397,13 @@ Swaps are counted with: $O(n)$
401
397
402
398
### Quick Sort
403
399
404
-
Quick Sort uses a recursivedivide and conquer method.
400
+
Quick Sort uses a [recursive](#recursion)[divide and conquer](#divide-and-conquer) method.
3. Do quick-sort on items left of original quick-sort
416
413
4. Do quick-sort on items right of original quick-sort
417
414
418
-
Worst case:
415
+
Worst case (*consider how the pivot and/or the input would cause this*):
419
416
420
417
$$O(n^2)$$
421
418
@@ -433,22 +430,27 @@ $$O(n)$$
433
430
434
431
A commonly used [divide and conquer](#divide-and-conquer) sorting algorithm. In fact it's probably one of the best examples of divide and conquer there is. The fundamental procedure of merge sort is to split apart the input (dividing) and solve each of those parts individually (conquoring) and then building the solution back together. This is a key difference between divide and conquer and [decrease and conquer](#decrease-and-conquer) as the input is being *divided* into sub-problems that are **all** solved, instead of *decreasing* the problem by discarding parts that don't need to be solved.
435
432
433
+
Merge sort runs in $O(n \, \log n)$ at worst case. Although this is considered as one of the fastest sorting algorithms, there are alternitives outside the study design that can run in $O(n+k)$ and $O(nk)$ (radix and counting sort) with fancy space tradeoffs.
434
+
436
435
## Searching
437
436
438
437
### linear Search
439
438
440
439
Most simple, checks elements left to right until the item is found.
441
440
442
-
Average case:
441
+
Worst case:
443
442
444
-
$$\Theta\left(\frac{n}{2}\right)$$
443
+
$$O(n)$$
444
+
445
+
It's not in the study design, but an average case of $\Theta\left(\frac{n}{2}\right)$ and a best case of $\Omega(1)$ are quite intuitive
445
446
446
447
### Binary Search
447
448
448
-
- Recursivedivide and conquer.
449
-
-**Must be sorted**
449
+
-[Recursive](#recursion)[divide and conquer](#divide-and-conquer).
450
+
-**Input must be sorted**
450
451
451
452
Order:
453
+
452
454
1. Select item from middle of array
453
455
1. If matches: halt
454
456
2. if item < what your looking for: search right side
@@ -458,7 +460,7 @@ Worst case:
458
460
459
461
$$O(\log_2 n) \implies O(\log n)$$
460
462
461
-
*Note that the number of searches in worst case is $\lfloor \log_2(n)\rfloor +1$*
463
+
*Note that the number of searches in worst case is $\lfloor \log_2(n)\rfloor +1$*. This is still pretty good. If you had to binary search all the atoms in the uinverse you would only have to use 267 operations
- Use [Divide and Conquer](#divide-and-conquer) when you **don't have overlapping sub problems**
471
473
- Use [Decrease and Conquer](#decrease-and-conquer) when you can **discard/ignore parts of the input** entirely
472
474
- Use [Dynamic Programming](#dynamic-programming) when you **do have overlapping sub problems**
473
-
- Use [Backtracking](#backtracking) when you can solve parts of the problem along the way and re-trace your steps when you make a mistake
474
-
- Use [Greedy](#greedy) when you see an optimisation that involves disregarding future consequences (which shoudn't normally exist in greedy implimentations)
475
+
- Use [Backtracking](#backtracking) when you can solve parts of the problem along the way and **re-trace your steps** when you make a mistake
476
+
- Use [Greedy](#greedy) when you see an optimisation that involves **disregarding future consequences** (which shoudn't normally exist in greedy implimentations)
475
477
- Use [Brute Force](#brute-force) when you can't do it any other way.
476
478
477
-
Both iterative and recursive algorithm design patterns in general are also part of the study design.
479
+
Both iterative and recursive algorithm design patterns in general are also part of the study design.
478
480
479
-
Both [backtracking](#backtracking) and [greedy](#greedy) algorithms types are debated to be design patterns or not. For the sake of VCE Algorithimics, the study design classes both backtracking and greedy classifications as design patterns in key knowledge and key skill markers:
481
+
Both [backtracking](#backtracking) and [greedy](#greedy) algorithms types are debated to be design patterns or not. For the sake of VCE Algorithimics, the study design classes both backtracking and greedy classifications as design patterns in key knowledge and key skill markers:
480
482
481
-
> - Apply the divide and conquer, dynamic programming and backtracking design patterns to design algorithms and recognise their usage within given algorithms
483
+
> - Apply the divide and conquer, dynamic programming and backtracking design patterns to design algorithms and recognise their usage within given algorithms
482
484
483
-
> - Characteristics and suitability of the brute-force search and greedy algorithm design patterns
485
+
> - Characteristics and suitability of the brute-force search and greedy algorithm design patterns
484
486
485
-
The study design also doesn't explicityly list '*Decrease and Conquer*' as a design pattern, but it does list both iterative and recursive patterns which can be applicable to decrease and conquer.
487
+
The study design also doesn't explicityly list '*Decrease and Conquer*' as a design pattern, but it does list both iterative and recursive patterns which can be applicable to decrease and conquer.
486
488
487
489
#### Brute Force
488
490
@@ -547,7 +549,7 @@ Examples:
547
549
548
550
!!! info
549
551
550
-
In general, DP solutions are used to maximise or minimise. Knapsack or coin change.
552
+
In general, DP solutions are used to maximise or minimise. Like Knapsack or [coin change](#coin-change-algorithm).
551
553
552
554
They store previous answers to stop the repetition of overlapping sub-problems
553
555
@@ -590,7 +592,7 @@ For example (TSP):
590
592
591
593
#### Evolutions
592
594
593
-
Algorithm will repeatedly evaluate all the tours in the “dish”
595
+
Algorithm will repeatedly evaluate all the tours in the "dish"
594
596
- throw out the longer tours
595
597
- replace them with copies of the better tours
596
598
- each copy is slightly different than the tour it was copied from
@@ -648,7 +650,6 @@ When stuck at:
648
650
- One can prove: If temperature decreases slowly enough, then simulated annealing search will find a global optimum with probability approaching one, which means you are certain of your solution. However, this usually takes impractically long.
@@ -821,8 +823,6 @@ So, when proving by induction, do the following:
821
823
822
824
---
823
825
824
-
From seminar
825
-
826
826
Consider a **Loop invariant**. Which is some condition that is true before and after each loop. Then use that to build on a True solution / proof
827
827
828
828
Examples:
@@ -888,7 +888,7 @@ He was wrong, see Gödel's Incompleteness Theorem (Not in 2023 course design)
888
888
889
889
The main goal of Hilbert's program was to provide secure foundations for all mathematics. In particular this should include:
890
890
891
-
-A formulation of all mathematics; in other words all mathematical statements should be written in a precise[formal language](https://en.wikipedia.org/wiki/Formal_language "Formal language"), and manipulated according to well defined rules.
891
+
-A formulation of all mathematics; in other words all mathematical statements should be written in a precise[formal language](https://en.wikipedia.org/wiki/Formal_language "Formal language"), and manipulated according to well defined rules.
892
892
- Completeness: a proof that all true mathematical statements can be proved in the formalism.
893
893
- Consistency: a proof that no contradiction can be obtained in the formalism ofmathematics. This consistency proof should preferably use only "finitistic" reasoning about finite mathematical objects.
894
894
- Conservation: a proof that any result about "real objects" obtained using reasoning about "ideal objects" (such as uncountable sets) can be proved without using ideal objects.
@@ -920,6 +920,10 @@ An equivalent of the [Turing machine](computer-science.md#turing-machine) invent
920
920
921
921
#### Halting problem
922
922
923
+
!!! important
924
+
925
+
In the current 2024 study design
926
+
923
927
Machine $H$ determines if the input $I$ (program and program input) will halt or not.
- Kind of like the evaluation function for the Wordle Solver
1394
1395
1395
1396
Essentially, it takes several inputs and multiplies them by their bias to be matched against a threshold or bias. The result of the bias comparison is then the resultant binary output. Which is: True or false, Yes or No, `0`, `1` etc
1396
1397
@@ -1478,43 +1479,39 @@ The inputs are only provided to the network, and it must learn on its own (self
1478
1479
### Conditions
1479
1480
1480
1481
A condition must have the following properties:
1482
+
1481
1483
- It must be a logical statement, i.e. one that can either be true or false, and
1482
1484
- It must be possible to know at the time the algorithm is being followed whether the statement is true or false.
1483
1485
1484
1486
### Abstractions
1485
1487
1486
1488
Changing real items, into abstracted representations (E.g. Intersections-> nodes on a graph).
1487
1489
1488
-
#### Signifiers
1489
-
1490
-
1491
-
1492
-
1493
1490
### Coin Change algorithm
1494
1491
1495
1492
```python title="DP Coin Change in python"
1496
1493
def change(change, denominations):
1497
-
'''Outputs number of coins required to complete give the `change`'''
1498
-
# solution/dp array
1499
-
y = [1]
1500
-
for runninc in range(2, change+1):
1501
-
# Add minimum solution to y
1502
-
y.append(runninc)
1503
-
for coin in denominations:
1504
-
# The new amount of change to work with
1505
-
newdif = runninc-coin
1506
-
if newdif > 0:
1507
-
# There's still some change left
1508
-
if y[newdif-1]+1 < runninc:
1509
-
# If the coins needed for the new change is better then the minimum
1510
-
# The +1 implies we have already used a `coin`
1511
-
y[runninc-1] = y[newdif-1]+1
1512
-
elif newdif == 0:
1513
-
# This has solved this iteration of change calculation
1514
-
y[runninc-1] = 1
1515
-
# Return last value
1516
-
print(y)
1517
-
return y[-1]
1494
+
'''Outputs number of coins required to complete give the `change`'''
1495
+
# solution/dp array
1496
+
y = [1]
1497
+
for runninc in range(2, change+1):
1498
+
# Add minimum solution to y
1499
+
y.append(runninc)
1500
+
for coin in denominations:
1501
+
# The new amount of change to work with
1502
+
newdif = runninc-coin
1503
+
if newdif > 0:
1504
+
# There's still some change left
1505
+
if y[newdif-1]+1 < runninc:
1506
+
# If the coins needed for the new change is better then the minimum
1507
+
# The +1 implies we have already used a `coin`
1508
+
y[runninc-1] = y[newdif-1]+1
1509
+
elif newdif == 0:
1510
+
# This has solved this iteration of change calculation
Copy file name to clipboardExpand all lines: docs/computer-science.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -408,7 +408,7 @@ A [Turing machine](#turing-machine) that follows fixed rules. **A natural or rea
408
408
409
409
Can solve NP problems?
410
410
411
-
A theoretical [Turing machine](#turing-machine) whose governing rules specify more than one possible action when in some given situations. That is, an NTM's next state is_not_completely determined by its action and the current symbol it sees, unlike a[Deterministic Turing machine](#deterministic-turing-machine)
411
+
A theoretical [Turing machine](#turing-machine) whose governing rules specify more than one possible action when in some given situations. That is, an NTM's next state is_not_completely determined by its action and the current symbol it sees, unlike a[Deterministic Turing machine](#deterministic-turing-machine)
0 commit comments