Skip to content

Commit 6519336

Browse files
committed
docs: rewrite descriptions
1 parent 1f44607 commit 6519336

12 files changed

+92
-57
lines changed

levels/bubble_sort.gd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
BUBBLE SORT
33
44
5-
Bubble sort iterates through the array and looks at each pair of
6-
elements, swapping them if they are out of order. When it has gone
7-
through the entire array without swapping a single pair, it has
8-
finished. Though simple to understand, bubble sort is hopelessly
9-
inefficient on all but the smallest of arrays.
5+
Bubble sort looks at consecutive pairs of elements and swaps them if
6+
they are out of order, finishing when it has gone through the whole
7+
array from beginning to end without a single swap. The actual level
8+
contains an optimization that skips over elements guaranteed to be
9+
already in place.
10+
11+
Due to its simplicity, it is commonly taught as the first sorting
12+
algorithm students learn in computer science classes, but is rarely used
13+
in real life because it is slow on large data and other simple quadratic
14+
algorithms like insertion sort perform better.
1015
1116
1217
If the two highlighted elements are out of order, hit LEFT ARROW to swap

levels/cocktail_sort.gd

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
COCKTAIL SORT
33
44
5-
Cocktail shaker sort is a variation of bubble sort that
6-
alternates going backwards and forwards.
5+
Cocktail sort is a variation of bubble sort that alternates going
6+
backwards and forwards. The actual level contains an optimization that
7+
skips over elements guaranteed to be already in place.
8+
9+
Because it is bidirectional, it is slightly faster than bubble sort, but
10+
is still quadratic and therefore not used on large data.
711
812
913
If the two highlighted elements are out of order, hit LEFT ARROW to swap
@@ -22,10 +26,8 @@ def cocktail_sort(a):
2226
if array[i] > array[i + 1]:
2327
a.swap(i, i + 1)
2428
swapped = true
25-
2629
if not swapped:
2730
break
28-
2931
swapped = false
3032
for i in range(len(a) - 1, 0, -1)
3133
if a[i - 1] > a[i]:

levels/comb_sort.gd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
COMB SORT
33
44
5-
Comb sort is a variant of bubble sort that operates on gapped arrays.
5+
Comb sort is a variant of bubble sort that compares elements a certain
6+
gap apart instead of consecutive elements. This gap is divided after
7+
every pass by an experimentally determined optimal factor of about 1.3.
8+
Once the gap becomes 1, comb sort becomes a regular bubble sort.
9+
10+
This allows comb sort to get rid of small values near the end more
11+
quickly, which turns out to be the bottleneck in bubble sort, but still
12+
has a quadratic worst case.
613
714
815
If the two highlighted elements are out of order, hit LEFT ARROW to swap
@@ -17,6 +24,7 @@ def comb_sort(a):
1724
gap = len(a)
1825
swapped = true
1926
while gap != 1 or swapped:
27+
swapped = false
2028
gap = max(gap / 1.3, 1)
2129
for i in range(len(a) - gap):
2230
if a[i] > a[i + gap]:

levels/comparison_sort.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const EFFECTS = {
1212

1313
const DISABLE_TIME = 1.0
1414
var NAME = _get_header().split(" ")[0]
15-
var DESCRIPTION = _get_header().split(" ")[1]
16-
var CONTROLS = _get_header().split(" ")[2]
15+
var DESCRIPTION = _get_header().split(" ")[1].replace(" ", "\n\n")
16+
var CONTROLS = _get_header().split(" ")[-1]
1717

1818
var array: ArrayModel
1919

levels/cycle_sort.gd

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
CYCLE SORT
33
44
5-
Cycle sort repeatedly counts the number of elements less than the first
6-
and swaps it with that index until the smallest element is reached. Then
7-
it does this process starting at the next out-of-place element.
5+
Cycle sort looks at the first element and finds its correct final
6+
position by counting the number of elements smaller than it. Then it
7+
saves the element at that index, writes the first element there, and
8+
repeats the process with the saved element. For the sake of
9+
demonstration, in the actual level, swaps are used instead.
810
11+
This results in a quadratic runtime but gives it the special property
12+
of being optimal in the number of writes to the array. This makes cycle
13+
sort useful in storage types where writes are very expensive or reduce
14+
its lifespan.
915
10-
If the highlighted element is less than the pointer, hit LEFT ARROW.
11-
Otherwise, hit RIGHT ARROW.
16+
17+
If the highlighted element is less than the element below the blue
18+
pointer, hit LEFT ARROW. Otherwise, hit RIGHT ARROW.
1219
"""
1320

1421
class_name CycleSort

levels/insertion_sort.gd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
INSERTION SORT
33
44
5-
Insertion sort goes through the array and inserts each
6-
element into its correct position. It is most similar to how most people
7-
would sort a deck of cards. It is also slow on large arrays but it is
8-
one of the faster quadratic algorithms. It is often used to sort smaller
9-
subarrays in hybrid sorting algorithms.
5+
Insertion sort goes through the array and inserts each element into its
6+
correct place, like how most people would sort a hand of playing cards.
107
8+
It is one of the fastest quadratic algorithms in practice and is
9+
efficient on small or almost sorted data. It is also simple, stable, and
10+
in-place. For these reasons it is sometimes used within faster divide
11+
and conquer algorithms when the array has been divided to a small size.
1112
12-
Hit LEFT ARROW to swap the two highlighted elements as long as they are
13-
out of order. When this is no longer the case, hit RIGHT ARROW to
14-
advance.
13+
14+
If the two highlighted elements are out of order, hit LEFT ARROW to swap
15+
them. Otherwise, hit RIGHT ARROW to continue.
1516
"""
1617

1718
class_name InsertionSort

levels/merge_sort.gd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
MERGE SORT
33
44
5-
Merge sort is an efficient sorting algorithm that splits the array into
6-
single-element chunks. Then it merges each pair of chunks until only one
7-
sorted chunk is left by repeatedly choosing the smaller element at the
8-
head of each chunk and moving the head back. However, it needs an entire
9-
array's worth of auxiliary memory.
5+
Merge sort merges subarrays of increasing size by setting a pointer to
6+
the head of each half. Then it repeatedly copies the smaller pointed
7+
element and increments that side's pointer. When one side is exhausted,
8+
it copies the rest of the other side and overwrites the two halves with
9+
the merged copy.
1010
1111
1212
Press the ARROW KEY corresponding to the side that the smaller
13-
highlighted element is on. If you've reached the end of one side, press
14-
the other side's ARROW KEY.
13+
highlighted element is on or the non-exhausted side.
1514
"""
1615

1716
class_name MergeSort
@@ -34,6 +33,7 @@ def merge_sort(a):
3433
merged.append(a[i])
3534
i += 1
3635
a[begin:begin + size] = merged
36+
size *= 2
3737
"""
3838
const ACTIONS = {
3939
"LEFT": "Left",

levels/odd_even_sort.gd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
ODD-EVEN SORT
33
44
5-
Odd-even sort is a variant of bubble sort that alternates on elements at
6-
odd and even indices.
5+
Odd-even sort is a variant of bubble sort that alternates between
6+
comparing consecutive odd-even and even-odd indexed pairs.
7+
8+
It is not of much use on a single processor as it is designed for
9+
parallel processors, which can perform every comparison in a single pass
10+
at the same time, thus making the algorithm much more efficient.
711
812
913
If the two highlighted elements are out of order, hit LEFT ARROW to swap

levels/quick_sort.gd

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
QUICKSORT
33
44
5-
Quicksort designates the last element as the pivot and puts everything
6-
less than the pivot before it and everything greater after it. This
7-
partitioning is done by iterating through the array while keeping track
8-
of a pointer initially set to the first element. Every time an element
9-
less than the pivot is encountered, it is swapped with the pointed
10-
element and the pointer moves forward. At the end, the pointer and pivot
11-
are swapped, and the process is repeated on the left and right halves.
5+
Quicksort designates the last element as the pivot and sets a pointer to
6+
the first element. Then it iterates through the array. Every time an
7+
element smaller than the pivot is encountered, that element is swapped
8+
with the pointed element and the pointer is incremented. Once the pivot
9+
is reached, it is swapped with the pointed element and this process is
10+
recursively repeated on the left and right halves.
11+
12+
Quicksort competes with other linearithmic algorithms like merge sort,
13+
which it is faster than at the tradeoff of stability.
1214
1315
1416
If the highlighted element is less than the pivot or the pivot has been
15-
reached, press LEFT ARROW to swap it with the pointer. Otherwise, press
16-
RIGHT ARROW to move on.
17+
reached, press LEFT ARROW. Otherwise, press RIGHT ARROW.
1718
"""
1819

1920
class_name QuickSort

levels/selection_sort.gd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
SELECTION SORT
33
44
5-
Selection sort incrementally builds a sorted array by repeatedly looking
6-
for the smallest element and swapping it onto the end of the sorted
7-
portion of the array, which initially starts with size zero but grows
8-
after each round. It is faster than an unoptimized bubble sort but
9-
slower than insertion sort.
5+
Selection sort incrementally builds a sorted subarray by finding the
6+
smallest unprocessed element and putting it in place.
107
8+
It is not very useful in real life as it is beat by insertion sort.
9+
However, it has the distinguishing feature of making the least number
10+
of swaps in the worst case.
1111
12-
Keep on hitting RIGHT ARROW until you encounter an element that is
13-
smaller than the left highlighted element, then hit LEFT ARROW and
14-
repeat.
12+
13+
If the two highlighted elements are out of order, hit LEFT ARROW to swap
14+
them. Otherwise, hit RIGHT ARROW to continue.
1515
"""
1616

1717

levels/shell_sort.gd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
SHELL SORT
33
44
5-
Shell sort is a variation of insertion sort that sorts arrays separated
6-
by gaps.
5+
Shell sort is a variant of insertion sort that compares elements a
6+
certain gap apart instead of consecutive elements. This gap is divided
7+
by 2 after every pass. Once the gap becomes 1, shell sort becomes a
8+
regular insertion sort.
79
10+
This allows the final pass of insertion sort to avoid having to move
11+
elements long distances. However, it still has a quadratic worst case,
12+
which can be reduced with more complex gap sequences.
813
9-
Hit LEFT ARROW to swap the two highlighted elements as long as they are
10-
out of order. When this is no longer the case, hit RIGHT ARROW to
11-
advance.
14+
15+
If the two highlighted elements are out of order, hit LEFT ARROW to swap
16+
them. Otherwise, hit RIGHT ARROW to continue.
1217
"""
1318

1419
class_name ShellSort

scenes/levels.tscn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ margin_top = 20.0
7171
margin_right = 596.0
7272
margin_bottom = 593.0
7373
size_flags_vertical = 3
74-
text = "This is a description for the level in the form of psuedocode.
74+
text = "This is a description of the algorithm in plain English.
75+
76+
This explains the relevance of the algorithm in computer science.
7577
7678
def algorithm(parameter):
7779
return result"

0 commit comments

Comments
 (0)