Go
Algorithms and Data Structures implemented in Go for beginners, following best practices.
Install / Use
/learn @TheAlgorithms/GoREADME
The Algorithms - Go
Algorithms implemented in Go (for education)
The repository is a collection of open-source implementation of a variety of algorithms implemented in Go and licensed under MIT License.
Read our Contribution Guidelines before you contribute.
List of Algorithms
<!--- AUTOGENERATED ---> <!--- GODOCMD BEGIN --->Packages:
<details> <summary> <strong> ahocorasick </strong> </summary>Functions:
Advanced: Advanced Function performing the Advanced Aho-Corasick algorithm. Finds and prints occurrences of each pattern.AhoCorasick: AhoCorasick Function performing the Basic Aho-Corasick algorithm. Finds and prints occurrences of each pattern.ArrayUnion: ArrayUnion Concats two arrays of int's into one.BoolArrayCapUp: BoolArrayCapUp Dynamically increases an array size of bool's by 1.BuildAc: Functions that builds Aho Corasick automaton.BuildExtendedAc: BuildExtendedAc Functions that builds extended Aho Corasick automaton.ComputeAlphabet: ComputeAlphabet Function that returns string of all the possible characters in given patterns.ConstructTrie: ConstructTrie Function that constructs Trie as an automaton for a set of reversed & trimmed strings.Contains: Contains Returns 'true' if array of int's 's' contains int 'e', 'false' otherwise.CreateNewState: CreateNewState Automaton function for creating a new state 'state'.CreateTransition: CreateTransition Creates a transition for function σ(state,letter) = end.GetParent: GetParent Function that finds the first previous state of a state and returns it. Used for trie where there is only one parent.GetTransition: GetTransition Returns ending state for transition σ(fromState,overChar), '-1' if there is none.GetWord: GetWord Function that returns word found in text 't' at position range 'begin' to 'end'.IntArrayCapUp: IntArrayCapUp Dynamically increases an array size of int's by 1.StateExists: StateExists Checks if state 'state' exists. Returns 'true' if it does, 'false' otherwise.
Types
Result: No description provided.
</details><details> <summary> <strong> armstrong </strong> </summary>
Functions:
IsArmstrong: No description provided.
</details><details> <summary> <strong> binary </strong> </summary>
Package binary describes algorithms that use binary operations for different calculations.
Functions:
Abs: Abs returns absolute value using binary operation Principle of operation: 1) Get the mask by right shift by the base 2) Base is the size of an integer variable in bits, for example, for int32 it will be 32, for int64 it will be 64 3) For negative numbers, above step sets mask as 1 1 1 1 1 1 1 1 and 0 0 0 0 0 0 0 0 for positive numbers. 4) Add the mask to the given number. 5) XOR of mask + n and mask gives the absolute value.BitCounter: BitCounter - The function returns the number of set bits for an unsigned integer numberFastInverseSqrt: FastInverseSqrt assumes that argument is always positive, and it does not deal with negative numbers. The "magic" number 0x5f3759df is hex for 1597463007 in decimals. The math.Float32bits is alias to *(*uint32)(unsafe.Pointer(&f)) and math.Float32frombits is to *(*float32)(unsafe.Pointer(&b)).IsPowerOfTwo: IsPowerOfTwo This function uses the fact that powers of 2 are represented like 10...0 in binary, and numbers one less than the power of 2 are represented like 11...1. Therefore, using the and function: 10...0 & 01...1 00...0 -> 0 This is also true for 0, which is not a power of 2, for which we have to add and extra condition.IsPowerOfTwoLeftShift: IsPowerOfTwoLeftShift This function takes advantage of the fact that left shifting a number by 1 is equivalent to multiplying by 2. For example, binary 00000001 when shifted by 3 becomes 00001000, which in decimal system is 8 or = 2 * 2 * 2LogBase2: LogBase2 Finding the exponent of n = 2**x using bitwise operations (logarithm in base 2 of n) See moreMeanUsingAndXor: MeanUsingAndXor This function finds arithmetic mean using "AND" and "XOR" operationsMeanUsingRightShift: MeanUsingRightShift This function finds arithmetic mean using right shiftReverseBits: ReverseBits This function initialized the result by 0 (all bits 0) and process the given number starting from its least significant bit. If the current bit is 1, set the corresponding most significant bit in the result and finally move on to the next bit in the input number. Repeat this till all its bits are processed.SequenceGrayCode: SequenceGrayCode The function generates an "Gray code" sequence of length nSqrt: No description provided.XorSearchMissingNumber: XorSearchMissingNumber This function finds a missing number in a sequence
</details><details> <summary> <strong> cache </strong> </summary>
Functions:
NewLRU: NewLRU represent initiate lru cache with capacityNewLFU: NewLFU represent initiate lfu cache with capacityGet: Get the value by key from LFU cachePut: Put the key and value in LFU cache
Types
</details><details> <summary> <strong> caesar </strong> </summary>
Package caesar is the shift cipher ref: https://en.wikipedia.org/wiki/Caesar_cipher
Functions:
Decrypt: Decrypt decrypts by left shift of "key" each character of "input"Encrypt: Encrypt encrypts by right shift of "key" each character of "input"FuzzCaesar: No description provided.
</details><details> <summary> <strong> catalan </strong> </summary>
Functions:
CatalanNumber: CatalanNumber This function returns thenthCatalan number
</details><details> <summary> <strong> checksum </strong> </summary>
Package checksum describes algorithms for finding various checksums
Functions:
CRC8: CRC8 calculates CRC8 checksum of the given data.Luhn: Luhn validates the provided data using the Luhn algorithm.
Types
CRCModel: No description provided.
</details><details> <summary> <strong> coloring </strong> </summary>
Package coloring provides implementation of different graph coloring algorithms, e.g. coloring using BFS, using Backtracking, using greedy approach. Author(s): Shivam
Functions:
BipartiteCheck: basically tries to color the graph in two colors if each edge connects 2 differently colored nodes the graph can be considered bipartite
Types
Graph: No description provided.
</details><details> <summary> <strong> combination </strong> </summary>
Package combination ...
Functions:
Start: Start ...
Types
Combinations: No description provided.
</details><details> <summary> <strong> compression </strong> </summary>
Functions:
HuffDecode: HuffDecode recursively decodes the binary code in, by traversing the Huffman compression tree pointed by root. current
Related Skills
node-connect
338.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.4kCommit, push, and open a PR
