Rust icon indicating copy to clipboard operation
Rust copied to clipboard

Add more algorithms in Rust Language

Open r0hit-gupta opened this issue 5 years ago • 58 comments

This issue is fairly easy and most beginners should be comfortable implementing algorithms of their choice in Rust. In case of any problem, raise an issue or just discuss it below.

Graphs

  • [ ] DFS

Dynamic Programming

  • [ ] Longest increasing subsequence()
  • [ ] Rod cut
  • [ ] Egg Dropping Puzzle

Data Structures

  • [ ] Graph
    • [ ] Directed
    • [ ] Undirected
  • [ ] Trie
  • [ ] AVL Tree

General

  • [ ] N-Queens
  • [ ] Graph Coloring
  • [ ] Run Length Encoding

Project Euler, LeetCode, etc.

  • Currently, we don't accept problems from those and similar websites

r0hit-gupta avatar Sep 19 '18 17:09 r0hit-gupta

@r0hit-gupta I'm still getting my feet wet with Rust, but I wouldn't mind taking a stab at insertion & selection sort along with some tests for them.

0xazure avatar Oct 01 '18 18:10 0xazure

@r0hit-gupta I am also looking for a first time contribution! Mind if I take on some of the data structures?

nlynchjo avatar Oct 01 '18 18:10 nlynchjo

@0xazure @nlynchjo Please feel free to contribute and work on anything you like. Take an idea from other repositories if you do not know how to begin. Send a pull request and if there is something not right, we will let you know. Cheers!

r0hit-gupta avatar Oct 01 '18 18:10 r0hit-gupta

@r0hit-gupta I'll take a crack at the KMP string pattern matching 👍

darkkeh avatar Oct 01 '18 19:10 darkkeh

@0xazure - sorry, I didn't read your comment until now. I just added a PR with insertion sort.

bofh69 avatar Oct 01 '18 20:10 bofh69

@bofh69 thanks for letting me know! I hadn't actually started implementing it yet, so I'll focus on the selection sort. I'm definitely interested in how you did it in Rust, so I'll have a look at your PR!

0xazure avatar Oct 01 '18 20:10 0xazure

@0xazure Great! I felt a bit stupid not checking the comments here first... My solution is probably not the best, I'm still learning Rust, but now it is decent.

bofh69 avatar Oct 01 '18 21:10 bofh69

I'm actually working on Merge Sort

eisterman avatar Oct 02 '18 14:10 eisterman

I think there is already a PR for Merge Sort @eisterman

AnshulMalik avatar Oct 02 '18 14:10 AnshulMalik

I'd like to work on implementing Queue, if no one has claimed it.

Jay9596 avatar Oct 02 '18 14:10 Jay9596

Go ahead @Jay9596 :)

AnshulMalik avatar Oct 02 '18 14:10 AnshulMalik

I'd like to try my hands on heap sort.

teskje avatar Oct 02 '18 18:10 teskje

I'll take a shot at making a Stack

DanielSauve avatar Oct 04 '18 13:10 DanielSauve

I'm up for k-means, but i'm not aware of a dynamic programming algorithm for data with more than one dimension. I can implement the more general iterative algorithm if you like.

BaxterEaves avatar Oct 05 '18 02:10 BaxterEaves

I am interested in caesar cipher.

pickfire avatar Oct 06 '18 01:10 pickfire

Give it a try @BaxterEaves and @pickfire 👍

AnshulMalik avatar Oct 06 '18 03:10 AnshulMalik

I've added another Merge Sort implementation, I will try to do some other as well PR #57 PS: I didn't see that it's already implemented :grin:

Update: Binary tree PR #58

elpiel avatar Oct 28 '18 12:10 elpiel

@AnshulMalik I have added the caesar cipher https://github.com/TheAlgorithms/Rust/pull/55

pickfire avatar Oct 28 '18 13:10 pickfire

@r0hit-gupta I add PR for Longest common subsequence, still not merged ?

leviathanbeak avatar Aug 31 '19 13:08 leviathanbeak

I will take a crack at a few of these! It looks like there's a Radix Sort PR in progress, what's the status there?

sstadick avatar Sep 26 '19 14:09 sstadick

I noticed Linked Lists are listed, I think this does the subject the most justice: https://rust-unofficial.github.io/too-many-lists/

kitlith avatar Oct 11 '19 06:10 kitlith

Hey I'll try to do Dijkstra algorithm

fabrizzioalco avatar Jun 07 '20 23:06 fabrizzioalco

would like to work on coin change, what's the status?

douglasvmo avatar Oct 03 '20 16:10 douglasvmo

I'm not sure sharing solutions of the Project Euler is a very good idea, I think it goes against the objective of the challenges...

pgimalac avatar Oct 04 '20 07:10 pgimalac

@r0hit-gupta Im thinking on contributing. Can I implement the following:

  1. dynamic_programming/01_knapsack.rs
  2. dynamic_programming/coin_change.rs

joao-conde avatar Oct 26 '20 19:10 joao-conde

@r0hit-gupta Hello, I am a bit new to Rust, but can I make implementations of:

  • Trie
  • Graph ?

marnagy avatar Dec 05 '20 09:12 marnagy

I wonder if there are enough reviewers in this repository. Some PR is not reviewed for months, and it reduce the committer's motivation.

ghost avatar Mar 06 '21 01:03 ghost

@ayaankhan98 If no one is currently maintaining it, I can help to temporary maintain the repo to reduce the amount of open pull requests and help to review them at the same time if I have time.

pickfire avatar Mar 06 '21 16:03 pickfire

@ayaankhan98 If no one is currently maintaining it, I can help to temporary maintain the repo to reduce the amount of open pull requests and help to review them at the same time if I have time.

Yes, sure @pickfire go ahead. Thanks for your support.

ayaankhan98 avatar Mar 06 '21 17:03 ayaankhan98

If you need any help, count me in too. I would be glad to help you maintain the repo.

cfvescovo avatar Mar 06 '21 18:03 cfvescovo

Is there any algorithm I can help with? Contact me if I can help with anything.

marnagy avatar Mar 06 '21 18:03 marnagy

I would like to implement the following algorithms with a fellow student as a project for our Rust lecture at the Corporate University DHBW Stuttgart.

  • Transposition Cipher
  • n-queens Problem
  • Rod cut

jonakr avatar Mar 29 '21 14:03 jonakr

Hello! I see this repo is unmaintained, but I think it provides a lot of value for the community, so I decided to make my own, which you can find in https://github.com/alexfertel/rust-algorithms.

I started by adding the sorting algorithms but feel free to contribute with your own. 🚀

alexfertel avatar Jul 06 '21 15:07 alexfertel

Hi @alexfertel, I'm cleaning up this repo at the moment and will continually review new submissions, so feel free to contribute here too :)

siriak avatar Aug 18 '21 05:08 siriak

n-queens: https://github.com/insou22/typing-the-technical-interview-rust/

shadiakiki1986 avatar Aug 28 '21 09:08 shadiakiki1986

Hello, i will work on DFS Graph Algorithm

MatheusMuriel avatar Oct 08 '21 15:10 MatheusMuriel

Kruskal is already in PR: https://github.com/TheAlgorithms/Rust/pull/129

iamdejan avatar Oct 11 '21 05:10 iamdejan

Hello, I wanted to work on Queue since PR: #25 was closed. Or should I work on a different algorithm?

Forget it just checked the actual repo and I see that queue is implemented. #229

Instead has anyone started working on BFS?

Azeajr avatar Oct 11 '21 12:10 Azeajr

@Azeajr seems like no one is working on that at the moment, but you can check open PRs to be sure

siriak avatar Oct 12 '21 05:10 siriak

Dijstra is actually implemented but not marked as one @r0hit-gupta

elpiel avatar Oct 30 '21 10:10 elpiel

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Nov 30 '21 00:11 github-actions[bot]

I think we can implement some items on this list:

Math

  • [x] Random number generation:
    • Basic implementation (#311)
    • Still many more features can be implemented there (like having other distributions, having random floats, randoms in a range, etc.)
  • [x] Integer factorization (#291)
  • [x] FFT (#293)
  • [x] Integration (for general functions) (#300)
  • [ ] Polynomial manipulation:
    • integration
    • differentiation
    • inversion
    • exponentiation, calculating logarithm
    • many more operations
  • [ ] Matrix operations:
    • Addition, subtraction, multiplication, transposition (#326, Non generic and doesn't implement traits)
    • LU decomposition
  • [x] Gaussian elimination (#328)
  • [ ] Big number implementation:
    • At least supporting addition, subtraction, multiplication, conversion to and from strings
    • Division is optional
  • [ ] Chinese Remainder Theorem (with big number support)
  • [x] Discrete logarithm (#301)
  • [ ] Discrete and primitive root

Graph and Trees

  • [x] Lowest common ancestor (#294)
  • [x] Prufer encoding (#289)
  • [x] Huffman encoding (#321)
  • [x] Strongly Connected Component tasks (#309)
  • [x] Heavy Light Decomposition (#310)
  • [x] Centroid, centroid decomposition (#314)
  • [x] Max flow:
    • Dinic's algorithm (#323)
    • Push relabel algorithm
    • MPM algorithm
  • [ ] Bipartite matching (can be implemented using max flow too)
  • [ ] All pairs shortest path
  • [ ] Eulerian path
  • [ ] 2-SAT

Searching

  • [x] Ternary search (#297)

Strings

  • [ ] Suffix array, suffix tree

I'm sure I'm missing many algorithms.

erfan-khadem avatar Mar 10 '22 18:03 erfan-khadem

Hi, all! I'd like to work on ternary search algorithm, if no one else is working on it.

mime8 avatar Mar 20 '22 17:03 mime8

Hi, all! I'd like to work on ternary search algorithm, if no one else is working on it.

Awesome! I added your name to the list.

erfan-khadem avatar Mar 21 '22 23:03 erfan-khadem

Hey y'all, I'm looking to make my first contribution. I would like to work on the matrix operations. Should that be separated into different PRs for addition, subtraction and multiplication?

b42thomas avatar Mar 22 '22 18:03 b42thomas

@b42thomas depending on how complex they are. If you're implementing naive approaches, they can be merged together, if some complex algorithms, better to do them separately

siriak avatar Mar 22 '22 20:03 siriak

@siriak I have a question: I want to implement a few graph algorithms, and if they are represented using BTreeMap, a log(n) factor would be added to their time complexity (obviously.) So can I only implement the algorithms for graphs with vertices numbered from 1 to n and having &[Vec<usize>] as their adjacency list?

I know we are supposed to create generic algorithms, but adding a log(n) to max flow wouldn't make anyone happy.

erfan-khadem avatar Mar 24 '22 20:03 erfan-khadem

@er888kh, I think we can have both versions. Depending on the task at hand, both can be useful.

siriak avatar Mar 25 '22 15:03 siriak

@er888kh, I think we can have both versions. Depending on the task at hand, both can be useful.

That's certainly an option, but it would create a lot of duplication (or at least generics boiler plate)

Another solution is to have a seperate implementation that enumerates graphs represented using BTreeMap to a convenient representation. Then anyone can use that instead. As an added bonus, this solution wouldn't change the time complexity, as iterating over a BTree can be done in O(n).

I will implement the option you choose (my code wouldn't be ready for at least a few days though, I'm too busy)

erfan-khadem avatar Mar 25 '22 19:03 erfan-khadem

Agree, let's implement for the from 1 to n case then

siriak avatar Mar 26 '22 19:03 siriak

While my PR for ternary search is still in review, I'd like to work on Ternary Search Tree. I don't see this data structure in the project.

mime8 avatar Mar 30 '22 19:03 mime8

@leonamtmann and me want to implement a couple of algorithms requested here. Right now we are working on these 3:

  • Gauss-Elimination
  • Newton-Raphson method derivation
  • Basic matrix operations: add, subtract, multiply

All of these should be generic.

mhorst00 avatar Apr 04 '22 12:04 mhorst00

Now that I have added (#309), it should be really easy to implement 2-SAT problem's solution. Here is my CPP implementation if anyone is interested.

erfan-khadem avatar Apr 08 '22 17:04 erfan-khadem

@siriak, what is your opinion about moving towards creating a general purpose crate for crates.io? We already have the "basic infrastructure" and people can really benefit from these implementations.

erfan-khadem avatar Apr 10 '22 16:04 erfan-khadem

In general, I like the idea, but let's discuss it in more detail on our Discord server https://discord.gg/adJacSyV

siriak avatar Apr 11 '22 15:04 siriak

I have an idea for implementing big number support:

First, One can implement a really basic base 10 big number module. It only supports addition and multiplication by 2. It can be formatted as a string and can be created from a string.

After that, a big number module can be implemented that is basically just a BitSet with usual operations (addition, multiplication, division, ...). Converting to and from strings can then be handled using the base 10 implementation.

Right now I am just way too busy, and I will not have time to implement these, plus the second one will have a ton of boring boilerplate. Can someone implement (or even just partially implement) any of the above modules?

Also, there might be simpler approaches to this problem, so other suggestions are welcome.

erfan-khadem avatar Apr 29 '22 19:04 erfan-khadem