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

Overview

The Algorithms - C # {#mainpage}

Gitpod Ready-to-Code Language grade: C/C++ Gitter chat contributions welcome GitHub repo size Doxygen CI Awesome CI Income Donate

Overview

The repository is a collection of open-source implementation 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 the associated documentation 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 a 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 three major operating systems viz., Windows, MacOS and Ubuntu (Linux) using MSVC 16 2019, AppleClang 11.0 and GNU 7.5.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.

Comments
  • Major rework to improve code quality, add automation checks and self hosted autogenerated documetnation website

    Major rework to improve code quality, add automation checks and self hosted autogenerated documetnation website

    Description of Change

    • Add cmake based structure
    • Include documentation building
    • Add GitHub Actions using cmake to check code compilation on linux (ubuntu), Mac OS and Windows (using MS Visual C/C++ compiler)
    • Add GitHub action to auto-generate documentation and push to repo's respective GitHub Pages -> this will create the website https://thealgorithms.github.io/C similar to https://kvedala.github.io/C
    • add documentations to various source codes including mathematical formulations where possible
    • fix code formatting issues with existing files
    • fix source codes so they compile on all operating systems
    • github actions workflow improved by
      • adding auto format code and file name
      • stage-by-stage actions for efficient checks

    This documentation approach will also enable other contributors to add documentation in their respective languages or use google translate to do so.

    Checklist

    • [x] Added description of change
    • [x] Added file name normalization - all small letters and no spaces
    • [x] Added tests and example, test must pass - wherever possible
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] Sort by alphabetical order
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Note

    Before merging, the parent repository branch structure would need to be improved (Adding images branch, adding gh-pages branch). Unless existing maintainers are up for the challenge, I,d like to volunteer to maintain the structure of the repo and the documentation of the same. It’d allow us to have graphs and files for a much better documentation.

    opened by kvedala 19
  • Add more solution for Leetcode algorithm.

    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

    help wanted hacktoberfest Practice coding Stale 
    opened by danghai 18
  • Add Absolute Value

    Add Absolute Value

    Description of Change

    absolute value

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [x] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    enhancement wontfix Admin views requested approved 
    opened by duyuanch 17
  • feat: Get a trace of all of the allocations, using a doubly linked list and wrappers for malloc/calloc and free.

    feat: Get a trace of all of the allocations, using a doubly linked list and wrappers for malloc/calloc and free.

    Hello, i created a new directory named "debugging". In this directory, i have created three new files : malloc_dbg.c, malloc_dbg.h and test.c

    The main objective of these files is to know where a memory leak occurred (even on a Windows computer where valgrind doesn't exists and without having to use WSL). The test.c only contains a main function in which we call malloc and calloc and we only free one of the two pointers.

    In malloc_dbg.h there are three macros : malloc, calloc and free. There are also the prototypes of the functions malloc_dbg, calloc_dbg, free_dbg and printLeaks.

    The malloc_dbg.c file contains the definitions of the above functions and a structure (a doubly linked list which is used to store a pointer returned by malloc/calloc, the number of bytes that have been allocated, the file from where malloc/calloc was called and the line number of this call).

    malloc_dbg and calloc_dbg functions both calls atexit() to make sure the leaks will be printed at the end of the execution.

    In test.c file, we simply include malloc_dbg.h to be able to use the macros.

    When the program exits, it should print if there are memory leaks or no, for example : "Memory Leaks detected.

    256 bytes lost address : 0x0x558c8a33e310 in main test.c:23

    ==================================== SUMMARY : 256 bytes lost in 1 blocks"

    This has been tested under Linux and Windows.

    enhancement approved 
    opened by tinouduart33 15
  • feat: leetcode zigzag solution

    feat: leetcode zigzag solution

    Description of Change

    A solution for the ZigZag conversion problem.

    References

    Hacktoberfest issue

    ZigZag Conversion problem on leetcode

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [x] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes: Solution to the 6-ZigZag conversion problem was missing. Here is (decent) one.

    ZigZagConversion-SubmissionDetail-LeetCode.pdf

    enhancement approved 
    opened by straight-into-the-wall 14
  • Create Kruskal

    Create Kruskal

    Description of Change

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [x] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    invalid Stale 
    opened by ishanisamanta 14
  • [FEATURE] Beginners friendly Array implementation

    [FEATURE] Beginners friendly Array implementation

    Detailed description

    The code provided in the Array Repository can only be understood by advanced C users. I hereby propose a basic array implementation and performing some basic operations using the same array implementation.

    Context

    This repository according to its description states that it consists of various Algorithms implementation using C language. But the code mentioned in the repository cannot be used by novice coders or other interested people easily. So I suggest a commonly used method of representing arrays along with its commonly used operations.

    Possible implementation

    No response

    Additional information

    No response

    enhancement Stale 
    opened by Saradwata-Bandyopadhyay 13
  • fix: several bugs on games/tic_tac_toe.c

    fix: several bugs on games/tic_tac_toe.c

    Description of Change

    Issue: #729 As mentioned in the issue , The piece code listed below throws the program into an loop (from line 247) if an invalid character is entered.

            else
            {
    +            int n = check_placex();
    -             printf("Invalid move\n");
    
    -            printf("Enter new position : ");
    -            scanf("%d", &n1);
    +           placex(n);
    -            placex(n1);
            }
        }
        else
        {
    -        printf("Invalid move \n");
    +       int n = check_placex();
    -        printf("Enter new position : ");
    -        scanf("%d", &n1);
    +       placex(n);
    -        placex(n1);
        }
    }
    

    Fixes / Changes

    Added an array [dynamic] at line36 :
    + int *stored_pos = NULL;
    

    line 47:

    +  stored_pos = (int*)calloc(9,sizeof(int))
    
    Assignment of the stored_pos array:

    line 331, line 308 & line 278

    example:

    + stored_pos[e] = 1;
    
    Freed the stored_pos memory

    line 75

    + free(stored_pos);
    
    Added a new function called check_places at line237 to line256
    int check_placex(){
    	char input[50];
    	int n1;
    	while (1){
    		fgets(input,49,stdin);
    		if ( strlen(input) > 2 || strlen(input)  == 0){
    			fprintf(stderr,"Invalid move, Enter number 1 - 9: ");
    			continue;
    		}
    		if(sscanf(input,"%d",&n1) != 1){
    			fprintf(stderr,"Invalid move, Enter number 1 - 9: ");
    			continue;
    		} 
    		if ((stored_pos[n1-1] == 1) || (n1== 0)){
    			fprintf(stderr,"Already allocated, Enter number: ");
    			continue;
    		}
    		return n1;
    	}
    }	
    

    The while-loop in the above above function will ask for an input until it gets a correct output.

    1. The first if condition checks whether the input is within the range. (strlen() is used so string.h lib is need)
    2. Second if condition checks if the value is integer
    3. Third if condition checks if the value (posistion) is already occupied.

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [x] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    enhancement Changes requested bugfix 
    opened by kana800 12
  • feat: Project Euler Problem #107

    feat: Project Euler Problem #107

    Description of Change

    Add a solution to project euler problem 107 using Kruskal's algorithm. I've followed the contribution guidelines to the best of my abilities, please lmk of any changes you would like to be made. Thank you for your time!

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [x] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    enhancement Changes requested Stale 
    opened by Daves1245 12
  • binary-tree

    binary-tree

    Description of Change

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [x] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    enhancement Changes requested Stale 
    opened by Aarti002 12
  • feat: K Means Clustering Added

    feat: K Means Clustering Added

    Implemented K Means Clustering in C The data set used for implementing is ordered pair(x,y) in 2D plane.

    Description of Change

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [x] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes: The Link Checks are always failing I am really unable to understand why If you can refer some resources to learn about it that would be really helpful.

    opened by Lakhan-Nad 11
  • add leetcode Maximum Bags With Full Capacity of Rocks

    add leetcode Maximum Bags With Full Capacity of Rocks

    Description of Change

    Add a guide for new LeetCode solutions.

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [ ] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    Leetcode folder changes 
    opened by alexpantyukhin 0
  • add leetcode Frequency of the Most Frequent Element

    add leetcode Frequency of the Most Frequent Element

    Description of Change

    Add a guide for new LeetCode solutions.

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [ ] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    Leetcode folder changes 
    opened by alexpantyukhin 0
  • add leetcode Pow(x, n)

    add leetcode Pow(x, n)

    Description of Change

    Add a guide for new LeetCode solutions.

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [ ] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    Leetcode folder changes 
    opened by alexpantyukhin 0
  • add leetcode Determine if Two Strings Are Close

    add leetcode Determine if Two Strings Are Close

    Description of Change

    Add a guide for new LeetCode solutions.

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [ ] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    Leetcode folder changes 
    opened by alexpantyukhin 0
  • add labeler for Leetcode changes folder

    add labeler for Leetcode changes folder

    Description of Change

    Add the leetcode labeler for leetcode change folder label.

    References

    Checklist

    • [x] Added description of change
    • [ ] Added file name matches File name guidelines
    • [ ] Added tests and example, test must pass
    • [ ] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    enhancement 
    opened by alexpantyukhin 0
  • add leetcode Keys and Rooms

    add leetcode Keys and Rooms

    Description of Change

    Add a guide for new LeetCode solutions.

    References

    Checklist

    • [x] Added description of change
    • [x] Added file name matches File name guidelines
    • [ ] Added tests and example, test must pass
    • [x] Relevant documentation/comments is changed or added
    • [x] PR title follows semantic commit guidelines
    • [x] Search previous suggestions before making a new one, as yours may be a duplicate.
    • [x] I acknowledge that all my contributions will be made under the project's license.

    Notes:

    Leetcode folder changes 
    opened by alexpantyukhin 0
Owner
The Algorithms
Open Source resource for learning Data Structures & Algorithms and their implementation in any Programming Language
The Algorithms
Algorithms for sound filters, like reverb, dynamic range compression, lowpass, highpass, notch, etc

sndfilter Algorithms for sound filters, like reverb, dynamic range compression, lowpass, highpass, notch, etc. It's easy to find countless math equati

Sean 362 Dec 22, 2022
Several algorithms and data structures implemented in C++ by me (credited to others where necessary).

Algorithms This repository contains my implementations of several algorithms and data structures in C++ (credited to others where necessary). It has i

Petar Veličković 589 Dec 19, 2022
In this project, we implemented twelve different sorting algorithms.

C - Sorting algorithms & Big O In this project, we implemented twelve different sorting algorithms. Tests tests: Folder of test files. Provided by Alx

Nicholas M Mwanza 1 Oct 26, 2021
Collection of algorithms and data structures in C++ and Java

Collection of algorithms and data structures in C++ and Java

Andrei Navumenka 1.7k Jan 2, 2023
C++17 (-O2) template for competitive programming algorithms, which contains numerous math algorithms.

cpplibForCP C++17 (-O2) template for competitive programming algorithms, which contains numerous math algorithms. Aims: build a stable, fast, easy-to-

null 33 Nov 25, 2022
Shamir’s Secret Sharing Algorithm: Shamir’s Secret Sharing is an algorithm in cryptography created by Adi Shamir. The main aim of this algorithm is to divide secret that needs to be encrypted into various unique parts.

Shamir-s-Secret-Sharing-Algorithm-Cryptography Shamir’s Secret Sharing Algorithm: Shamir’s Secret Sharing is an algorithm in cryptography created by A

Pavan Ananth Sharma 5 Jul 5, 2022
This project implemented the Mean Value Coordinates in 3D algorithm in c++

Mean Value Coordinates in 3D [c++] | Paper link on Sciencedirect | Pdf version link | This project implemented the Mean Value Coordinates in 3D algori

null 3 Nov 22, 2022
A global planner plugin for ROS navigation stack, in which A* search on a discrete gneralized Voronoi diagram (GVD) is implemented.

voronoi_planner This repo contains a global planner plugin for ROS navigation stack, in which A* search on a discrete gneralized Voronoi diagram (GVD)

Jian Wen 17 Nov 30, 2022
WasmEdge Runtime is a high-performance, extensible, and hardware optimized WebAssembly Virtual Machine for automotive, cloud, AI, and blockchain applications.

WasmEdge Runtime is a high-performance, extensible, and hardware optimized WebAssembly Virtual Machine for automotive, cloud, AI, and blockchain applications.

null 5.1k Jan 5, 2023
llvm-tutor is a collection of self-contained reference LLVM passes

llvm-tutor is a collection of self-contained reference LLVM passes. It's a tutorial that targets novice and aspiring LLVM developers.

Andrzej Warzyński 1.9k Dec 28, 2022
A library of common data structures and algorithms written in C.

C Algorithms The C programming language includes a very limited standard library in comparison to other modern programming languages. This is a coll

Simon Howard 2.9k Jan 9, 2023
Algorithms & Data structures in C++.

Algorithms & Data Structures in C++ 目标 ( goal ) : 经典的算法实现 (classical algorithms implementations) 服务器端 (based on linux/gcc) 正确,易于使用和改造, 一个头文件一个算法,并附带一个

xtaci 4.7k Dec 30, 2022
C++ implementations of well-known (and some rare) algorithms, while following good software development practices

ProAlgos: C++ This project is focused on implementing algorithms and data structures in C++, while following good software engineering practices, such

ProAlgos 485 Dec 7, 2022
This repository contains path planning algorithms in C++ for a grid based search.

This repository contains path planning algorithms in C++ for a grid based search.

null 245 Dec 30, 2022
Provide building blocks (software, hardware and algorithms) for implementing SLAM using small sensors

RemoteSLAM The purpose of this repo is to provide the building blocks (software drivers, hardware and algorithms) for implementing SLAM systems using

Autonomous Drones Lab, Tel Aviv University 38 Jan 20, 2022
Fundamentals of Data structures and algorithms in c++

Data Structures & Algorithms About the repository: Contains theories and programming questions related to fundamentals of data structures and algorith

fifu 46 Dec 1, 2022
CXXGraph is a Header-Only C++ Library for Graph Representation and Algorithms

CXXGraph is a small library, header only, that manages the Graph and it's algorithms in C++. In other words a "Comprehensive C++ Graph Library".

ZigRazor 186 Dec 29, 2022
Library for building multi-level indoor routes using routing algorithms.

Library for building multi-level indoor routes using routing algorithms. You can easily construct routing graphs and find the shortest path for optimal indoor navigation.

Navigine 5 Nov 21, 2022
Header-only C++ library for robotics, control, and path planning algorithms.

Header-only C++ library for robotics, control, and path planning algorithms.

null 360 Dec 13, 2022