algorithms README

The project's README from github.com/williamfiset/algorithms. As one markdown file: README.md.

License: MIT Bazel Tests README Checker Sponsor

Algorithms & data structures project

Algorithms and data structures are fundamental to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. This repository's goal is to demonstrate how to correctly implement common data structures and algorithms in the simplest and most elegant ways.

🎬 Many of the algorithms and data structures in this repo have companion video explanations on the William Fiset YouTube channel — so if the code alone doesn't click, grab some popcorn and watch the videos!

Running an algorithm implementation

To compile and run any of the algorithms here, you need at least JDK version 8 and Bazel

This project uses Bazel as its build system. Install Bazel by following the official installation guide.

Run a single algorithm like this:

bazel run //src/main/java/com/williamfiset/algorithms/<subpackage>:<ClassName>

For instance:

bazel run //src/main/java/com/williamfiset/algorithms/search:BinarySearch

Run all tests:

bazel test //src/test/...

Run tests for a specific package:

bazel test //src/test/java/com/williamfiset/algorithms/sorting:all

Compiling and running with only a JDK

If you don't want to use Bazel, you can compile and run with just the JDK:

Create a classes folder

cd Algorithms
mkdir classes

Compile the algorithm

javac -sourcepath src/main/java -d classes src/main/java/<relative-path-to-java-source-file>

Run the algorithm

java -cp classes <class-fully-qualified-name>

Example

$ javac -d classes -sourcepath src/main/java src/main/java/com/williamfiset/algorithms/search/BinarySearch.java
$ java -cp classes com.williamfiset.algorithms.search.BinarySearch

Data Structures

Dynamic Programming

Dynamic Programming Classics

Dynamic Programming Problem Examples

Adhoc

Tiling problems

Geometry

More geometry algorithms

Graph theory

Tree algorithms

Network flow

Main graph theory algorithms

algorithms (williamfiset/algorithms)

Searching Database…

这是什么?一个大型开源项目,收录了用 Java 实现的经典算法和数据结构,目的是用最简单、最优雅的写法展示正确的实现。
这是可以直接加到我项目里的库,还是更像一份学习资料?它更像一份参考合集,而不是拿来即用的库:README 演示了如何单独编译和运行每个实现,你可以先读代码,再把需要的内容复制过去。
怎么编译和运行某个实现?一定要用 Bazel 吗?需要 JDK 8 或更高版本。Bazel 是推荐的构建工具,用来运行算法和测试,但你也可以不用它,直接用 javac 把任意文件编译到 classes 文件夹,然后用 java 运行。
它标出每个算法的时间复杂度吗?有——几乎每个条目都列出了复杂度,比如 Dijkstra 是 O(Elog(V)),后缀数组的构建是 O(nlog(n))。
这个项目还在更新吗?项目创建于 2017 年,目前没有被归档,仓库里也配置了 GitHub Actions 工作流(main.yml、readme-url-checker.yml)。
我可以把代码复制到自己的项目里吗?可以——项目采用 MIT 许可证,你可以使用、修改和分发这些实现,包括用于商业用途。
Size
1.2 GB
Stars
18.8K
Updated
CommitJun 23
Age
9y
Commits · 90 Days