Minimal examples of data structures and algorithms in Python

Overview

PyPI version Open Source Helpers Build Status Coverage Status

Pythonic Data Structures and Algorithms

Minimal and clean example implementations of data structures and algorithms in Python 3.

Contributing

Thanks for your interest in contributing! There are many ways to contribute to this project. Get started here

Tests

Use unittest

For running all tests write down:

$ python3 -m unittest discover tests

For running some specific tests you can do this as following (Ex: sort):

$ python3 -m unittest tests.test_sort

Use pytest

For running all tests write down:

$ python3 -m pytest tests

Install

If you want to use the API algorithms in your code, it is as simple as:

$ pip3 install algorithms

You can test by creating a python file: (Ex: use merge_sort in sort)

from algorithms.sort import merge_sort

if __name__ == "__main__":
    my_list = [1, 8, 3, 5, 6]
    my_list = merge_sort(my_list)
    print(my_list)

Uninstall

If you want to uninstall algorithms, it is as simple as:

$ pip3 uninstall -y algorithms

List of Implementations

Contributors

Thanks to all the contributors who helped in building the repo.

Comments
  • Implement bst tree

    Implement bst tree

    Hi, I implement the bst tree. insert, and search works now. But I am not sure why size method does not work: The error: AttributeError: 'NoneType' object has no attribute 'size' @goswami-rahul @christianbender Could you help me?

    opened by danghai 16
  • Plan for testing

    Plan for testing

    I want to add some additional matrix algorithms and some tests for that.

    So, do you have a testing plan of test format, rules of in/output example data, test script name and others?

    enhancement 
    opened by mingrammer 16
  • Logo/Icon

    Logo/Icon

    Greetings, Im a graphics designer here on Github and I would like to ask for your permission to design for your logo/icon that you maybe used for your future plans in your project. I want to help open source projects by designing logos or banners for there project. Thank you for your time reading this

    Best regards -jbeguna04

    opened by jbeguna04 15
  • added nearest neighbor algorithm - machine-learning

    added nearest neighbor algorithm - machine-learning

    • Two functions nearest_neighbor(x, tSet) and a (eulidean) distance function distance(x,y).
    • I used the numpy library for calculating the absolute value of a vector.
    • Two trainings sets for the logical AND-function and for color-analysing (dark/light color).

    Have someone a tip for finding the k-nearest neighbors? I wrote a simple algorithm.

    • [X] If creating a new file :

      • [X] added links to it in the README files ?
      • [X] included tests with it ?
      • [ ] added description (overview of algorithm, time and space compleixty, and possible edge case) in docstrings ?
    • [ ] if done some changes :

      • [ ] wrote short description in the PR explaining what the changes do ?
      • [ ] Fixes #[issue number] if related to any issue
    • [] other

    opened by christianbender 14
  • separate test module

    separate test module

    Since we now have tests in most of the algorithms, I think it is a good idea to have a separate test_module.py file in each module. We can move all the tests from one module to it, and any further algorithms must have their tests in this file. It will make the repo easy to manage. @keon what do you think? I can start working on this.

    help wanted for newcomers 
    opened by goswami-rahul 11
  • WIP: Fix some issues in Travis and add more python env

    WIP: Fix some issues in Travis and add more python env

    This PR does some tasks:

    • [x] : Add requirements dependency in requirements.txt for algorithms.

    • [x] : Update cache, and coverall ( algorithms and tests) in Travis

    • [x] : Switch to use tox for running the unittest, coveralls. Add more python environment for testing. It does not only test for python 3.6. It could probably test python 3.4, 3.5, 3.6

    opened by danghai 10
  • Fix sort

    Fix sort

    I added doc sting to wiggle_sort.py, modified counting_sort.py and merge_sort.py so that the type of returned array is also numpy.ndarray when the type of input array is numpy.ndarray (the other sort method already achieved this). I alos wrap function in quick_sort.py, so we can use quick sort just like other sort method. And I also modified all the files according to pep8 specification.

    opened by techkang 10
  • Tests in directory tests

    Tests in directory tests

    tests
    If I ran the tests I get this kind of error message:

    from search.binary_search import binary_search, binary_search_recur ImportError: No module named 'search'

    or

    from array.delete_nth import delete_nth, delete_nth_naive ImportError: No module named 'array.delete_nth'; 'array' is not a package

    opened by christianbender 9
  • Adding k_factor.py in dp folder in add_K_FactorofStrings branch

    Adding k_factor.py in dp folder in add_K_FactorofStrings branch

    I have implemented an algorithm to solve a dp problem named "K-factor" Problem statement: The K factor of a string is defined as the number of times ‘abba’ appears as a substring. Given two numbers N and k,​ find the number of strings of length N with ‘K factor’ = k.

    opened by TheCodeYoda 8
  • Added fractional knapsack

    Added fractional knapsack

    I have added fractional knapsack code under greedy. Given the weights and values of n items, we need to put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In Fractional Knapsack, we can break items for maximizing the total value of the knapsack.

    hacktoberfest-accepted 
    opened by ritikverma2000 8
  • Organizing the repo neatly

    Organizing the repo neatly

    Hey guys, I was wondering we should put all the algorithms in an algorithm folder or something. I feel like It's getting big with all those new files being added to it. I have to scroll all the way down or up to get to where I want and right now I feel it is a bit disorganized. It would be very easy for readers to just click the algorithm folder and look for the intended algorithms inside it. The extra junk can remain outside. What do you guys think?

    enhancement 
    opened by SaadBenn 8
  • Added 4 more algorithms with test case

    Added 4 more algorithms with test case

    Reference issues/PRs:

    None

    What does this implementation/fix? Explain your changes.

    These are just some algorithm that I found useful.

    algorithms/dp/ 1. Wildcard matching 2. Trapping rain water

    algorithms/graph/ 1. Kadane's algorithm 2. Kahn's algorithm

    Any other comments?

    No

    opened by Yash5675 0
Releases(v0.1.4)
Owner
Keon
Keon
Policy Gradient Algorithms (One Step Actor Critic & PPO) from scratch using Numpy

Policy Gradient Algorithms From Scratch (NumPy) This repository showcases two policy gradient algorithms (One Step Actor Critic and Proximal Policy Op

1 Jan 17, 2022
Primedice like provably fair algorithm

Primedice like provably fair algorithm

Ryu juheon 3 Dec 02, 2022
A simple library for implementing common design patterns.

PyPattyrn from pypattyrn.creational.singleton import Singleton class DummyClass(object, metaclass=Singleton): # DummyClass is now a Singleton!

1.7k Jan 01, 2023
🧬 Performant Evolutionary Algorithms For Python with Ray support

🧬 Performant Evolutionary Algorithms For Python with Ray support

Nathan 49 Oct 20, 2022
Fedlearn algorithm toolkit for researchers

Fedlearn algorithm toolkit for researchers

89 Nov 14, 2022
Python-Strongest-Encrypter - Transform your text into encrypted symbols using their dictionary

How does the encrypter works? Transform your text into encrypted symbols using t

1 Jul 10, 2022
Algorithmic trading backtest and optimization examples using order book imbalances. (bitcoin, cryptocurrency, bitmex)

Algorithmic trading backtest and optimization examples using order book imbalances. (bitcoin, cryptocurrency, bitmex)

172 Dec 21, 2022
Implementation of an ordered dithering algorithm used in computer graphics

Ordered Dithering Project In this project, we use an ordered dithering method to turn an RGB image, first to a gray scale image and then, turn the gra

1 Oct 26, 2021
A selection of a few algorithms used to sort or search an array

Sort and search algorithms This repository has some common search / sort algorithms written in python, I also included the pseudocode of each algorith

0 Apr 02, 2022
ROS Basics and TurtleSim

Homework 1: Turtle Control Package Anna Garverick This package draws given waypoints, then waits for a service call with a start position to send the

Anna Garverick 1 Nov 22, 2021
Python algorithm to determine the optimal elevation threshold of a GNSS receiver, by using a statistical test known as the Brown-Forsynthe test.

Levene and Brown-Forsynthe: Test for variances Application to Global Navigation Satellite Systems (GNSS) Python algorithm to determine the optimal ele

Nicolas Gachancipa 2 Aug 09, 2022
Genetic algorithm which evolves aoe2 DE ai scripts

AlphaScripter Use the power of genetic algorithms to evolve AI scripts for Age of Empires II : Definitive Edition. For now this package runs in AOC Us

6 Nov 04, 2022
🌟 Python algorithm team note for programming competition or coding test

🌟 Python algorithm team note for programming competition or coding test

Seung Hoon Lee 3 Feb 25, 2022
An NUS timetable generator which uses a genetic algorithm to optimise timetables to suit the needs of NUS students.

A timetable optimiser for NUS which uses an evolutionary algorithm to "breed" a timetable suited to your needs.

Nicholas Lee 3 Jan 09, 2022
This is a Python implementation of the HMRF algorithm on networks with categorial variables.

Salad Salad is an Open Source Python library to segment tissues into different biologically relevant regions based on Hidden Markov Random Fields. The

1 Nov 16, 2021
Genius Square puzzle solver in Python

Genius Square puzzle solver in Python

James 3 Dec 15, 2022
Implementation for Evolution of Strategies for Cooperation

Moraliser Implementation for Evolution of Strategies for Cooperation Dependencies You will need a python3 (= 3.8) environment to run the code. Before

1 Dec 21, 2021
It is a platform that implements some path planning algorithms.

PathPlanningAlgorithms It is a platform that implements some path planning algorithms. Main dependence: python3.7, opencv4.1.1.26 (for image show) Tip

5 Feb 24, 2022
causal-learn: Causal Discovery for Python

causal-learn: Causal Discovery for Python Causal-learn is a python package for causal discovery that implements both classical and state-of-the-art ca

589 Dec 29, 2022
:computer: Data Structures and Algorithms in Python

Algorithms in Python Implementations of a few algorithms and datastructures for fun and profit! Completed Karatsuba Multiplication Basic Sorting Rabin

Prakhar Srivastav 2.9k Jan 01, 2023