Top Related Projects
All Algorithms implemented in Python
Minimal examples of data structures and algorithms in Python
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.
A collection of algorithms and data structures
A Python module for learning all major algorithms
Quick Overview
The arnauddri/algorithms repository is a collection of classic computer science algorithms implemented in Go. It covers various categories such as sorting, searching, data structures, and graph algorithms, providing a valuable resource for learning and reference.
Pros
- Comprehensive collection of algorithms covering multiple categories
- Clear and well-organized code structure
- Includes test cases for most implementations
- Serves as both a learning resource and a reference for Go developers
Cons
- Some algorithms may lack detailed explanations or comments
- Not actively maintained (last commit was several years ago)
- May not include the most recent or optimized versions of some algorithms
- Limited to Go language implementations
Code Examples
Here are a few examples of algorithms implemented in this repository:
- Binary Search implementation:
func BinarySearch(array []int, target int) int {
left, right := 0, len(array)-1
for left <= right {
mid := (left + right) / 2
if array[mid] == target {
return mid
} else if array[mid] < target {
left = mid + 1
} else {
right = mid - 1
}
}
return -1
}
- Quicksort implementation:
func QuickSort(arr []int) []int {
if len(arr) <= 1 {
return arr
}
pivot := arr[len(arr)/2]
left := make([]int, 0)
right := make([]int, 0)
middle := make([]int, 0)
for _, item := range arr {
switch {
case item < pivot:
left = append(left, item)
case item == pivot:
middle = append(middle, item)
case item > pivot:
right = append(right, item)
}
}
left = QuickSort(left)
right = QuickSort(right)
return append(append(left, middle...), right...)
}
- Depth-First Search (DFS) implementation for a graph:
func (g *Graph) DFS(start int, visited map[int]bool) {
if visited == nil {
visited = make(map[int]bool)
}
visited[start] = true
fmt.Printf("%d ", start)
for _, neighbor := range g.adjacencyList[start] {
if !visited[neighbor] {
g.DFS(neighbor, visited)
}
}
}
Getting Started
To use these algorithms in your Go project:
-
Clone the repository:
git clone https://github.com/arnauddri/algorithms.git
-
Import the desired algorithm package in your Go code:
import "github.com/arnauddri/algorithms/sorting"
-
Use the algorithm functions in your code:
arr := []int{5, 2, 8, 12, 1, 6} sortedArr := sorting.QuickSort(arr) fmt.Println(sortedArr)
Note that you may need to adjust import paths based on your project structure and Go workspace configuration.
Competitor Comparisons
All Algorithms implemented in Python
Pros of Python
- Larger community and more contributors, leading to more diverse algorithms and implementations
- Better organized with clear categorization of algorithms by type (e.g., sorts, searches, data structures)
- More comprehensive documentation and explanations for each algorithm
Cons of Python
- Focused solely on Python, limiting language diversity
- May include some less optimized or non-standard implementations due to the large number of contributors
Code Comparison
algorithms (Go):
func BubbleSort(arr []int) {
for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr)-1-i; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
}
Python:
def bubble_sort(array):
n = len(array)
for i in range(n):
for j in range(0, n - i - 1):
if array[j] > array[j + 1]:
array[j], array[j + 1] = array[j + 1], array[j]
return array
Both implementations are similar, with Python's version being slightly more readable due to the language's syntax. The algorithms repository focuses on Go implementations, while Python provides a wider range of algorithms in Python.
Minimal examples of data structures and algorithms in Python
Pros of algorithms (keon)
- More comprehensive coverage of algorithms and data structures
- Better organized with clear categorization of topics
- More active development and community engagement
Cons of algorithms (keon)
- Less focus on language-specific implementations (primarily Python)
- May be overwhelming for beginners due to the large number of algorithms
Code Comparison
algorithms (arnauddri):
func BubbleSort(arr []int) {
for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr)-1-i; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
}
algorithms (keon):
def bubble_sort(arr):
def swap(i, j):
arr[i], arr[j] = arr[j], arr[i]
n = len(arr)
swapped = True
x = -1
while swapped:
swapped = False
x = x + 1
for i in range(1, n-x):
if arr[i - 1] > arr[i]:
swap(i - 1, i)
swapped = True
return arr
The code comparison shows that algorithms (arnauddri) uses Go, while algorithms (keon) uses Python. The keon implementation includes additional optimizations, such as early termination when no swaps occur and reducing the number of comparisons in each pass.
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
Pros of javascript-algorithms
- More comprehensive coverage of algorithms and data structures
- Better documentation with explanations and complexity analysis
- Active maintenance with regular updates and contributions
Cons of javascript-algorithms
- Larger codebase, potentially overwhelming for beginners
- Focuses solely on JavaScript implementations
- May include more advanced topics not suitable for all skill levels
Code Comparison
algorithms (Go):
func BubbleSort(arr []int) {
for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr)-1-i; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
}
javascript-algorithms (JavaScript):
function bubbleSort(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
}
}
}
return arr;
}
Both repositories implement common algorithms, but javascript-algorithms offers a more extensive collection with detailed explanations. algorithms provides implementations in Go, making it suitable for developers working with that language. The code structure and logic are similar, but the syntax differs due to the languages used.
120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.
Pros of interactive-coding-challenges
- More comprehensive coverage of topics, including system design and object-oriented design
- Includes Jupyter notebooks for interactive learning and testing
- Provides detailed explanations and multiple solutions for each problem
Cons of interactive-coding-challenges
- Less focus on pure algorithmic implementations
- May be overwhelming for beginners due to the extensive content
- Requires additional setup for Jupyter notebooks
Code Comparison
algorithms:
func BubbleSort(arr []int) {
for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr)-1-i; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
}
interactive-coding-challenges:
def bubble_sort(data):
for i in range(len(data) - 1):
for j in range(len(data) - 1 - i):
if data[j] > data[j + 1]:
data[j], data[j + 1] = data[j + 1], data[j]
return data
Both repositories offer implementations of common algorithms and data structures. algorithms focuses on Go implementations with a clean, minimalist approach. interactive-coding-challenges provides a more comprehensive learning experience with Python implementations, interactive notebooks, and detailed explanations. The choice between the two depends on the user's preferred language and learning style.
A collection of algorithms and data structures
Pros of Algorithms
- More comprehensive coverage of algorithms and data structures
- Better documentation and explanations for each implementation
- Includes unit tests for most algorithms
Cons of Algorithms
- Primarily uses Java, which may not be ideal for all users
- Less focus on graph algorithms compared to algorithms
Code Comparison
algorithms (Go):
func BinarySearch(array []int, target int) int {
low, high := 0, len(array)-1
for low <= high {
mid := (low + high) / 2
if array[mid] == target {
return mid
} else if array[mid] < target {
low = mid + 1
} else {
high = mid - 1
}
}
return -1
}
Algorithms (Java):
public static int binarySearch(int[] arr, int target) {
int lo = 0, hi = arr.length - 1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (arr[mid] == target) return mid;
if (arr[mid] < target) lo = mid + 1;
else hi = mid - 1;
}
return -1;
}
Both repositories provide implementations of common algorithms and data structures. algorithms focuses on Go implementations with a clean, minimalist approach. Algorithms offers a more extensive collection in Java with detailed explanations and unit tests. The choice between them may depend on your preferred programming language and the depth of explanations you require.
A Python module for learning all major algorithms
Pros of pygorithm
- Written in Python, making it more accessible for Python developers
- Includes a wider range of algorithms and data structures
- Provides detailed explanations and time complexity for each algorithm
Cons of pygorithm
- Less organized file structure compared to algorithms
- May have slower performance due to being implemented in Python
- Lacks some advanced algorithms present in algorithms
Code Comparison
pygorithm (Binary Search implementation):
def binary_search(sorted_collection, item):
left = 0
right = len(sorted_collection) - 1
while left <= right:
midpoint = left + (right - left) // 2
current_item = sorted_collection[midpoint]
if current_item == item:
return midpoint
elif item < current_item:
right = midpoint - 1
else:
left = midpoint + 1
return None
algorithms (Binary Search implementation):
func BinarySearch(array []int, target int, lowIndex int, highIndex int) int {
if highIndex < lowIndex {
return -1
}
mid := int(lowIndex + (highIndex-lowIndex)/2)
if array[mid] > target {
return BinarySearch(array, target, lowIndex, mid)
} else if array[mid] < target {
return BinarySearch(array, target, mid+1, highIndex)
} else {
return mid
}
}
The pygorithm implementation uses an iterative approach, while algorithms uses recursion. The Go implementation in algorithms may be more efficient due to the language's performance characteristics.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Algorithms
Classic algorithms and data structures implemented in Go. Not for production use, it is mostly an attempt to get comfortable both with Go and key CS concepts.
Contents
Data Structures
- Binary Search Tree (wiki)
- Graph (wiki)
- Hash Tables (wiki)
- Linked List (wiki)
- Matrix (wiki)
- Min/Max Heap (wiki)
- Priority Queue (wiki)
- Queue (wiki)
- Stack (wiki)
Graph algorithms
Searching:
Shortest path:
Sorting:
Maths algorithms
- Binary GCD algorithm (wiki)
- Closest pairs (wiki)
- FastPower (wiki)
- Fibonacci (wiki)
- Fisher-Yates Shuffle (wiki)
- Erastothenes Sieve (wiki)
- Extented GCD algorithm (wiki)
- Karatsuba's Multiplication (wiki)
- Newton's Square Root (wiki)
- Permutations Count
- Strassen's matrix multiplication (wiki)
- Randomized Selection
Sorting algorithms
- Bubble Sort (wiki)
- Heap Sort (wiki)
- Quick Sort (wiki)
- Merge Sort (wiki)
- Insertion Sort (wiki)
- Shell Sort (wiki)
- Selection Sort (wiki)
Searching algorithms
Top Related Projects
All Algorithms implemented in Python
Minimal examples of data structures and algorithms in Python
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.
A collection of algorithms and data structures
A Python module for learning all major algorithms
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot