Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BubbleSort ¶
func BubbleSort[T number](arr []T) []T
BubbleSort performs an in-place bubble sort on a slice of numeric values. It implements the bubble sort algorithm which repeatedly steps through the slice, compares adjacent elements and swaps them if they are in the wrong order. The function doesn't return new slice, but it sorts the slice in-place. Time Complexity: O(n²) where n is the length of the slice Space Complexity: O(1) as it sorts in-place
func HeapSort ¶
func HeapSort[T number](arr []T) []T
HeapSort performs heap sort on a slice of numbers. It takes a slice of any numeric type T and returns a sorted slice. Time Complexity: O(n log n) Space Complexity: O(1)
func InsertionSort ¶
func InsertionSort[T number](arr []T) []T
InsertionSort performs an in-place insertion sort on a slice of numeric values. It works by building a sorted array one element at a time by repeatedly taking the next unsorted element and inserting it into its correct position in the sorted portion. Time Complexity:
- Best Case: O(n) when array is already sorted
- Average Case: O(n²)
- Worst Case: O(n²) when array is reverse sorted
Space Complexity: O(1) as it sorts in-place
func MergeSort ¶
func MergeSort[T number](arr []T) []T
MergeSort performs a merge sort on a slice of numeric values. It uses the divide-and-conquer strategy by recursively dividing the input array into two halves, sorting them, and then merging the sorted halves. Time Complexity: O(n log n) for all cases Space Complexity: O(n) for temporary arrays during merging
func QuickSort ¶
func QuickSort[T number](arr []T) []T
QuickSort performs a quick sort on a slice of numeric values. It uses the divide-and-conquer strategy by selecting a 'pivot' element and partitioning the surrounding array such that smaller elements are on the left and larger elements are on the right. Time Complexity:
- Average Case: O(n log n)
- Worst Case: O(n²) when array is already sorted
- Best Case: O(n log n)
Space Complexity: O(log n) due to recursive call stack
func SelectionSort ¶
func SelectionSort[T number](arr []T) []T
SelectionSort performs an in-place selection sort on a slice of numeric values. It works by dividing the input array into a sorted and an unsorted region. In each iteration, it finds the minimum element from the unsorted region and places it at the beginning of the sorted region. Time Complexity:
- Best Case: O(n²)
- Average Case: O(n²)
- Worst Case: O(n²)
Space Complexity: O(1) as it sorts in-place
Types ¶
This section is empty.