Algorithms in Go

Data structures and algorithms implemented in Go.

Overview

This course requires you to implement a collection of common data structures and algorithms as Go packages. Your code is automatically tested for correctness (unit tests) and performance (CPU cycle measurement against a reference baseline).

There are 28 exercises worth a total of 123 points across 14 topics.

Getting Started

  1. Sign in at classbox.dev with your GitHub account.
  2. Enroll in the Algorithms in Go course. This installs a GitHub App on a repository created from the course template.
  3. Clone the repository to your local machine.
  4. Implement the exercises as Go packages following the descriptions below.
  5. Commit and push your changes to trigger automatic grading.
  6. Check your results on classbox.dev or in the GitHub Check Run on your commit.

Rules

Allowed packages

Your source code can only import the following standard library packages:

Imports between your own stdlib packages are also allowed.

Code style

All code must pass gofmt. Run gofmt -w -l . before committing to fix formatting issues.

Testing

Unit tests check correctness: return values, edge cases, memory constraints, and input immutability.

Performance tests measure CPU cycles on large inputs and compare to a reference baseline. Your code must reach 120% of the baseline or less to pass.

Test source code is not published. You are encouraged to write your own tests using Go's testing package.

Exercises

Introduction

ExerciseDescriptionScore
cmpMin and Max functions for a variable number of arguments.0
primesNthPrime function for computing prime numbers.3

Data Structures

ExerciseDescriptionScore
vectorDynamic array with memory management. Uses constant-factor expansion (α=4/3) and shrinking strategy. Built-in append() is not permitted.7
matrixTwo-dimensional row-major array. The row-major requirement is essential — otherwise the implementation will fail performance tests due to cache misses.3
ndarrayPrototype of a row-major n-dimensional array. Computes linearised indices for given n-dimensional coordinates without holding the actual data.3
maxqueueFIFO queue with fast queries for the maximal element. Max() in guaranteed constant time, Push() and Pop() in amortised constant time.3

Sorting and Selection

ExerciseDescriptionScore
nthelementNthElement selection algorithm.4
firstnFirstN selection algorithm.5
radixRadix sort algorithm.4
listsortSort algorithm for container/list linked lists.5

Hashing

ExerciseDescriptionScore
lruFixed-size cache with Least Recently Used (LRU) replacement policy.3

Trees

ExerciseDescriptionScore
treebalancedConstruct a balanced binary search tree.3
treeinorderNon-recursive in-order traversal of a binary tree. Must be implemented without recursion.3
treeserialiseEncode and Decode functions for binary trees using level-order serialisation format.4
treesymCheck if a binary tree is symmetric.3
treenoleftTransform a binary tree to have no left children.3

Sets

ExerciseDescriptionScore
bitsetFixed-size sequence of bits with an interface for setting and testing individual bits. Interface is a subset of std::bitset from C++.5
setOrdered collection of unique elements with logarithmic operations. Reference implementation uses skip-list with maximum 26 pointer levels. Supports iterator-based traversal with LowerBound/UpperBound.10

Dynamic Programming

ExerciseDescriptionScore
levenshteinCompute Levenshtein distance and edit transcripts between strings. Operations: Insert, Replace, Delete, Match.5
lcsLongest Common Subsequence algorithm.4
segmentationString segmentation using dynamic programming.4

Graphs: Ancestry

ExerciseDescriptionScore
treeancestryFast ancestry enquiries in binary trees using depth-first search properties.4

Graphs: Grid Problems

ExerciseDescriptionScore
islandsCount non-zero regions on an integer grid. Grid mutation is allowed, no graph package required.4

Graphs: Data Structure

ExerciseDescriptionScore
graphData structure for directed or undirected graphs using adjacency list representation.5

Graphs: Topological Sort

ExerciseDescriptionScore
tsortTopological sorting of directed graphs. Must be implemented non-recursively.7

Graphs: Minimum Spanning Tree

ExerciseDescriptionScore
mstMinimum spanning tree algorithm for undirected graphs.7

Graphs: Shortest Paths

ExerciseDescriptionScore
dijkstraDijkstra’s shortest path algorithm.7

Strings

ExerciseDescriptionScore
fulltextSimple fulltext search: find documents containing all query words, order-independent. No specialised data structures required.5