Python icon indicating copy to clipboard operation
Python copied to clipboard

New algorithm suggestion : Dutch National Flag algorithm

Open yatharthmathur opened this issue 5 years ago • 6 comments

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.

yatharthmathur avatar Aug 19 '21 07:08 yatharthmathur

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

KiranHipparagi avatar Aug 19 '21 09:08 KiranHipparagi

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.

yatharthmathur avatar Aug 19 '21 11:08 yatharthmathur

@yatharthmathur thanks for responding!

can I pick this issue as my first contribution?

KiranHipparagi avatar Aug 19 '21 14:08 KiranHipparagi

@yatharthmathur is this issue still open ?

VasanthKumar14 avatar Aug 21 '21 05:08 VasanthKumar14

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

yatharthmathur avatar Aug 21 '21 07:08 yatharthmathur

https://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/

ganeshdatta23 avatar Sep 09 '21 10:09 ganeshdatta23