Algorithms and Data Structures of all kinds written in Rust.

Overview

Classic Algorithms in Rust

This repo contains the implementation of various classic algorithms for educational purposes in Rust. Right now, it is in its early stages, but the plan is to include a comprehensive list of algorithms. Contributions are welcome!

The main goal right now is to match the current algorithms implemented in https://github.com/TheAlgorithms/Rust.

Setup

This repo is only for educational purposes. It is meant to be used as a reference material. Thus, it is written as a library instead of a binary.

The way to check the execution of an algorithm is running the tests, which you can do using:

cargo test

Algorithms

Sorting Algorithms

  • Bubble
  • Counting
  • Heap
  • Insertion
  • Merge
  • Quick
  • Radix
  • Selection
  • Shell

Graphs

  • Dijkstra
  • Kruskal's Minimum Spanning Tree
  • Prim's Minimum Spanning Tree
  • BFS
  • DFS

Dynamic Programming

  • 0-1 Knapsack
  • Edit Distance
  • Longest common subsequence
  • Longest increasing subsequence
  • K-Means Clustering
  • Coin Change
  • Rod cutting
  • Egg Dropping Puzzle

Data Structures

  • Queue
  • Stack
  • Heap
  • Linked List
  • Graph
  • Trie
  • Binary Search Tree
  • B-Tree
  • AVL Tree

String Matching

  • Naive
  • Rabin Carp
  • Finite Automaton
  • Knuth Morris Pratt

General

  • Convex Hull: Graham Scan
  • N-Queens
  • Graph Coloring
  • Tower of Hanoi

Ciphers

  • Transposition

Bit Manipulation

  • Bit Distance
  • Bits Length
  • Clear Bit
  • Count Ones
  • Divide By Two
  • Get Bit
  • Is Even
  • Is Positive
  • Is Power Of Two
  • Multiply By Two
  • Multiply Signed
  • Multiply Unsigned
  • Set Bit
  • Twos Complement
  • Update Bit

Contributing

See CONTRIBUTING.md

Comments
  • refactor(sorting): add traits for sorting algorithms

    refactor(sorting): add traits for sorting algorithms

    Hi Alex,

    Referring to PR #48, I have added two traits:

    • Sort
    • SortMutable

    in an attempt to unify the sorting algorithms behind structs that expose the sort method.

    Not sure how complete the feature needs to be, but I believe the PR would be too large at that point to be easily reviewable. I was considering submitting the traits for 1 algorithm at a time, modifying those that do not adhere to the trait properties.

    I wanted to get into contributing to OSS, and I thought your library would be a great place to start. Any comments are welcome.

    opened by borghol 8
  • feat: Add three algorithms

    feat: Add three algorithms

    These were really easy to add, they're functionally identical to the ones in the older repository, the only thing I changed was proper tests for reverse (it only had palindromes) and morse, which never attempted decoding.

    What does this PR do?

    Added the following ciphers and string manipulation algorithms:

    • Reverse
    • Morse
    • VIgenere

    All Submissions:

    • [x] Have you followed the guidelines in our Contributing document?
    • [x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [x] Does your submission pass tests?
    2. [x] Have you lint your code locally prior to submission?
    enhancement 
    opened by ghost 8
  • feat: add `sorting_tests` macro to almost all sorting algorithms

    feat: add `sorting_tests` macro to almost all sorting algorithms

    There were a few algorithms I wasn't able to do this for, because the function signatures didn't match those expected by the macro. Perhaps it'd be a good idea to standardize those too?

    opened by aliencdh 3
  • feat: migrate most implementations from base repo

    feat: migrate most implementations from base repo

    #7

    More or less just copied any files that wouldn't cause an overwrite, and updated use statements of various modules accordingly.

    Made a few tweaks to searching::kth_smallest_heap as it relied on a different version of the Heap struct, and made sorting::quick_sort::partion public as searching::kth_smallest depended on it.

    I also took the liberty to rename string_matching into just string like in the old repo, as there are a few algorithms that aren't strictly related to matching.

    This is pretty much my first time contributing to anything. I just came across the issue and thought "move some stuff around? I can do that!" (one of these days I might try my luck contributing some actual code). Please let me know if there's anything I missed or should've done differently.

    enhancement 
    opened by Craksy 3
  • feat: add docs to stack (vector)

    feat: add docs to stack (vector)

    Hi, hope these comments are okay. I didn't change it with this commit but I did notice that in the src/data_structures/README.md that the Properties section for the linked list stack says that accessing the tail happens in O(n) time. This doesn't seem particularly relevant to stacks, though?

    opened by bhlieberman 2
  • Revamp the Counting Sort implementation

    Revamp the Counting Sort implementation

    The current implementation of Counting Sort supports sorting integers only, but it can be extended to support any form of object that is represented by an integer key.

    Also, the current implementation is missing tests for stability. Since radix sort relies on this algorithms' property of being stable, it would be nice to assert that it is present.

    • Extend Counting Sort to the general case of having objects with integer keys.
    • Add tests that assert the stability of the algorithm.
    documentation enhancement good first issue tests 
    opened by alexfertel 2
  • refactor(combsort): implement MutableSorter trait for CombSorter

    refactor(combsort): implement MutableSorter trait for CombSorter

    • Implementing the MutableSorter trait for CombSorter
    • Standardized the tests by adding the descending test case to the macro and removing it from tests that use it
    opened by borghol 1
  • feat(docs): add 'reverse' algo to string docs

    feat(docs): add 'reverse' algo to string docs

    Hey, I am a junior developer and I am looking to increase my open source contributions. I found your project on Good First Issue.

    I promise I won't mess anything up. Thanks for the opportunity to contribute.

    opened by dlkritter 1
  • ref: add macro to dedup tests in sorting algorithms

    ref: add macro to dedup tests in sorting algorithms

    In #19 has been pointed out that a new macro that represents the test suite for sorting algorithms could be used to avoid code duplication in tests for sorting algorithms.

    The changes introduced by this PR are the following:

    1. introduction of the sorting_tests! macro, which represents the test previously done through the basic, repeated_elements and pre_sorted functions
    2. the macro can be used in two ways:
      1. sorting_tests!(sorting_function), for algorithms implemented without in-place implementation
      2. sorting_tests!(sorting_function, inplace), for algorithms with in-place implementation
    3. all the implemented sorting algorithms now use the sorting_tests! with two excpetions:
      1. radix sort uses a different test suite
      2. shell sort uses only the basic test function and the pre_sorted has a different name (already_sorted in this case)

    The total number of tests run with cargo test remains 129

    opened by Trolloldem 1
  • fix: Fix some typos

    fix: Fix some typos

    Hi, I found some typos in the comment section of the following code and fixed it. Please merge if you like.

    • src/ciphers/morse_code.rs
    • src/ciphers/transposition.rs
    • src/dynamic_programming/edit_distance.rs
    • src/dynamic_programming/egg_dropping.rs
    • src/general/nqueens.rs
    opened by ymidori 1
  • Improve duplication in the sorting algorithm tests

    Improve duplication in the sorting algorithm tests

    Currently, we have the assert_sorted! and assert_not_sorted! macros that make it easy to check that an array is sorted. But we have very similar tests for the sorting algorithms and it makes sense because the API of those algorithms should be the same or very similar: You take an array and sort it.

    Therefore, I think it makes sense to come up with a new macro that represents our test suite for sorting algorithms, and then we can extend each local module with other tests that may be relevant to a specific algorithm like counting sort not relying on items being integers.

    help wanted tests 
    opened by alexfertel 1
  • added tower of hanoi

    added tower of hanoi

    Hi, I want to contribute to this repo, I particularly want to create some algorithms with proper documentation.

    I created tower of hanoi algorithm with test cases. Thank you.

    opened by Austincardoza 0
  • Make tests in sorting algorithms consistent

    Make tests in sorting algorithms consistent

    Following the discussion in https://github.com/alexfertel/rust-algorithms/pull/35 it would be good to make tests consistent across sorting algorithm implementations such that they share a basic suite (calling the sorting_tests! macro) and then any other test that might be meaningful to that particular algorithm.

    good first issue tests 
    opened by alexfertel 5
  • Created Linear Search algorithm

    Created Linear Search algorithm

    Hi, I want to contribute to this repo, I particularly want to create the all searching algorithms with proper documentation.

    I created a Linear Search algorithm with test cases. Thank you.

    opened by RajMazumder18110 1
  • Add documentation

    Add documentation

    We want to document each class of algorithms. This comes in two flavors:

    • Adding README files to each directory holding a class of algorithms, for example, sorting.
    • Adding documentation comments to each of the algorithms.

    You can find examples of documentation comments in here.

    General guidelines for the explanations are to be concise and link to the bibliography. Images are better than no images. If it is possible include time and space complexities.

    documentation help wanted good first issue 
    opened by alexfertel 0
Owner
Alexander González
Alexander González
Rust-algorithm-club - Learn algorithms and data structures with Rust

Rust Algorithm Club ?? ?? This repo is under construction. Most materials are written in Chinese. Check it out here if you are able to read Chinese. W

Weihang Lo 360 Dec 28, 2022
Common data structures and algorithms in Rust

Contest Algorithms in Rust A collection of classic data structures and algorithms, emphasizing usability, beauty and clarity over full generality. As

Aram Ebtekar 3.3k Dec 27, 2022
rust_aads - Rust Algorithms And Data Structures

rust_aads - Rust Algorithms And Data Structures rust_aads is an open repository with algorithms and data structures, used in computer science and comp

stepa 2 Dec 15, 2022
Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

null 6.5k Dec 31, 2022
All Algorithms implemented in Rust

The Algorithms - Rust All algorithms implemented in Rust (for educational purposes) These are for demonstration purposes only. RESTART BUILD Sort Algo

The Algorithms 13.1k Dec 26, 2022
Rust data structures and client for the PubChem REST API

pubchem.rs Rust data structures and client for the PubChem REST API. ?? Usage ?? Compound Create a Compound to query the PubChem API for a single comp

Martin Larralde 2 Jan 18, 2022
Obake is a procedural macro for declaring and maintaining versioned data-structures.

Obake is a procedural macro for declaring and maintaining versioned data-structures. The name 'obake' is taken from the Japanese 'お化け (おばけ)', a class of supernatural beings in Japanese folklore that shapeshift.

Nathan Corbyn 174 Dec 26, 2022
Fast, efficient, and robust memory reclamation for concurrent data structures

Seize Fast, efficient, and robust memory reclamation for concurrent data structures. Introduction Concurrent data structures are faced with the proble

Ibraheem Ahmed 240 Dec 23, 2022
Rust Persistent Data Structures

Rust Persistent Data Structures Rust Persistent Data Structures provides fully persistent data structures with structural sharing. Setup To use rpds a

Diogo Sousa 883 Dec 31, 2022
A proof of concept implementation of cyclic data structures in stable, safe, Rust.

A proof of concept implementation of cyclic data structures in stable, safe, Rust. This demonstrates the combined power of the static-rc crate and the

null 157 Dec 28, 2022
Rust library for string parsing of basic data structures.

afmt Simple rust library for parsing basic data structures from strings. Usage You can specify string formats to any strucute, via the use of the fmt

Eduard 4 May 8, 2021
Library containing various Data Structures implemented using Rust.

rust-data-structures Library containing various Data Structures implemented using Rust. Running You can test the library by running cargo test, an exa

c1m50c 1 Jan 6, 2022
A library for comparing data structures in Rust, oriented toward testing

Delta: Structural differencing in Rust The delta crate defines the trait Delta, along with a derive macro for auto-generating instances of this trait

John Wiegley 19 Oct 7, 2022
A library for comparing data structures in Rust, oriented toward testing

The comparable crate defines the trait [Comparable], along with a derive macro for auto-generating instances of this trait for most data types. Primar

John Wiegley 19 Oct 7, 2022
Collection of Data Structures in Rust

cds - Collection of Data Structures !!! UNDER CONSTRUCTION !!! The version v0.0.1 is a crates.io placeholder. License Licensed under either of Apache

Rafael Buchbinder 2 May 23, 2022
Succinct data structures in Rust

sucds: Succinct data structures in Rust sucds contains some succinct data structures written in Rust. Data structures So far, the following data struc

Shunsuke Kanda 43 Dec 3, 2022
Dade is data definition for Rust structures.

dade dade is data definition for Rust structures. For the easy handle of data, the following will support it. Data validation. Data schema conforms Js

odd 3 May 1, 2022
NixEl is a Rust library that turns Nix code into a variety of correct, typed, memory-safe data-structures

?? NixEL Lexer, Parser, Abstract Syntax Tree and Concrete Syntax Tree for the Nix Expressions Language. NixEl is a Rust library that turns Nix code in

Kevin Amado 56 Dec 29, 2022
This repository aims to organize codes related to data structures in Rust. 🦀

Rust Data Structure A project with the objective of introducing the main concepts about data structure using Rust! Explore the docs and learn Rust » R

guto 12 Apr 3, 2023