Top Level Namespace
Defined in:
Method Summary
- binary_search(arr : Array(U), left : Int32, right : Int32, value : U) forall U
- binary_search(arr : Array(U), value : U) forall U
-
bubble_sort(arr : Array(U)) forall U
Optimized version of the bubble sort algorithm.
- heap_sort(arr : Array(U)) forall U
-
insertion_sort(arr : Array(U)) forall U
Crystal implementation of the insertion sort algorithm.
-
make_heap(arr : Array(U), n : Int32, i : Int32) forall U
Make a subtree into a heap of size
n
rooted at indexi
. -
merge_sort(arr : Array(U)) forall U
Crystal implementation of the merge sort algorithm, which divides an array into 2 halves and takes a divide and conquer approach.
Method Detail
Optimized version of the bubble sort algorithm. The standard algorithm always runs in O(n^2) time even if the array is sorted. This one will stop running if it realizes that the array is already sorted.
Crystal implementation of the insertion sort algorithm. This algorithm always has a time complexity of O(n^2) so it's certainly not the most efficient, but it is super easy to implement.
Make a subtree into a heap of size n
rooted at index i
.
Crystal implementation of the merge sort algorithm, which divides an array into 2 halves and takes a divide and conquer approach. Time complexity of this algorithm isn't great, since it always splits the array regardless of size, sorts them individually (and not in parallel), and then takes linear time to merge them back together.