Algorithms and data structures for educational, demonstrational and experimental purposes.

Overview

Algorithms and Data Structures (ands)

Python 3.5+ Build Status Coverage Status Codacy Badge Packagist

Introduction

This project was created for personal use mostly while studying for an exam (starting in the month of June in 2015) of a previous course that I followed called Algorithms and Data Structures I decided to make it publicly available to use and modify, so that people with difficulties in understanding and applying these topics can take benefit from it.

I discourage every beginner from copying shamelessly the source code, but instead you should definitely give a chance to your brain and sense of challenge first! At the end, you will definitely feel a better and more serious programmer! If you really do not have any ideas on how to do something, try to read the comments next to each function and/or class (or even the code itself) that you are interested in. They are there for a reason!

Any suggestions to improve the code, or the design of an algorithm or data structure, or corrections are of course welcome. Feel free to open an issue.

Content

In this repository, you will find data structures, such as binary-search trees, and algorithms that often work on (those) data structures. You will also find some algorithms related to some particular design paradigm, for example algorithms related to the greedy or dynamic programming design paradigms.

Notes, warnings and "philosophy"

  • This is a work in progress, don't expect to find here all the data structures and algorithms you're searching. Consider to contribute to the quality and size of the project.

  • Again, mistakes are possible, even if decent tests are starting to being done. You can find them under the folder tests. So, as the license says, this project is provided "as is", etc.

  • No optimisation has been done to any algorithm or data structure. The purpose of the implementations is just for exposition of the concepts!

  • My intent is to continue to contribute to this repository in my free time, and new data structures and algorithms will therefore be added.

References

For each module I always try not to forget to specify the specific references that I used to implement the particular concept exposed in that module.

Apart from those, the following are the references which I always keep an eye on:

Resources

There many useful resources around the web to help you (and me) understand how certain algorithms or data structures work.

One curated list that I found useful which points to a bunch of other resources is the following:

Other resources that may be useful:

Comments
  • Fixed issue 36

    Fixed issue 36

    Fixed by checking input keys as follows:

    1. Raise TypeError if the key is not an instance of str
    2. Raise a ValueError if the key is empty
    3. Raise a TypeError if value is none
    opened by nbro 3
  • Issue fixed #42

    Issue fixed #42

    • Changed name of run.sh to automate.sh
    • Added tests for Queue
    • Changed a few other things around
    • Removed queue for BFS, because it’s quite useless
    • Removed (temporarily) MinPrioriotyQueue
    opened by nbro 2
  • Inconsistencies between the acceptable values in the key-value pair of a HeapNode when adding a HeapNode to a Heap

    Inconsistencies between the acceptable values in the key-value pair of a HeapNode when adding a HeapNode to a Heap

    I've just noticed that method search_by_value in the class Heap raises a ValueError if the input val is None.

    The problem is that theoretically it's possible to add a HeapNode to the heap (either max, min or min-max) with a value None using the add method defined in the Heap class. In that same class, if the input is already a HeapNode, no further checks are performed.

    Two possible solutions:

    1. Allow HeapNode objects with None values to be added to the Heap.
    2. Make sure that HeapNode objects with None values are not added to the heap by modifying the add method.

    Note: the tests have not caught this bug!

    bug 
    opened by nbro 2
  • Searching algorithms in AI

    Searching algorithms in AI

    I had already implemented BFS and DFS, even though currently they were removed temporarily from this project, since the graph data structure was also removed (because I'd to fix a few things with it), but I would like to add also other algorithms like:

    • Uniform-cost search (also called cheapest-first search)

      • This is a variant of the famous Dijkstra's algorithm, where instead of starting with a queue full of nodes, it starts only with one item, and inserts new items as they are discovered. This can avoid some "decrease-key" operations.

      • Dijkstra's algorithm finds the shortest path between a source node and all nodes in a graph, whereas UCS only finds the shortest path between a source and a destination node.

    • Depth-limited search

    • Bidirectional search

    • Iterative-deepening (depth-first) search

    • Best-first search

      These algorithms are usually used in path finding in combinatorial search. There's also a particular version of best-first search, i.e. a greedy version, where paths that are predicted to be closer are chosen first.

    • Beam search

    • A* (not a greedy version of a best-first search)

      • A (A* without admissible heuristics)
    • IDA* (or iterative-deepening A*)

    • Alpha-Beta pruning

    Local search

    Interesting articles

    Possibly useful resources

    • Chapter 3.5 of Russell and Norvig.
    • Slides of prof. Gambardella
    opened by nbro 2
  • Not all methods of the LinearProbingHashTable class check if the input key is Hashable

    Not all methods of the LinearProbingHashTable class check if the input key is Hashable

    The following methods do not check if the key is an instance of an Hashable

    • [x] get
    • [x] put

    whereas the following do

    • delete

    Note: update tests to reflect changes.

    opened by nbro 1
  • Make

    Make "invariant" methods which contain assertions external methods to the related class

    For example, in the class LinearProbingHashTable, I have defined a method called __invariants, whose purpose is to check that the preconditions, postconditions and invariants of the data structure or methods of the same are maintained. This method could be defined as an external function, like I'm already doing for heaps and binary search trees.

    Another example where there's this problem is in the TST class. I may also want to add a similar function to DisjointSetsForest.

    opened by nbro 1
  • Assertion error when checking if a MinMaxHeap is a MinMaxHeap inside the deletion operation

    Assertion error when checking if a MinMaxHeap is a MinMaxHeap inside the deletion operation

    When I was running all tests locally, using the script ./run_tests.sh, at a certain point, an assertion (i.e. assert is_min_max_heap(self)) in the deletion operation was not satisfied. This only occurred locally and when I run all tests, apparently.

    In general, there was some strange behavior going on.

    Verify that the algorithm for deleting an element from a MinMaxHeap (and also MaxHeap and MinHeap) really work, but thinking about all possible cases!!!

    bug 
    opened by nbro 1
  • Query the size of a data structure is being done both providing a method and a property

    Query the size of a data structure is being done both providing a method and a property

    In some data structures, size is a property (e.g. DisjointSetsForest), and in others size is a method (e.g. BinaryHeap). Need to fix these inconsistencies.

    opened by nbro 1
  • Not all methods of MinMaxHeap which accept indices assert that indices are in the bounds

    Not all methods of MinMaxHeap which accept indices assert that indices are in the bounds

    For consistency, I should assert in all methods that accept "indices" that they are valid, i.e. by using something of the form assert self.is_good_index(my_index). Examples of functions that do not do that: _index_of_max, _index_of_min, etc.

    Mare sure that this assertion is required in certain methods: it may happen that it's "ok" that in a call or recursive sub-call to a function the indices are no more valid!!!

    Check also the cases for BinaryHeap, MinHeap and MaxHeap.

    opened by nbro 1
  • Inconsistencies in the coding style for the heap data structures regarding private methods

    Inconsistencies in the coding style for the heap data structures regarding private methods

    For example, push_down should be a private method, but its name does not start with _.

    Be careful: decide well which methods are part of the public API of these heap classes. To do that, you may need to think why would you use a heap.

    opened by nbro 1
  • Should the implementation details of DSForests be hidden from the clients?

    Should the implementation details of DSForests be hidden from the clients?

    Currently, it seems that the implementation of DSForests assumes that the user knows about DSNode and thus can access its public fields. Is this a good thing in this case? My first intuition is that the user doesn't care about these implementations details and therefore they should be hidden. Note: if that's the case, we may need also to change the interface of certain methods, e.g. find, which instead of returning DSNode would return the original value stored in the corresponding representative.

    For example, Kruskal's MST algorithm uses DSForests, but doesn't really care about implementation details, it only cares about the main functionalities and advantages that DSForests uses:

    1. Find if two elements belong to the same set in amortized constant time
    2. The nature of the DS, i.e. that you have a forest of disjoint sets and you can union them.
    question 
    opened by nbro 1
  • Reorganize the `ds` subpackage so that e.g. trees are placed in a sub-subpackage

    Reorganize the `ds` subpackage so that e.g. trees are placed in a sub-subpackage

    We have e.g. multiple heaps, multiple trees or multiple classes/modules related to hash tables, so it may be a good idea to place them inside a subpackage

    data-structures 
    opened by nbro 0
  • Fix the issue that we see an error related to poetry when we type just `make`

    Fix the issue that we see an error related to poetry when we type just `make`

    If I type only make, I get

    Poetry does not seem to be installed, but it's required. Please, install it. See https://python-poetry.org/
    make: *** [poetry_check] Error 1
    

    However, I think it would be better to just show the help message.

    bug 
    opened by nbro 0
Owner
null
Minimal examples of data structures and algorithms in Python

Pythonic Data Structures and Algorithms Minimal and clean example implementations of data structures and algorithms in Python 3. Contributing Thanks f

Keon 22k Jan 9, 2023
: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 1, 2023
Cormen-Lib - An academic tool for data structures and algorithms courses

The Cormen-lib module is an insular data structures and algorithms library based on the Thomas H. Cormen's Introduction to Algorithms Third Edition. This library was made specifically for administering and grading assignments related to data structure and algorithms in computer science.

Cormen Lib 12 Aug 18, 2022
zoofs is a Python library for performing feature selection using an variety of nature inspired wrapper algorithms. The algorithms range from swarm-intelligence to physics based to Evolutionary. It's easy to use ,flexible and powerful tool to reduce your feature size.

zoofs is a Python library for performing feature selection using a variety of nature-inspired wrapper algorithms. The algorithms range from swarm-intelligence to physics-based to Evolutionary. It's easy to use , flexible and powerful tool to reduce your feature size.

Jaswinder Singh 168 Dec 30, 2022
Genetic algorithms are heuristic search algorithms inspired by the process that supports the evolution of life.

Genetic algorithms are heuristic search algorithms inspired by the process that supports the evolution of life. The algorithm is designed to replicate the natural selection process to carry generation, i.e. survival of the fittest of beings.

Mahdi Hassanzadeh 4 Dec 24, 2022
Code for generating alloy / disordered structures through the special quasirandom structure (SQS) algorithm

Code for generating alloy / disordered structures through the special quasirandom structure (SQS) algorithm

Bruno Focassio 1 Nov 10, 2021
Repository for data structure and algorithms in Python for coding interviews

Python Data Structures and Algorithms This repository contains questions requiring implementation of data structures and algorithms concepts. It is us

Prabhu Pant 1.9k Jan 1, 2023
Planning Algorithms in AI and Robotics. MSc course at Skoltech Data Science program

Planning Algorithms in AI and Robotics course T2 2021-22 The Planning Algorithms in AI and Robotics course at Skoltech, MS in Data Science, during T2,

Mobile Robotics Lab. at Skoltech 6 Sep 21, 2022
Python Client for Algorithmia Algorithms and Data API

Algorithmia Common Library (python) Python client library for accessing the Algorithmia API For API documentation, see the PythonDocs Algorithm Develo

Algorithmia 138 Oct 26, 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 4, 2022
My dynamic programming algorithms for exercise and fun

My Dynamic Programming Algorithms giraycoskun [email protected] It is a repo for various dynamic programming algorithms for exercise.

Giray Coskun 1 Nov 13, 2021
CLI Eight Puzzle mini-game featuring BFS, DFS, Greedy and A* searches as solver algorithms.

?? Eight Puzzle CLI Jogo do quebra-cabeças de 8 peças em linha de comando desenvolvido para a disciplina de Inteligência Artificial. Escrito em python

Lucas Nakahara 1 Jun 30, 2021
Algorithms and utilities for SAR sensors

WARNING: THIS CODE IS NOT READY FOR USE Sarsen Algorithms and utilities for SAR sensors Objectives Be faster and simpler than ESA SNAP and cloud nativ

B-Open 201 Dec 27, 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
Classic algorithms including Fizz Buzz, Bubble Sort, the Fibonacci Sequence, a Sudoku solver, and more.

Algorithms Classic algorithms including Fizz Buzz, Bubble Sort, the Fibonacci Sequence, a Sudoku solver, and more. Algorithm Complexity Time and Space

null 1 Jan 14, 2022
Sorting-Algorithms - All information about sorting algorithm you need and you can visualize the code tracer

Sorting-Algorithms - All information about sorting algorithm you need and you can visualize the code tracer

Ahmed Hossam 15 Oct 16, 2022
BCI datasets and algorithms

Brainda Welcome! First and foremost, Welcome! Thank you for visiting the Brainda repository which was initially released at this repo and reorganized

null 52 Jan 4, 2023
All Algorithms implemented in Python

The Algorithms - Python All algorithms implemented in Python (for education) These implementations are for learning purposes only. Therefore they may

The Algorithms 150.6k Jan 3, 2023
Algorithms implemented in Python

Python Algorithms Library Laurent Luce Description The purpose of this library is to help you with common algorithms like: A* path finding. String Mat

Laurent Luce 264 Dec 6, 2022