Skip to content

Conversation

@anirudh-kac
Copy link

Fixes #273

Brief description of what is fixed or changed

I implemented the quick sort algorithm . Added required _partition function and quick_sort function in pydatastructs.linear_data_structures.algorithms
I checked all export statements and init files to make sure it's working

Other comments

This is the non parallel version.
I'm also working on the parallel version , but I was facing some issues with that.
Since some code from this will be reused and this is working fine , I'm making a PR for this version first

@codecov
Copy link

codecov bot commented May 5, 2020

Codecov Report

Merging #274 into master will decrease coverage by 0.192%.
The diff coverage is 85.294%.

@@              Coverage Diff              @@
##            master      #274       +/-   ##
=============================================
- Coverage   98.810%   98.617%   -0.193%     
=============================================
  Files           23        23               
  Lines         2353      2387       +34     
=============================================
+ Hits          2325      2354       +29     
- Misses          28        33        +5     
Impacted Files Coverage Δ
pydatastructs/linear_data_structures/__init__.py 100.000% <ø> (ø)
pydatastructs/linear_data_structures/algorithms.py 96.527% <85.294%> (-3.473%) ⬇️
pydatastructs/trees/heaps.py 97.927% <0.000%> (ø)
pydatastructs/trees/m_ary_trees.py 91.176% <0.000%> (ø)
pydatastructs/trees/binary_trees.py 97.364% <0.000%> (ø)
pydatastructs/trees/space_partitioning_trees.py 97.656% <0.000%> (ø)
...datastructs/linear_data_structures/linked_lists.py 99.596% <0.000%> (ø)

Impacted file tree graph

Comment on lines 432 to 433
quick_sort(array,start=start,end=s)
quick_sort(array,start=s+1,end=end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is recursive. Please convert it into iterative logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the notion of stacks to do it.

@czgdp1807
Copy link
Member

Are you participating through GSSoC, 2020?

@czgdp1807
Copy link
Member

Since some code from this will be reused

Where can this code be used other than in quick sort algorithm? Serial version isn't needed, only parallel version is to be added. Do not close this PR, just update this with the parallel version of quick sort and remove the sequential version.

@anirudh-kac
Copy link
Author

@czgdp1807 , I tried using Stack from miscellaneous_data_structures in my implementation of iterative quick sort , however I'm getting import error when importing Stack
cannot import name 'DynamicOneDimensionalArray' from 'pydatastructs.linear_data_structures'

@anirudh-kac
Copy link
Author

Yes I'm participating through GSSOC as of now

@czgdp1807
Copy link
Member

I tried using Stack from miscellaneous_data_structures

You can use python list as a stack. No problems.

==========
.. [1] https://en.wikipedia.org/wiki/Quicksort
.. [2] https://www.geeksforgeeks.org/quick-sort
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. [2] https://www.geeksforgeeks.org/quick-sort

Please use, wikipedia/university lectures/research papers as references.

@anirudh-kac
Copy link
Author

Sorry for the delay, couldn't work for some time.
I removed the recursive logic but how can this be made parallel now? We have a single stack that will be accessed ,won't that be an issue? Can you guide me a little

@czgdp1807
Copy link
Member

Well, a stack is a list. So you can access any element from inside it. Launch threads for some of the top elements. It's just like a tree, all the leafs are processed parallely in the bottom layer, then the second last, and so on till we reach the top.

@czgdp1807
Copy link
Member

czgdp1807 commented May 15, 2020

I think you forgot to add tests for your patch. See, tests folder under linear_data_structures.

@czgdp1807
Copy link
Member

@anirudh-kac Are you working on it? Please do not close the PR.

@anirudh-kac
Copy link
Author

@czgdp1807 sorry for replying late. I was having some trouble with the parallel implementation and got busy with some college stuff later tbh.
Any resource that might be helpful for implementing the parallel version?

@czgdp1807
Copy link
Member

See, https://en.wikipedia.org/wiki/Quicksort#Parallelization and a lot PDFs on the web.

@czgdp1807 czgdp1807 mentioned this pull request May 26, 2020
@robotjellyzone
Copy link

Hi @anirudh-kac are you still working on it ! feel free to ask your queries here

@anirudh-kac
Copy link
Author

anirudh-kac commented May 30, 2020

@robotjellyzone I had some trouble implementing the iterative parallel version of quick sort. I went through some resources over the internet but couldn't really figure out how to implement it. I'm still trying but I won't mind if anyone else takes over the issue as I've taken a lot of time

@robotjellyzone
Copy link

robotjellyzone commented May 30, 2020

@robotjellyzone I had some trouble implementing the iterative parallel version of quick sort. I went through some resources over the internet but couldn't really figure out how to implement it. I'm still trying but I won't mind if anyone else takes over the issue as I've taken a lot of time

@anirudh-kac have you checked this https://en.wikipedia.org/wiki/Quicksort#Parallelization already? if so then that's totally fine i would add upforgrabs for other contributors !

@robotjellyzone robotjellyzone added upforgrabs Please take over PRs that can be continued by anyone. labels May 30, 2020
@czgdp1807 czgdp1807 removed the gssoc20 label Jul 19, 2020
@Arvind-raj06
Copy link
Member

Is this PR still in progress or should I take it over!

@sidhu1012
Copy link

Is this PR still in progress or should I take it over!

You can take it over.

@czgdp1807
Copy link
Member

Closing in favor of #314

@czgdp1807 czgdp1807 closed this Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quick Sort

5 participants