Initial commit
This commit is contained in:
commit
41868ff6c7
7 changed files with 349 additions and 0 deletions
0
notes/fund-prog-3/2024-01-24.md
Normal file
0
notes/fund-prog-3/2024-01-24.md
Normal file
51
notes/fund-prog-3/some-sorts-2024-01-31.md
Normal file
51
notes/fund-prog-3/some-sorts-2024-01-31.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
# Some sorts
|
||||
|
||||
In pseudocode, but python syntax highlighting fits decently so that's what I'm using.
|
||||
|
||||
## Insertion sort (for shell sort)
|
||||
|
||||
```py
|
||||
InsertionSortForShell(array, start, gap)
|
||||
for i = start + gap to len(array) - 1 # inclusive
|
||||
j = i
|
||||
while (j - gap >= start) and (array[j] < array[j - gap])
|
||||
swap(array[j], array[j - gap])
|
||||
j = j - gap
|
||||
```
|
||||
|
||||
## Shell sort
|
||||
|
||||
```py
|
||||
ShellSort(array, gapList)
|
||||
for gap in gapList
|
||||
for i = = 0 to gap - 1
|
||||
InsertionSortForShell(array, i, gap)
|
||||
```
|
||||
|
||||
## Hibbard
|
||||
|
||||
2<sup>k</sup> - 1 where k is 1 to p where └ k<sup>p</sup> ┐ = N
|
||||
|
||||
## Pratt
|
||||
|
||||
For a Z-tuples for (0, 0) -> (k, k) create all the cartesian pairs
|
||||
|
||||
```txt
|
||||
(0, 0), (0, 1), (0, 2), ..., (0, k)
|
||||
(1, 0), (1, 1), (1, 2), ..., (1, k)
|
||||
(2, 0), (2, 1), (2, 2), ..., (2, k)
|
||||
...
|
||||
(k, 0), (k, 1), (k, 2), ..., (k, k)
|
||||
```
|
||||
|
||||
## Naive gap values
|
||||
|
||||
N/2<sup>k</sup>, k = 1 to p where N/2<sup>p</sup> => 1
|
||||
|
||||
```py
|
||||
for i, j in S
|
||||
value = 2<sup>i</sup> * 3<sup>j</sup>
|
||||
gapList.append(value)
|
||||
sort(gapList)
|
||||
gapValues[0 ... N]
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue