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
Pathfinding algorithm based on A*

Pathfinding V1 What is pathfindingV1 ? This program is my very first path finding program, using python and turtle for graphic rendering. How is it wo

Yan'D 6 May 26, 2022
Sign data using symmetric-key algorithm encryption.

Sign data using symmetric-key algorithm encryption. Validate signed data and identify possible validation errors. Uses sha-(1, 224, 256, 385 and 512)/hmac for signature encryption. Custom hash algori

Artur Barseghyan 39 Jun 10, 2022
A calculator to test numbers against the collatz conjecture

The Collatz Calculator This is an algorithm custom built by Kyle Dickey, used to test numbers against the simple rules of the Collatz Conjecture. Get

Kyle Dickey 2 Jun 14, 2022
A Python program to easily solve the n-queens problem using min-conflicts algorithm

QueensProblem A program to easily solve the n-queens problem using min-conflicts algorithm Performances estimated with a sample of 1000 different rand

0 Oct 21, 2022
Distributed algorithms, reimplemented for fun and practice

Distributed Algorithms Playground for reimplementing and experimenting with algorithms for distributed computing. Usage Running the code for Ring-AllR

Mahan Tourkaman 1 Oct 16, 2022
Solving a card game with three search algorithms: BFS, IDS, and A*

Search Algorithms Overview In this project, we want to solve a card game with three search algorithms. In this card game, we have to sort our cards by

Korosh 5 Aug 04, 2022
Better control of your asyncio tasks

quattro: task control for asyncio quattro is an Apache 2 licensed library, written in Python, for task control in asyncio applications. quattro is inf

Tin Tvrtković 37 Dec 28, 2022
Algoritmos de busca:

Algoritmos-de-Buscas Algoritmos de busca: Abaixo está a interface da aplicação: Ao selecionar o tipo de busca e o caminho, então será realizado o cálc

Elielson Barbosa 5 Oct 04, 2021
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
A simple python implementation of A* and bfs algorithm solving Eight-Puzzle

A simple python implementation of A* and bfs algorithm solving Eight-Puzzle

2 May 22, 2022
A raw implementation of the nearest insertion algorithm to resolve TSP problems in a TXT format.

TSP-Nearest-Insertion A raw implementation of the nearest insertion algorithm to resolve TSP problems in a TXT format. Instructions Load a txt file wi

sjas_Phantom 1 Dec 02, 2021
Exact algorithm for computing two-sided statistical tolerance intervals under a normal distribution assumption using Python.

norm-tol-int Exact algorithm for computing two-sided statistical tolerance intervals under a normal distribution assumption using Python. Methods The

Jed Ludlow 1 Jan 06, 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
Algorithms written in different programming languages

Data Structures and Algorithms Clean example implementations of data structures and algorithms written in different languages. List of implementations

Zoran Pandovski 1.3k Jan 03, 2023
Algorithms for calibrating power grid distribution system models

Distribution System Model Calibration Algorithms The code in this library was developed by Sandia National Laboratories under funding provided by the

Sandia National Laboratories 2 Oct 31, 2022
Algorithmic Trading with Python

Source code for Algorithmic Trading with Python (2020) by Chris Conlan

Chris Conlan 1.3k Jan 03, 2023
Implementation of core NuPIC algorithms in C++

NuPIC Core This repository contains the C++ source code for the Numenta Platform for Intelligent Computing (NuPIC)

Numenta 270 Nov 19, 2022
Greedy Algorithm-Problem Solving

MAX-MIN-Hackrrank-Python-Solution Greedy Algorithm-Problem Solving You will be given a list of integers, , and a single integer . You must create an a

Mahesh Nagargoje 3 Jul 13, 2021
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
A collection of design patterns/idioms in Python

python-patterns A collection of design patterns and idioms in Python. Current Patterns Creational Patterns: Pattern Description abstract_factory use a

Sakis Kasampalis 36.2k Jan 05, 2023