Skip to content

About

Algorithms and data structures in Java, with worked problems by topic

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Latest commit

 

History

816 Commits

Folders and files

Repository files navigation

algorithms-java

build codecov Codacy Badge

A small Java library of algorithms and data structures, plus worked problems organised by topic that show them in use.

Build

Requires Java 25. Maven comes with the wrapper.

./mvnw verify          # format check, compile, run all tests, write coverage to target/site/jacoco
./mvnw spotless:apply  # format the sources (palantir-java-format)
./mvnw install         # make io.github.diegourban:algorithms available to other local projects

Layout

src/main/java/io/github/diegourban/algorithms/
  datastructure/   array (shuffle, swap), binarytree, linkedlist, queue, set (WordSet), stack, vector
  io/              Reader: fast tokenising stdin reader for judge-style input
  math/            NumberTheory (gcd, lcm, primes, factorisation), Sequences (Fibonacci), Combinatorics, Geometry, Measurement, Numbers, Statistics
  search/          BinarySearch.indexOf
  sorting/         Sorter interface: Insertion, Merge, Quick and Selection sort
  string/          StringUtils

src/test/java/io/github/diegourban/algorithms/
  <same packages>  unit tests for the library (*PropertyTest: jqwik property-based tests)
  problems/<topic> worked problems (see below)
  testing/         SampleBuilder, SampleLoader: helpers for judge-style tests

Problems

Each problem is one test class, problems/<topic>/<Name>Test.java:

  • The Javadoc gives the title, the source (beecrowd/URI, Codewars, SPOJ, Interview Cake, HackerRank) and a link, plus a line on the approach and its complexity.
  • static solve(...) is a pure function on typed inputs, and the unit tests call it directly.
  • Problems with judge sample files also have a static String run(InputStream) adapter (Reader → solve → judge-formatted output). A parameterised test replays every .in/.out pair from src/test/resources/problems/<topic>/<name>/ through it.

Topics: bit, datastructure.{array,graph,linkedlist,map,queue,set,stack,tree,trie}, dp, greedy, math, recursion, search, simulation, sorting, string.

A problem's id is <topic>/<kebab-name> (e.g. math/prime-generator), the same in the resource folder and in any future algorithms-<language> sibling repo, so problems and their sample files port across languages one to one. This repo is the source of truth for the problem catalogue.

The original per-judge solutions (URI Online Judge, Codewars, SPOJ) are preserved at the git tag archive/judges-2018.

About

Algorithms and data structures in Java, with worked problems by topic

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages