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
Algorithms and data structures for educational, demonstrational and experimental purposes.

Algorithms and Data Structures (ands) Introduction This project was created for personal use mostly while studying for an exam (starting in the month

50 Dec 06, 2022
A Python project for optimizing the 8 Queens Puzzle using the Genetic Algorithm implemented in PyGAD.

8QueensGenetic A Python project for optimizing the 8 Queens Puzzle using the Genetic Algorithm implemented in PyGAD. The project uses the Kivy cross-p

Ahmed Gad 16 Nov 13, 2022
QDax is a tool to accelerate Quality-Diveristy (QD) algorithms through hardware accelerators and massive parallelism

QDax: Accelerated Quality-Diversity QDax is a tool to accelerate Quality-Diveristy (QD) algorithms through hardware accelerators and massive paralleli

Adaptive and Intelligent Robotics Lab 183 Dec 30, 2022
A library for benchmarking, developing and deploying deep learning anomaly detection algorithms

A library for benchmarking, developing and deploying deep learning anomaly detection algorithms Key Features • Getting Started • Docs • License Introd

OpenVINO Toolkit 1.5k Jan 04, 2023
Exam Schedule Generator using Genetic Algorithm

Exam Schedule Generator using Genetic Algorithm Requirements Use any kind of crossover Choose any justifiable rate of mutation Use roulette wheel sele

Sana Khan 1 Jan 12, 2022
PathPlanning - Common used path planning algorithms with animations.

Overview This repository implements some common path planning algorithms used in robotics, including Search-based algorithms and Sampling-based algori

Huiming Zhou 5.1k Jan 08, 2023
Given a list of tickers, this algorithm generates a recommended portfolio for high-risk investors.

RiskyPortfolioGenerator Given a list of tickers, this algorithm generates a recommended portfolio for high-risk investors. Working in a group, we crea

Victoria Zhao 2 Jan 13, 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
Gnat - GNAT is NOT Algorithmic Trading

GNAT GNAT is NOT Algorithmic Trading! GNAT is a financial tool with two goals in

Sher Shah 2 Jan 09, 2022
Pathfinding visualizer in pygame: A*

Pathfinding Visualizer A* What is this A* algorithm ? Simply put, it is an algorithm that aims to find the shortest possible path between two location

0 Feb 26, 2022
Evol is clear dsl for composable evolutionary algorithms that optimised for joy.

Evol is clear dsl for composable evolutionary algorithms that optimised for joy. Installation We currently support python3.6 and python3.7 and you can

GoDataDriven 178 Dec 27, 2022
HashDB is a community-sourced library of hashing algorithms used in malware.

HashDB HashDB is a community-sourced library of hashing algorithms used in malware. How To Use HashDB HashDB can be used as a stand alone hashing libr

OALabs 216 Jan 06, 2023
Python implementation of Aho-Corasick algorithm for string searching

Python implementation of Aho-Corasick algorithm for string searching

Daniel O'Sullivan 1 Dec 31, 2021
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
My own Unicode compression algorithm

Zee Code ZCode is a custom compression algorithm I originally developed for a competition held for the Spring 2019 Datastructures and Algorithms cours

Vahid Zehtab 2 Oct 20, 2021
Robotic Path Planner for a 2D Sphere World

Robotic Path Planner for a 2D Sphere World This repository contains code implementing a robotic path planner in a 2D sphere world with obstacles. The

Matthew Miceli 1 Nov 19, 2021
Implementation of Apriori algorithms via Python

Installing run bellow command for installing all packages pip install -r requirements.txt Data Put csv data under this directory "infrastructure/data

Mahdi Rezaei 0 Jul 25, 2022
Using Bayesian, KNN, Logistic Regression to classify spam and non-spam.

Make Sure the dataset file "spamData.mat" is in the folder spam\src Environment: Python --version = 3.7 Third Party: numpy, matplotlib, math, scipy

0 Dec 26, 2021
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