GithubHelp home page GithubHelp logo

thealgorithms / c Goto Github PK

View Code? Open in Web Editor NEW
18.3K 516.0 4.2K 19.89 MB

Collection of various algorithms in mathematics, machine learning, computer science, physics, etc implemented in C for educational purposes.

Home Page: https://thealgorithms.github.io/C

License: GNU General Public License v3.0

C 96.74% Makefile 0.33% Dockerfile 0.02% CMake 2.38% Python 0.52%
algorithms data-structures datastructures c algorithm-challenges algorithm-competitions education learn-to-code interview-questions interview community-driven mathematics sort educational machine-learning-algorithms machine-learning computer-science search hacktoberfest

c's Introduction

The Algorithms - C # {#mainpage}

Gitpod Ready-to-Code CodeQL CI Gitter chat contributions welcome GitHub repo size Doxygen CI Awesome CI Income Discord chat Donate

Overview

The repository is a collection of open-source implementations of a variety of algorithms implemented in C and licensed under GPLv3 License. The algorithms span a variety of topics from computer science, mathematics and statistics, data science, machine learning, engineering, etc.. The implementations and their associated documentations are meant to provide a learning resource for educators and students. Hence, one may find more than one implementation for the same objective but using different algorithm strategies and optimizations.

Features

  • The repository provides implementations of various algorithms in one of the most fundamental general purpose languages - C.
  • Well documented source code with detailed explanations provide a valuable resource for educators and students alike.
  • Each source code is atomic using standard C library libc and no external libraries are required for their compilation and execution. Thus the fundamentals of the algorithms can be studied in much depth.
  • Source codes are compiled and tested for every commit on the latest versions of two major operating systems viz., MacOS and Ubuntu (Linux) using AppleClang 14.0.0 and GNU 11.3.0 respectively.
  • Strict adherence to C11 standard ensures portability of code to embedded systems as well like ESP32, ARM Cortex, etc. with little to no changes.
  • Self-checks within programs ensure correct implementations with confidence.
  • Modular implementations and OpenSource licensing enable the functions to be utilized conveniently in other applications.

Documentation

Online Documentation is generated from the repository source codes directly. The documentation contains all resources including source code snippets, details on execution of the programs, diagrammatic representation of program flow, and links to external resources where necessary. Click on Files menu to see the list of all the files documented with the code.

Documentation of Algorithms in C by The Algorithms Contributors is licensed under CC BY-SA 4.0
Creative Commons LicenseCredit must be given to the creatorAdaptations must be shared under the same terms

Contributions

As a community developed and maintained repository, we welcome new un-plagiarized quality contributions. Please read our Contribution Guidelines.

c's People

Contributors

alexpantyukhin avatar amitha-nayak avatar anupkumarpanwar avatar ashwek avatar ayaankhan98 avatar carloszoft avatar cclauss avatar christianbender avatar danghai avatar deadshotsb avatar dhruvpasricha avatar dsmurrow avatar dynamitechetan avatar harshildarji avatar ketan-lambat avatar koseokkyu avatar kvedala avatar northernsage avatar panquesito7 avatar r0hit-gupta avatar rachitbhalla avatar realduyuanchao avatar sachinarora707 avatar saurusxi avatar serturx avatar sh-ubh avatar shubhamsah avatar stepfenshawn avatar theycallmemac 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

c's Issues

Add more solution for Leetcode algorithm.

I create leetcode directory. You can contribute solution for Leetcode algorithm by C language.
Good practice coding :)
Please put some comment for explanation. It helps other people understand your algorithm better

Hacktoberfest 2020 - Implement C algorithms or data structures, fix existing ones and more!

The annual Hacktoberfest is around the corner! Register on Hacktoberfest's website and open 4 pull requests during October 2020 to receive the swags (if you're the first 70,000 participants)!

In our C repository, there are currently several open issues:

What's more, you can also fix an existing bugs, improve any documentation and provide better implementations for certain algorithms! Feel free to inform the community by filling an issue and start hacking! If you're new to contributing code, please read our Contribution Guidelines for an overall understanding and ask questions on the internet - Google, StackOverflow or our Gitter.

TheAlgorithms has repositories in other programming languages, so find your language and start coding there!

What you can do to participate

  1. Read our Contribution Guidelines
  2. Comment below or open an issue (for big ideas you may want the community to know) on your new implementations, fixes or functionalities
  3. Start hacking!
  4. Open a pull request for your contribution
  5. Label your pull requests with hacktoberfest
  6. Wait until your pull requests get reviewed or merged! In the meantime, you can review someone else's pull requests too

Useful links

Remarks

  • Please observe Hacktoberfest's rules, terms and FAQ. If a pull request is marked invalid or spam it would not be counted and the person may be disqualified for the swags.
  • Hacktoberfest 2020 is an event presented by DigitalOcean, Intel and DEV.

[BUG] Logical error fixed in conversions/c_atoi_str_to_integer.c

Description

Expected Behavior

Program should pass all the assertions.

Actual Behavior

Program failed to pass all the assertions.

Possible Fix

Improve the logic of the prgram to fix the error.

Steps to Reproduce

just compile and execute the program as it is.

Context

Make code more modular in nature

Presently, each algorithm implementation requires implementation of each underlying data structure from scratch. This is a hassle, as more than often the implementations of underlying data structures increases the code size unnecessarily.
For example, while implementing graph algorithms if we have to reimplement graph ADT again it will meaningless. Instead it would be good idea to implement a header file alongside, which could be used as includes later in other algorithms.
This issue aims to provide such modular nature in the present existing files.

the getMax function in binary search tree may not work correctly

Hi there,
I am learning data structure. it's really helpful to find such a excellent project. Thanks for the excellent work.

However, I found this code may not work correctly.

root->right = getMax(root->right);

let's say we have a tree like this
node *root = NULL;
root = insert(root, 100);
root = insert(root, 50);
root = insert(root, 25);
root = insert(root, 12);
root = insert(root, 35);
root = insert(root, 75);
root = insert(root, 58);
root = insert(root, 87);
root = insert(root, 150);
root = insert(root, 125);
root = insert(root, 175);
root = insert(root, 168);
root = insert(root, 180);

When I want to delete 50 from this tree, getMax function returns 25 for the max data of the left subtree of node 50, which should have to be 35. And after I delete 50 from this tree, I used inOrder function to check the updated tree. I got this:

[ 12 ] [ 35 ] [ 25 ] [ 58 ] [ 75 ] [ 87 ] [ 100 ] [ 125 ] [ 150 ] [ 168 ] [ 175 ] [ 180 ]

As you can see, the sequence is not correctly ordered.

I think the correct code for getMax should be:

node *getMax(node *root)
{
// If there's no leaf to the right, then this is the maximum key value
if (root->right == NULL)
return root;
else
// root->right = getMax(root->right);
return getMax(root->right);
}

Correct me if I was wrong, please.

Solutions for Project Euler should be deleted

Publishing the solutions destroys the Project Euler's intent.
Quoted from the site:

Q: ”I learned so much solving problem XXX so is it okay to publish my solution elsewhere?”
A: “It appears that you have answered your own question. There is nothing quite like that "Aha!" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, however, that will not be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself."

"Members have generally taken pride in showing their achievements. The obvious place to do so is the forum that is set up for each problem. However the increasing popularity has also been attracting people with a different agenda. With so many internet sites publishing answers for the PE problems instead of using the forum on this site, some people now seem to take pride in gathering and submitting those answers for whatever reason.

It is humanly impossible for Project Euler, or indeed any member, to reliably differentiate those people from members that have solved the problems under their own steam. The ranking lists on Project Euler should be interpreted for what they are: an indication of the number of correct answers submitted by the member in question and validated by our answer checker. Individual members themselves know best what they have achieved on their own. Laying too much stress on competition might spoil the fun of problem solving which is one of the purposes of Project Euler. Also, any claim from a member about his own achievement cannot be supported as trustworthy by Project Euler. If critical, other means from third parties would be required to verify such claims."

Link: https://projecteuler.net/

Counting Sort

The counting sort code here is not well formatted. I would like to re-format it, adding useful comments and proper indentation to make it more understandable. @danghai

Skip List[FEATURE]

Detailed Description

I can't find Skip List implementation

Context

Possible Implementation

I can contribute if it's possible

Felicitaciones

Me gusto mucho la forma de tratar con los datos obtenidos hacia la estructura, hace un buen manejo de las pilas y las colas bueno formación en cuanto a las posibilidades de como recibir los datos me gusto tu estilo de programación en este código espero ver muy pronto otro código y aprender de vos

Two Sort folder

There are 2 Sort folder: Sorts and sorting.
Which one should I contribute to?

Implimentation for the Trie data structure

In the data structure section there doesn't have Trie data structure. A Trie is a special data structure used to store strings that can be visualized like a graph.That is mostly used in Search Engines, Genome Analysis, Data Analytics. So I would like to implement Trie using C.

not working bubbleSort

C:\Users\Marcel\Desktop\Projekte\C-Projekte\Bubblesort_Github\cmake-build-debug\Bubblesort_Github.exe
Enter the value number 1
2
2
would you enter an other value (1:Continue/0:Sort the actual array)?
1
1
Enter the value number 2
3
3
would you enter an other value (1:Continue/0:Sort the actual array)?
1
1
Enter the value number 3
4
4
would you enter an other value (1:Continue/0:Sort the actual array)?
1
1
Enter the value number 4
1
1
would you enter an other value (1:Continue/0:Sort the actual array)?
0
0
1, 2, 3, 1811939332,
Process finished with exit code 0

2 Search folders

There are 2 separate folders in the repo for searching algorithms. Merge them.

[BUG] Unhandled Exception in Tic-tack-toe-game

Tick-Tack-Toe game is not working for exception part

Description

Else part on line 247 takes you to infinite loop on getting any char value as input for position.

Expected Behavior

It should give the option to enter value again

Actual Behavior

Infite Loop with print value - Invalid value

Logical Error Fixed

Description

Bug fixed in conversions/c_atoi_str_to_integer.c & formatting
Logical error fixed in conversions/c_atoi_str_to_integer.c

Expected Behavior

Should succesfully pass all assertions

Actual Behavior

Fails to pass all assertions.

Possible Fix

Steps to Reproduce

Compile & Execute Code.

Context

Failed to assert all the checks.

a bug

C/data_structures/stack.c

I think there is a bug !

the node->next always equal to NULL

Prime.c

I tested it with the lowest prime number but it tells me that it's actually not one.

Adding the following to isPrime function solved the issue for me
if (x == 2)
return 1;

[FEATURE]

Detailed Description

Context

Possible Implementation

Translation of README.md

You think is a good idea to add translations of the README.md?
I can write the spanish version.

[BUG] multikey_quick_sort.c - erroneous

erroneous code sequences

Description

  • line# 259 -> while loop has invalid termination condition because pp variable is not initialized and garbage value.

Expected Behavior

Actual Behavior

Possible Fix

Steps to Reproduce

Context

Jogo de adivinha qual número é maior

#include <stdio.h>
main (){
int num, num2, menor,maior;
printf("\n----------------------------------");
printf("\n| JOGO DO NÚMERO MAIOR OU MENOR |");
printf("\n----------------------------------");
printf("\n\nDigite o número 1: ");
scanf("%d",&num);
printf("\nDigite o número 2: ");
scanf("%d", &num2);
if (num > num2)
printf("\n\nNumero 1 é Maior que o Número 2");

    if (num < num2)
    printf("\n\nNumero 2 é Maior que o Número 1");
    
    else 
    printf("\n\nOs dois Números são iguais");

return (0);
}

Compilation Error otherBinarySearch

gcc -Wall -Werror otherBinarySearch.c -o otherBinarySearch
otherBinarySearch.c:3:13: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
 #define len 5
             ^
otherBinarySearch.c:5:36: note: in expansion of macro ‘len’
 int binarySearch(int array[] , int len , int searchX)
                                    ^~~

This is because pre-processor is replacing len with 5 in the function prototype.
https://stackoverflow.com/a/7103183

[BUG]

Description

Expected Behavior

Actual Behavior

Possible Fix

Steps to Reproduce

Context

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.