Skip to content

New algorithm suggestion : Dutch National Flag algorithm #4636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yatharthmathur opened this issue Aug 19, 2021 · 6 comments
Closed

New algorithm suggestion : Dutch National Flag algorithm #4636

yatharthmathur opened this issue Aug 19, 2021 · 6 comments

Comments

@yatharthmathur
Copy link
Contributor

Since it is a very popular algorithm, I feel it should be a part of this collection of algorithms and it'll surely be of great help to a lot of programmers.

@KiranHipparagi
Copy link
Contributor

Already we have function in python which sorts the array data. it is list.sort()

@yatharthmathur
Copy link
Contributor Author

yatharthmathur commented Aug 19, 2021

list.sort() is used to sort list with arbitrary range of elements [-inf<a[i]<inf]. Dutch National Flag algorithm is the most optimal sort for 3 unique values (eg. 0,1,2) in an Array. It's a popular algorithm, check https://en.wikipedia.org/wiki/Dutch_national_flag_problem. And isn't the entire point of the repository is to catalogue a list of implementations of popular algorithms in different languages. There's an entire section dedicated to sorting as well.
Dutch National Flag algorithm can sort an array of n size with [0<=a[i]<=2] at guaranteed O(n) complexity in a single pass. It's a common interview problem as well.

@KiranHipparagi
Copy link
Contributor

@yatharthmathur thanks for responding!

can I pick this issue as my first contribution?

yatharthmathur added a commit to yatharthmathur/Python that referenced this issue Aug 19, 2021
yatharthmathur added a commit to yatharthmathur/Python that referenced this issue Aug 19, 2021
@VasanthKumar14
Copy link

@yatharthmathur is this issue still open ?

@yatharthmathur
Copy link
Contributor Author

There are already 2 pull requests trying to resolve this issue. I suggest you take up a new one or create another.

cclauss added a commit that referenced this issue Aug 31, 2021
* Added Dutch national flag sort Algorithm

* Changed file name to dnf_sort.py

* Added descriptive name and type hint 

Added descriptive name and type hint  for parameter with doctest for the function dnf_sort.

* Added test cases

* Added doctest cases

* Update sorts/dnf_sort.py

* Added doctest for dutch_national_flag_sort sorts/dnf_sort.py

* Update sorts/dnf_sort.py

* Added doctest for the function
dutch_national_flag_sort

* update file as per black code formatter

* Update dnf_sort.py

* Update and rename dnf_sort.py to dutch_national_flag_sort.py

Co-authored-by: Christian Clauss <[email protected]>
@ganeshdatta23
Copy link

@cclauss cclauss closed this as completed Sep 9, 2021
shermanhui pushed a commit to shermanhui/Python that referenced this issue Oct 22, 2021
…#4639)

* Added Dutch national flag sort Algorithm

* Changed file name to dnf_sort.py

* Added descriptive name and type hint 

Added descriptive name and type hint  for parameter with doctest for the function dnf_sort.

* Added test cases

* Added doctest cases

* Update sorts/dnf_sort.py

* Added doctest for dutch_national_flag_sort sorts/dnf_sort.py

* Update sorts/dnf_sort.py

* Added doctest for the function
dutch_national_flag_sort

* update file as per black code formatter

* Update dnf_sort.py

* Update and rename dnf_sort.py to dutch_national_flag_sort.py

Co-authored-by: Christian Clauss <[email protected]>
cclauss added a commit that referenced this issue Jul 30, 2023
* Added a more pythonic implementation of LRU_Cache.[#4628]

* Added test cases and doctest

* Fixed doc tests

* Added more tests in doctests and fixed return types fixes [#4628]

* better doctests

* added doctests to main()

* Added dutch_national_flag.py in sorts. fixing [#4636]

* Delete dutch_national_flag.py

incorrect commit

* Update lru_cache_pythonic.py

* Remove pontification

---------

Co-authored-by: Christian Clauss <[email protected]>
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this issue Sep 15, 2024
* Added a more pythonic implementation of LRU_Cache.[TheAlgorithms#4628]

* Added test cases and doctest

* Fixed doc tests

* Added more tests in doctests and fixed return types fixes [TheAlgorithms#4628]

* better doctests

* added doctests to main()

* Added dutch_national_flag.py in sorts. fixing [TheAlgorithms#4636]

* Delete dutch_national_flag.py

incorrect commit

* Update lru_cache_pythonic.py

* Remove pontification

---------

Co-authored-by: Christian Clauss <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants