GithubHelp home page GithubHelp logo

thealgorithms / python Goto Github PK

View Code? Open in Web Editor NEW
179.2K 179.2K 43.6K 14.72 MB

All Algorithms implemented in Python

Home Page: https://the-algorithms.com/

License: MIT License

Python 99.99% Dockerfile 0.01%
algorithm algorithm-competitions algorithms-implemented algos community-driven education hacktoberfest interview learn practice python searches sorting-algorithms sorts

python's Introduction

Gitpod Ready-to-Code Contributions Welcome Discord chat Gitter chat
GitHub Workflow Status pre-commit code style: black

All algorithms implemented in Python - for education

Implementations are for learning purposes only. They may be less efficient than the implementations in the Python standard library. Use them at your discretion.

Getting Started

Read through our Contribution Guidelines before you contribute.

Community Channels

We are on Discord and Gitter! Community channels are a great way for you to ask questions and get help. Please join us!

List of Algorithms

See our directory for easier navigation and a better overview of the project.

python's People

Contributors

alexpantyukhin avatar algobytewise avatar anupkumarpanwar avatar caedenph avatar cclauss avatar christianbender avatar daniel-s-ingram avatar dhruvmanila avatar dylanbuchi avatar dynamitechetan avatar fpringle avatar frmatias avatar harshildarji avatar kush1101 avatar l3str4nge avatar maximsmolskiy avatar mhihasan avatar poyea avatar prateekiiest avatar pre-commit-ci[bot] avatar quant12345 avatar quantumnovice avatar rafaelleru avatar realduyuanchao avatar rohanrbharadwaj avatar ruppysuppy avatar saksham-chawla avatar sanderslin avatar suyashd999 avatar tianyizheng02 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python's Issues

LCA problem

Hey, Can i include code for Lowest Common Ancestor algorithm for Directed Acyclic Graph (algorithm is based upon LCA problem to RMQ(Range Minimum Query) problem reduction (solving RMQ problem via sparse table), which has time complexity per query O(1) and memory complexity of O(N.log N) ?

knapsack.py can be improved

knapsack.py fills up the entire 2D table. We can improve it by using memory functions.Which solve only subproblems which are needed

Sync with Travis-CI

If you want previous merge to work, you need to sync this repository with Travis-CI.
I already had made request from my Travis-CI profile to this organization, you just need to grant it.

Logo Proposal

Greetings @TheAlgorithms ,

I'm a Graphic Designer interested in collaborating
with this project by delivering a free logo proposal
if this is something that interest this project, let me know

Cheers!
-Luigi.

test

I have a queryk

quicksort probabilistic guarantee

Hi,
I think your implementation of quicksort lacks randomizing of the input. If you shuffle it, you are almost guaranteed to not have O(n^2) time scenario.

/sorts/merge_sort_fastest.py is NOT fast at all

Hi @harshildarji & @yesIamHasi ,

Thanks for sharing algorithm source code and I really like them.

Just want to raise an issue on '/sorts/merge_sort_fastest.py' that it is not an merge_sort option as there are dependencies on python built-in functions - remove(), max() & min(), which makes 'merge_sort_fastest' like O(n^2) [ (n*(n+1)) / 2 * 2 as one max()/min() with remove()] instead of O(n log n).

For example, while sorting 50,000 random numbers with below list:
unsorted = random.sample(range(0, 100000), 50000)

The running result will be like:
(venv) $ time python3 merge_sort.py
real 0m0.361s
user 0m0.347s
sys 0m0.011s

(venv) $ time python3 merge_sort_fastest.py
real 0m49.306s
user 0m49.103s
sys 0m0.099s

thanks!
Tom

server.py : Error

See the file here

Traceback (most recent call last):
File "/home/christian/Programmierung/GitHub/Python/server.py", line 29, in
t.bind()
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
TypeError: bind() takes exactly one argument (0 given)

The error above occures by python 2 and python 3.

The taste of selection_sort and merge_sort is not good.

All the sorting algorithms are implemented in Python using C++ thinking which makes the code execution time too high.
The current selection sort algorithm is 65% slower, merge_sort algorithm is 10^4 times slower.
Here's timeit result.
screenshot from 2018-05-19 18-15-11
Here is a better taste of selection sort.
Here is a better taste of merge sort.
Tell me what you think about it?
Should I add it to TheAlgorithms/Python/sorts ?

travis-ci

@h-darji why you removed python version 2.7 from travis.yml file? Many people are still using python ver 2.7.

Bug report for radix sort

Description

if the test case for radix_sort.py is [104, 203, 308, 401], the result would be [401, 203, 104, 308]

It's wrong!

The reason is that if the tmp is always 0 in one loop, it will exit the loop. In other words, If the same digit of all numbers is 0, then the result may be wrong. The similar example like:
Input: [2018, 33017, 24016]
Output: [24016, 33017, 2018]
Wrong again!!

Suggestion

Do not use maxLength as a loop variable because the value of maxLength is related to tmp.

I think that by finding the maximum value of the array and assigning it to max_digit, using another variable digit with an initial value of 1 as the loop variable, each loop digit is multiplied by 10, and exit the loops when the digit greater than max_digit, which can guarantee the correct number of loops.

And the complexity will be O(nk + n) . n is the size of input list and k is the digit length of the number.

Invalid file name

file Graphs/A*.py has invalid file name, leading failure to sync this remote repository.
can anyone fix this file?

Tests

Hey, maybe it would be necessary to add a test for each algorithm. For those who need it do not want to test everything yourself :)

2 Graph folders

There are 2 separate folder of Graph

  1. Graph
  2. Data Structures - > Graph

Merge them and keep the second one

bucket_sort

hello,where is "P26_InsertionSort" for bucket_sort.py?I can't run it.I am a player,you know.Thank you

Typo in BinSearch

Line 113 & 115 in BinSearch have typos in them. It should be mid-1 and mid+1.
https://github.com/TheAlgorithms/Python/blob/master/searches/binary_search.py

if sorted_collection[midpoint] == item:
    midpoint
elif sorted_collection[midpoint] > item:
    binary_search_by_recursion(sorted_collection, item, left, right-1)
else:
    binary_search_by_recursion(sorted_collection, item, left+1, right)

should be

if sorted_collection[midpoint] == item:
    return midpoint
elif sorted_collection[midpoint] > item:
    return binary_search_by_recursion(sorted_collection, item, left, mid-1)
else:
    return binary_search_by_recursion(sorted_collection, item, mid+1, right)

Issue in importing SKLearn package in Jupyter notebook (Python code)

Hello folks,

I have problem in importing some packages. I need to know how and where could I install packages so I can import it in Jupyther Notebook?

e.g: I write this code in jupyther :
from sklearn.family import Model

and i got an error as shown bellow.


ModuleNotFoundError Traceback (most recent call last)
in ()
----> 1 from sklearn.family import Model

ModuleNotFoundError: No module named 'sklearn.family'

I installed the SKlearn package using python command prompt. However, I think there is no link between SKlearn package I have installed and the Jupyter notebook that I am using. How to solve it out?

I appreciate your responses.

Regards,
Mona

Sending Email by extracting xml content

image

I need python code which will watch for directory for XML files. Once the xml is generated, i need to send email to the persons. 'TO' email is dynamic and it would be available with 'BillingCode field in xml file which is generated. Also in mail body i need to use other xml fields.

Please suggest!

Add demo gif to README

Disclaimer: This is a bot

It looks like your repo is trending. The github_trending_videos Instgram account automatically shows the demo gifs of trending repos in Github.

Your README doesn't seem to have any demo gifs. Add one and the next time the parser runs it will pick it up and post it on its Instagram feed. If you don't want to just close this issue we won't bother you again.

Radix Sort broken in Python 3

In Python 3 radix sort is broken.

Traceback (most recent call last):
  File "radix_sort.py", line 30, in <module>
    radixsort(ar);
  File "radix_sort.py", line 14, in radixsort
    buckets[tmp % RADIX].append( i )
TypeError: list indices must be integers or slices, not float

I will fix it asap and submit a pull request.

Incorrect markdown

The markdown in README.md for Time-Compexity Graphs is not used correctly.
Should I send a PR for a fix ?

Redundant parameters in SegmentTree

here st.query(1, 1, N, ...) the first three parameters are unnecessary. We are using class but not taking advantage of it.

The same thing is with other classes as well.

Adopt a more robust testing system

I find that tests are currently very limited in capability. And there are very few tests with each algorithm.

We should have more tests and an efficient testing mechanism.

Contribution

Hello,

My name is Iro Kafetzaki and I'm studying in the third year at the Athens University of Economics and Business in the Department of Management Science and Technology. In terms of a lesson called Software Engineering in Practise and as I'm interested in algorithms that can be used for operational research I would like to ask you if I can contribute to your project in the "searches" folder and contribute tabu search for a Traveling Salesman Problem -TSP written in python.

Thank you in advance.

Add a license for your repository

Hi!

I would request the owner of this repository to add a license. A license is useful to show if whether a user can use your code freely or not. If you do not have a license, a user may avoid to use your code (see here: http://choosealicense.com/no-license/).

I recommend using MIT license (http://choosealicense.com/licenses/mit/) so the user can tinker with the codes themselves. Also, by using this license, the user can't hold you liable if somehow they broke their computers using your example codes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.