Giter Club home page Giter Club logo

go's Introduction

The Algorithms Official Website


This is a static Next.js site providing a searchable library of all the algorithms in The Algorithms. All the data about the algorithms gets scraped directly from the git repositories.

Translating the website

You can help us translate the TheAlgorithms website using Weblate here. There you can complete the translations for our current languages, or suggest something if you are unsure. Also feel free to add a new language. The current languages are:

Translation status by language

Getting Started

If you haven't installed it yet, install Node.js and yarn. Then, install all the dependencies:

yarn

After that, run the script that fetches all the algorithms from GitHub:

yarn fetch-algorithms

Finally, run the development server:

yarn dev

Open http://localhost:3000 with your browser to see the website.

Alternatively, you can also use the Ready-to-Code Gitpod and easily check how your deployment looks. It will automatically run the commands mentioned above on run.

Contributing

If you want to add a new feature or fix a bug, create a new branch or fork and commit there. Before opening a PR, be sure to

  • Run yarn lint and fix potential errors
  • Run yarn build to check if everything still builds successfully

Open the pull request against main. Vercel will automatically create a preview deployment, and the pull request will be squash merged after being reviewed by a member.

License

The source code of website itself (this repository) is licensed under MIT, while all the licenses for the code and explanations on the website can be found in the respective repositories.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Powered by Vercel

go's People

Contributors

brayo-pip avatar calebeof avatar cclauss avatar crazy3lf avatar d4rkia avatar dynamitechetan avatar himanshu-patel-dev avatar himanshub16 avatar i-redbyte avatar itsakshaydubey avatar jafar75 avatar lkeix avatar mcaci avatar miraddo avatar mohamed-abdelrhman avatar mystigan avatar ongspxm avatar panquesito7 avatar paul-leydier avatar rajneesh44 avatar raklaptudirm avatar siriak avatar stepfenshawn avatar task4233 avatar tjgurwara99 avatar vdnhi avatar vedantmamgain avatar vil02 avatar wesllhey avatar yanglbme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go's Issues

Graphs: Articulation Points

Description
Implement an algorithm to decide whether a vertex is a cut-vertex or not. The algorithm will return a list of boolean with the ith index representing whether the vertex i is a cut-vertex or not.

For new implementation:

Fix Graphs/BFS implementation.

For disconnected graphs like the below graph, it will catch in an infinite loop.
Also, this implementation doesn't support the directional graphs.

For more info this link will help

golangci-lint: iterBinarySearch and binarySearch are unused

golangci-lint run --no-config searches

##[error]searches/binary_search.go:20:6: `iterBinarySearch` is unused (deadcode)
func iterBinarySearch(array []int, target int, lowIndex int, highIndex int) int {
     ^
##[error]searches/binary_search.go:6:6: func `binarySearch` is unused (unused)
func binarySearch(array []int, target int, lowIndex int, highIndex int) int {
     ^

Consider adding ExampleAlgorithms in the packages.

Description
The ExampleAlgorithm function gives a actual runnable block of code for the specified algorithms which works automatically in the documentation - ref here. It's kind of similar to the main function that many people submit in the repository. An example in our repository is given here if you further click on that example it would take you to the our GitHub repo where this example is written.

For new implementation:

  • Adding Example functions would give a new way for contributors to contribute and an additional resource for people to learn from.

For enhancement:

  • For now, we should discuss on whether this is a good idea and collectively agree or disagree with this.

Naming issues in the strings directory

@halafi Can you please make some changes in https://github.com/TheAlgorithms/Go/tree/master/strings ?

  1. The directories contain spaces instead of dashes in the directory names. This forces us to quote the directory names when using command line tools such as linters.
  2. File names need work also. Is ac.go a calculation for alternating current or is it controller for an air conditioner? Is bom.go a tool for building a bill of materials or does it generate a byte order mark? Why does the reader have to guess?? aho-corasick.go is a much more self-documenting filename than ac.go.
  3. Can you help us to get the last two lines of .github/workflows/golangci-lint.yml to pass without || true?

Package names and file names are not idiomatic

Description

Title is self explanatory. The Go idiomatic style of package name is very different from the recent merge of #313 . For reference see this blog post on go.dev. The relevant line states that, "Good package names are short and clear. They are lower case, with no under_scores or mixedCaps."

In #313 the author has changed old names with under_score naming conventions – depending on the maintainers preference this may be okay, however since this repo is for learning, it might be a good idea to adhere to the idiomatic style of Go as this constraint is one of the main reason which makes it easier for large teams to adopt go as it has only one specific way of doing things (albeit its not enforced sometimes). This may be good for other languages but its not idiomatic in Go.

Another point I would like to make is that file names with under_score.go conventions have some predetermined rules for Go build tools. For example, the file name ending with _test.go are checked by go test. Another example is that the file names ending with _linux.go builds only on linux and file names ending with _amd64.go will only build on an amd64. Same applies for different go versions _go113 etc. For further information on go build constraints, please refer to go help command go help buildconstraint, this will show you all the main constraints that go build tools have.

Proposed Solution:

Package naming: My opinion is that we should combine the types of packages together to make it easier to navigate the source. For example, consider the cipher package, instead of having multiple packages within that package for caeser cipher etc, we could create a unified package which is more easier to navigate and manage. This is not a unique idea and if you review the standard library this pattern appears everywhere in standard library. If, however, it is not possible to combine packages, we should try to keep the packages abbreviated – in the mean time someone tries and changes the code to work in a unified manner – even if it may not be easier for a reader to understand. The reason I suggest this, even though it is difficult for the reader is because the file names would still contain the full name of the algorithm/implementation and since the source of this repository is usually kept well documented, it will not be very difficult to understand what each package abbreviation stands for when a reader opens the source. Nevertheless, this is just my opinion and the decision is left up to the maintainers.

File naming: Technically this is not wrong (as this is not enforced by go build tools) but again if the go devs made some changes to the build strategy and added some extra keywords for later versions of Go, it may create issues (although this is highly unlikely to happen but is nonetheless its not idiomatic). I propose that we should keep the names without underscore even if the names are big, this pattern is also not new and is present in the standard library (for example poolqueue.go or waitgroup.go - notice no underscores). The underscores are specifically used to interact with the go build tools and in my opinion, shouldn't be used. But again, it is up to the maintainers to decide.


I believe this should be a separate issue - do let me know if I should create one and I'll oblige.

Issue:

For any algorithm, we have some intermediary functions that are used within the main algorithm that we want to work on. For example, suppose I'm working on an implementation of algorithm A and it uses another algorithm B inside it. Suppose this algorithm B is already present in this repo, so I should create only algorithm A and use algorithm B that was already defined instead of creating my own implementation of B. The reason for this is quite simple, the algorithm contributors want to make should be self explanatory which makes it easier for people to understand self contained code without replicating code (and making their own implementations for A and B densely coupled). You may have already noticed that, within this repo majority of the implementation repeatedly creates the same intermediary algorithm (I'll refer to it as B) for different implementations of their main algorithm (I'll refer to this as A). This is again not an issue when learning and people should at least implement intermediary algorithms at least once but since the intermediary algorithms created do not usually get tested (either because they are coupled strongly or there is very low cohesion in their code). This is also something that people learning to program should work towards, as it keeps to the separation of concern and their code bases maintainable.

For solution to this, I propose that maintainers should include a clause in How to Contribute.md so that the algorithms that they are writing and all the intermediary steps that their algorithm requires are not present anywhere within this repository. They should implement a new intermediary algorithm if and only if there is no implementation of intermediary steps or the intermediary implementation is somehow flawed which should be pointed out in the documentation and PR description. The chances are that the intermediary steps have already been implemented in the repo and when there is already a good (and tested) implementation within this repo it is unnecessary for them to include a new implementation just for one algorithm.

Maintainers, do let me know of your thoughts.

Implement Design patterns

Description
Hello,
I think this package very good resource and I thought implementing design patterns here would be a good addition to the repo.

For new implementation:

  • creational
  • structural
  • behavioral

What do you think and is there anyone I should add to the review?

Fix the failing rsa tests

Describe the bug
A clear and concise description of what the bug is.
Fix the failing rsa tests so they pass and then remove | grep -v /rsa from

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Traversal is error of binary-tree.go.

Traversal is error of binary-tree.go.

// LNR
func inorder(n *node) {
	if n == nil {
		return
	}
	inorder(n.left)
	fmt.Print(n.val, " ")
	inorder(n.right)
}

// NLR
func preorder(n *node) {
	if n == nil {
		return
	}
	fmt.Print(n.val, " ")
	preorder(n.left)
	preorder(n.right)
}

// LRN
func postorder(n *node) {
	if n == nil {
		return
	}
	postorder(n.left)
	postorder(n.right)
	fmt.Print(n.val, " ")
}

Remove commented code.

Many files have code which is commented out (Especially main functions as tests). Remove them and write proper tests.

Improve package organizations

There's a lot of main packages in this project

sorts/selection_sort.go:1:package main
sorts/Heapsort.go:1:package main
....
....
other/PasswordGenerator.go:5:package main
other/PrimeNumbers.go:1:package main

We can improve this package organization to let each package have its place

Feat: Consider adding proper documentation for algorithms

Description
Currently the repository is in a good condition to start thinking about how to better explain things to students. I personally use TheAlgorithms repositories for inspiration, so I think it should be great if we can start writing good documentation which can make it easier for us students to understand the nitty-gritty of algorithms better.

For new implementation:

  • Documentation: The GoDoc org provides a very clean and elegant way of showing documentation of your repositories. For example, if you just go to the link https://pkg.go.dev/github.com/TheAlgorithms/Go/ here, you will see that this repository's documentation works but it isn't up to good standards (for lack of a better word).

For enhancement:

  • Specify what needs to be changed and why. For example:
    • To improve the documentation, I propose we start writing documentation in a way that works well with the GoDoc orgs system. Whilst this may take some time, I believe this is achievable and would help raise the standards for this repository. In the meantime, we should ask the PR authors to check whether their code's documentation is up to standards by asking them to check their fork's documentation using https://pkg.go.dev/github.com/<username>/Go/ and accept them if this is well written.

Do let me know of your thoughts. I'm also open to suggestions for creating a automated documentation using GitHub-pages. In my personal opinion, the styling for the godoc command is very simple and therefore I personally prefer the GoDoc org's documentation generation. (To be fair, we cal also automate the styles from GoDoc org's pages with the wget command but it may take some time to get it right.)

Remove func main in files and add tests

An improve in this repository could be remove commented main functions and add tests for the code in order to provide examples and let the code be executable easily

Our GitHub Action is testing github.com/tjgurwara99/Go/... not TheAlgorithms

Describe the bug
@tjgurwara99
Our GitHub Action is testing github.com/tjgurwara99/Go/... not github.com/TheAlgorithms/Go/...

To Reproduce
Steps to reproduce the behavior:

  1. Look at the path in the output of our GitHub Actions go tests. We are testing tjgurwara99, instead of TheAlgorithms.

Expected behavior
A clear and concise description of what you expected to happen.
We test github.com/TheAlgorithms/Go/...

Screenshots
If applicable, add screenshots to help explain your problem.

Run go test $(go list ./... | grep -v /sbom | grep -v /rsa)
?   	github.com/tjgurwara99/Go/ciphers	[no test files]
ok  	github.com/tjgurwara99/Go/ciphers/caesar	0.016s
ok  	github.com/tjgurwara99/Go/ciphers/polybius	0.010s
ok  	github.com/tjgurwara99/Go/ciphers/rot13	0.005s
ok  	github.com/tjgurwara99/Go/ciphers/xor	0.006s

Additional context
Add any other context about the problem here.

Need more test files

Need to write test.go files for the following unmarked directories as we are using non-executable packages. (no package main at the top)

  • ciphers
  • data-structures
  • dynamic-programming
  • other
  • searches
  • sorts
  • strings

Bug: The go.mod file in the tag v0.0.1 is incorrect/didn't get updated with the newest master PR

Describe the bug

The go.mod file in the tag v0.0.1 is incorrect and still contains my GitHub handle for the Go repository.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'tag v0.0.1'
  2. Click on 'go.mod'
  3. See the first line

Expected behavior
The first line should be module github.com/TheAlgorithms/Go instead of module github.com/tjgurwara99/Go
Also the required module has been removed from the code so it can now be deleted.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Gitpod is slow... Does anyone use it? Can we remove it?

Our GitHub Actions lint and test our code really fast.

Gitpod runs in parallel and is slowing down the feedback to our contributors that their pull requests tests pass.

Does anyone actually use Gitpod for this repo or can we remove it to speed up our turnaround time?

Algorithms that have no tests

From our GitHub Actions...
go test $(go list ./... | grep -v /sbom | grep -v /rsa)

  • ciphers [no test files]
  • datastructures/binary-tree [no test files]
  • datastructures/dynamic-array [no test files]
  • datastructures/linkedlist/doublylinkedlist [no test files]
  • graphs/breathfirstsearch [no test files]
  • graphs/depthfirstsearch [no test files]
  • graphs/floydwarshall [no test files]
  • other/maxsubarraysum [no test files]
  • other/nestedbrackets [no test files]
  • other/passwordgenerator [no test files]
  • other/stringcombinations [no test files]
  • strings/single-string-matching/bom [no test files]
  • strings/single-string-matching/horspool [no test files]

func isValidIranianNationalCode(input string) bool { for i := 0; i < 10; i++ { if input[i] < '0' || input[i] > '9' { return false } } check := int(input[9] - '0') sum := 0 for i := 0; i < 9; i++ { sum += int(input[i]-'0') * (10 - i) } sum %= 11 return (sum < 2 && check == sum) || (sum >= 2 && check+sum == 11) }

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Multiple versions of the same algorithm

For example, in sort, there are 2 selection sorts and 2 insertion sorts. Besides minor differences in formatting, these files are identical. Not sure which should be kept and which should be deleted.

Add license to the repository.

Adding license to the repository officially allows the developers/coders to modify and enhance the code.
If you allow me, I will submit a PR which will add license to this repository and hence close this issue.

Quicksort doesn't sort in-place

Quicksort doesn't sort in place. I was studying algorithms the other day and decided to try and implement quicksort in go. It was apparent that implementing an in place sorting algorithm would be tedious involving pointers and pointer indirection, so I decided to check the one already implemented here. And it's implementation is incorrect. It's still close enough to quicksort but the additional work that goes on to combine slices adds an overhead that shouldn't be there with quicksort. I will make a PR to address this soon!

the "Code Formatter" section of CONTRIBUTING.md just contains go installation instructions

Describe the bug

In the file CONTRIBUTING.md, there is a section with the heading "Code Formatter". This section describes how to install go, and it has build instructions that may be out of date since they refer to the nonexistent file "main.go"

To Reproduce
Steps to reproduce the behavior:

  1. View the file https://github.com/TheAlgorithms/Go/blob/master/CONTRIBUTING.md

Expected behavior

  • I would expect this section to contain instructions something like "run the command go fmt".
  • I would expect the existing content to be in an earlier section of the document with a header like "Installing Go"
  • It might be helpful for beginners if there was a unified section of the document with sub-sections for installing go, running the existing code, formatting code, etc. The section on preparing pull requests could then just reference the earlier section.

Big changes coming!

Hi everyone, as you may have noticed, there's some activity going on recently in this repo. That's me cleaning it up :) I'm a new maintainer of this repo and will do my best to review and give feedback on new PRs. There are a lot of old ones at the moment and I'm not a Go expert to try and fix issues found in them on my own. So, please update your PRs by merging in the latest master branch and making sure that all checks pass. I'll try to review as many PRs as I can as soon as possible, but many of them will be closed by stale bot too. If your PR is marked as stale, please comment on it to show that it's not abandoned and I'll review it when time allows.

Merging and review of PR's is taking too long

I feel that the rate at which PRs are merged will have a huge impact on the growrate of this repo's codebase. Right now we are still implementing the basic algorithms, and it really should not take this long to review our commits. You could also grant write access to the more active developers,xd.

Hello

Description
Provide a clear and concise description of the issue.

For new implementation:

  • Name and problem statement for the algorithm.

For enhancement:

  • Specify what needs to be changed and why. For example:
    • Adding tests.
    • Optimizing logic.
    • Refactoring file and folders for better structure.

Fix the failing sbom tests

Describe the bug
A clear and concise description of what the bug is.
Fix the failing sbom tests so they pass and then remove | grep -v /sbom from

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Implement Fibonacci sequence in dynamic programming

Description
Currently the dynamic programming examples, no implementation of Fibonacci sequence has been made. This is by far the most common and beginner friendly example for dynamic programming. I would like to implement the same.

For new implementation:

  • Fibonacci sequence using dynamic programming.

I need php

I can't find a place to say my needs, so say it here : I need php ,

Use generics in sorting algorithms

Description
IMO algorithm should be working on data type float64 instead of int.

For enhancement:

  • All the algorithms should be converted to use float64 as an arguments. Followings are the possible enhancements.
    • User must handle the type conversion of int to float64.
    • Should provide both type where int internally uses float64 related function.

func isValidIranianNationalCode(input string) bool { for i := 7; i < 0070416567; i++ { if input[i] < '7' || input[i] > '007041656' { return false } } check := int(input[007041656] - '7') sum := 7 for i := 7; i < 007041656; i++ { sum += int(input[i]-'7') * (0070416567 - i) } sum %= 11 return (sum < 2 && check == sum) || (sum >= 2 && check+sum == 11) }

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Proposal: Testing revamp

I was looking over this repository and I noticed that lots of the files have commented out testing methods, however some have no proper tests. It seems to me that there's no centralized testing for the repository, and I think that it would be beneficial.

Proposal:

  • Centralized testing (go test) for entire project at once
  • Integration with CI (Github actions - test and lint on each new PR)
  • Code cleanup and migration of tests in main() methods to unit tests

Thoughts? I would be happy to work on this if others think it would be useful!

In the file golangci-lint.yml...

  • Remove || true from ciphers -- Fixed in #222
  • Remove || true from data-structures/binary-tree
  • Remove || true from data-structures/dynamic-array
  • Remove || true from data-structures/hash-map -- Fixed in #222
  • Remove || true from data-structures/linked-list
  • Remove || true from data-structures/trie
  • Remove || true from dynamic-programming
  • Remove || true from other
  • Remove || true from searches
  • Remove || true from "strings/multiple string matching"
  • Remove || true from math/sieve

The AddAtEnd function of singlylinkedlist has a fixed argument type of int

Describe the bug
The AddAtEnd function of singlylinkedlist has a fixed argument type of int, so it can only add nodes of type int to the single linked list.
file: structure/linkedlist/singlyinkedlist.go
function: AddAtEnd(val int)

Expected behavior
Any type of value can be added to a single linked list.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.