algorithms

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinarySearch

func BinarySearch(arr []int, target int) int

BinarySearch performs binary search on a sorted slice

func BinarySearchRecursive

func BinarySearchRecursive(arr []int, target int) int

BinarySearchRecursive performs recursive binary search on a sorted slice

func BoyerMooreSearch

func BoyerMooreSearch(text, pattern string) []int

BoyerMooreSearch performs Boyer-Moore pattern searching

func BubbleSort

func BubbleSort(arr []int) []int

BubbleSort performs bubble sort on an integer slice

func CountingSort

func CountingSort(arr []int) []int

CountingSort implements the Counting Sort algorithm for non-negative integers Time Complexity: O(n + k) where n is the number of elements and k is the range of input Space Complexity: O(k)

func CountingSortBytes added in v1.1.0

func CountingSortBytes(arr []byte) []byte

CountingSortBytes implements Counting Sort for byte slices This is useful for sorting binary data or custom encodings

func CountingSortString added in v1.1.0

func CountingSortString(str string) string

CountingSortString sorts a string using counting sort algorithm

func CountingSortWithRange added in v1.1.0

func CountingSortWithRange(arr []int, minVal, maxVal int) []int

CountingSortWithRange implements Counting Sort for a known range of integers This version is more efficient when the range is known and smaller than the array size

func ExponentialSearch

func ExponentialSearch(arr []int, target int) int

ExponentialSearch performs exponential search on a sorted slice

func FibonacciSearch

func FibonacciSearch(arr []int, target int) int

FibonacciSearch performs Fibonacci search on a sorted slice

func HeapSort

func HeapSort(arr []int) []int

HeapSort performs heap sort on an integer slice

func HibbardGaps added in v1.1.0

func HibbardGaps(n int) []int

Hibbard sequence: 2^k - 1

func InsertionSort

func InsertionSort(arr []int) []int

InsertionSort performs insertion sort on an integer slice

func InterpolationSearch

func InterpolationSearch(arr []int, target int) int

InterpolationSearch performs interpolation search on a sorted slice

func JumpSearch

func JumpSearch(arr []int, target int) int

JumpSearch performs jump search on a sorted slice

func KMPSearch

func KMPSearch(text, pattern string) []int

KMPSearch performs Knuth-Morris-Pratt pattern searching

func LevenshteinDistance

func LevenshteinDistance(str1, str2 string) int

LevenshteinDistance calculates the minimum number of single-character edits required to change one string into another

func LinearSearch

func LinearSearch(arr []int, target int) int

LinearSearch performs linear search on a slice

func LongestCommonSubsequence

func LongestCommonSubsequence(text1, text2 string) string

LongestCommonSubsequence finds the longest common subsequence of two strings

func MergeSort

func MergeSort(arr []int) []int

MergeSort performs merge sort on an integer slice

func PrattGaps added in v1.1.0

func PrattGaps(n int) []int

Pratt sequence: 2^i * 3^j

func QuickSort

func QuickSort(arr []int) []int

QuickSort performs quick sort on an integer slice

func RabinKarpSearch

func RabinKarpSearch(text, pattern string) []int

RabinKarpSearch performs Rabin-Karp pattern searching

func RadixSort added in v1.1.0

func RadixSort(arr []int) []int

RadixSort implements the Radix Sort algorithm for non-negative integers Time Complexity: O(d * (n + k)) where d is the number of digits, n is the number of elements and k is the range of values for each digit (10 for decimal)

func RadixSortBytes added in v1.1.0

func RadixSortBytes(arr [][]byte) [][]byte

RadixSortBytes implements Radix Sort for byte slices of equal length

func RadixSortString added in v1.1.0

func RadixSortString(arr []string) []string

RadixSortString implements Radix Sort for strings This implementation sorts strings of equal length

func RecursiveCountNQueensSolutions added in v1.1.0

func RecursiveCountNQueensSolutions(n int) int

RecursiveCountNQueensSolutions returns the number of solutions for the N-Queens problem

func RecursiveFactorial added in v1.1.0

func RecursiveFactorial(n int) int

RecursiveFactorial calculates n! recursively

func RecursiveGetNQueensBoard added in v1.1.0

func RecursiveGetNQueensBoard(solution []int) []string

RecursiveGetNQueensBoard converts a solution to a 2D board representation Returns a slice of strings where 'Q' represents a queen and '.' represents an empty cell

func RecursiveIsValidNQueensSolution added in v1.1.0

func RecursiveIsValidNQueensSolution(solution []int) bool

RecursiveIsValidNQueensSolution verifies if a given solution is valid

func RecursiveNQueens added in v1.1.0

func RecursiveNQueens(n int) [][]int

RecursiveNQueens solves the N-Queens problem and returns all solutions Each solution is represented as a slice of integers where the index represents the row and the value represents the column where a queen is placed

func RecursiveReverseString added in v1.1.0

func RecursiveReverseString(s string) string

RecursiveReverseString reverses a string using recursion

func SedgewickGaps added in v1.1.0

func SedgewickGaps(n int) []int

Sedgewick sequence: 4^k + 3 * 2^(k-1) + 1

func ShellSort added in v1.1.0

func ShellSort(arr []int) []int

ShellSort implements the Shell Sort algorithm Shell sort is an optimization of insertion sort that allows the exchange of items that are far apart

func ShellSortWithGaps added in v1.1.0

func ShellSortWithGaps(arr []int, gaps []int) []int

ShellSortWithGaps implements Shell Sort with custom gap sequence This version allows you to specify the gap sequence to use

func SortingSort added in v1.1.0

func SortingSort(arr []int) []int

SortingSort performs counting sort on an integer slice

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL