It's UWAweek 49

help3001

This forum is provided to promote discussion amongst students enrolled in CITS3001 Advanced Algorithms.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying the 4 articles in this topic
Showing 4 of 202 articles.
Currently 1 other person reading this forum.


 UWA week 32 (2nd semester, week 3) ↓
SVG not supported

Login to reply

👍?
helpful
3:06pm Wed 7th Aug, ANONYMOUS

Hi! I just had a discussion with a friend over Quicksort algorithm and we were confused as to which sort type quicksort is. In the lecture Gozz mentioned it was Distribution sort however when searching online it mentions it is comparison sort. The part I'm confused about is in the slides it is stated that distribution sort "Distribute the elements o the list into multiple intermediate data structures (blocks) such that there are no inversion between blocks", which is what Quicksort does but doesn't quicksort first use comparisons to get the 2 "blocks" (i.e. less than pivot or more than pivot). Could a sorting algorithm be both comparison-based and distribution-based? Could someone clarify which one it is and why it is that type? Thank you very much for reading and helping!


SVG not supported

Login to reply

👍?
helpful
4:20pm Wed 7th Aug, Andrew G.

ANONYMOUS wrote:
> Hi! I just had a discussion with a friend over Quicksort algorithm and we were confused as to which sort type quicksort is. In the lecture Gozz mentioned it was Distribution sort however when searching online it mentions it is comparison sort. The part I'm confused about is in the slides it is stated that distribution sort "Distribute the elements o the list into multiple intermediate data structures (blocks) such that there are no inversion between blocks", which is what Quicksort does but doesn't quicksort first use comparisons to get the 2 "blocks" (i.e. less than pivot or more than pivot). Could a sorting algorithm be both comparison-based and distribution-based? > > Could someone clarify which one it is and why it is that type? Thank you very much for reading and helping!
These are not exclusive categories. Indeed, as you say, quicksort is both. Comparison-based sorting algorithms are restricted to only be able to compare elements, and have no other way to get information about their ordering. Quicksort only requires comparison, so it is a comparison-based sorting algorithm. Distribution sorting algorithms, as you quoted, work by distributing the elements into blocks such that there are no inversions between blocks, and then sorting within each block if necessary. By this definition quicksort can be interpreted as a distribution sort, but it only has two blocks since by comparing each element to the pivot it only gets one bit of information, and can only distinguish between elements <= pivot and > pivot. I am not interested in these categories for the purposes of memorizing a complete taxonomy of all algorithms. They are of interest because understanding the ways in which the logic of different algorithms is similar helps understand the logic itself. We derived quicksort without having any concept of what a distribution sort was, but we are able to generalize the concept and use it to reason about quicksort, bucket sort, counting sort, etc. So long as you are able to understand and work with the concepts and the logic, it is not particularly meaningful whether quicksort is classified as a distribution sort. I would be more interested in your ability to, given some sorting algorithm, formulate an argument for why it should or should not be considered a distribution sort, or otherwise compare the properties and logic of the algorithms. As an exercise in exactly that, here are a couple of fun open-ended questions to have a think about: 1. Do you believe heap sort is a distribution sort? What is your argument to support your position? Can you formulate a counterargument? 2. Could you adapt merge sort to use more information than just comparison? If so, how does your resulting algorithm relate to others we have covered in lectures (what is it similar to, etc.)? Cheers, Gozz


SVG not supported

Login to reply

👍?
helpful
5:00pm Wed 7th Aug, ANONYMOUS

"Andrew Gozzard" <an*r*w*g*z*a*d@u*a*e*u*a*> wrote:
> ANONYMOUS wrote: > > > Hi! I just had a discussion with a friend over Quicksort algorithm and we were confused as to which sort type quicksort is. In the lecture Gozz mentioned it was Distribution sort however when searching online it mentions it is comparison sort. The part I'm confused about is in the slides it is stated that distribution sort "Distribute the elements o the list into multiple intermediate data structures (blocks) such that there are no inversion between blocks", which is what Quicksort does but doesn't quicksort first use comparisons to get the 2 "blocks" (i.e. less than pivot or more than pivot). Could a sorting algorithm be both comparison-based and distribution-based? > > > > Could someone clarify which one it is and why it is that type? Thank you very much for reading and helping! > > These are not exclusive categories. Indeed, as you say, quicksort is both. > > Comparison-based sorting algorithms are restricted to only be able to compare elements, and have no other way to get information about their ordering. Quicksort only requires comparison, so it is a comparison-based sorting algorithm. > > Distribution sorting algorithms, as you quoted, work by distributing the elements into blocks such that there are no inversions between blocks, and then sorting within each block if necessary. By this definition quicksort can be interpreted as a distribution sort, but it only has two blocks since by comparing each element to the pivot it only gets one bit of information, and can only distinguish between elements <= pivot and > pivot. > > I am not interested in these categories for the purposes of memorizing a complete taxonomy of all algorithms. They are of interest because understanding the ways in which the logic of different algorithms is similar helps understand the logic itself. We derived quicksort without having any concept of what a distribution sort was, but we are able to generalize the concept and use it to reason about quicksort, bucket sort, counting sort, etc. So long as you are able to understand and work with the concepts and the logic, it is not particularly meaningful whether quicksort is classified as a distribution sort. I would be more interested in your ability to, given some sorting algorithm, formulate an argument for why it should or should not be considered a distribution sort, or otherwise compare the properties and logic of the algorithms. > > As an exercise in exactly that, here are a couple of fun open-ended questions to have a think about: > 1. Do you believe heap sort is a distribution sort? What is your argument to support your position? Can you formulate a counterargument? > 2. Could you adapt merge sort to use more information than just comparison? If so, how does your resulting algorithm relate to others we have covered in lectures (what is it similar to, etc.)? > > Cheers, > Gozz
Hi Gozz, thank your clarification. Below I'd like to try my hand at the open-ended questions you have provided. 1. Do you believe heap sort is a distribution sort? What is your argument to support your position? Can you formulate a counterargument? - From a standpoint of heap sort being distribution sort, it could be stated that splitting the list into heaps can be considered as blocks. However I believe that heap sort is mainly a comparison sort as it only provides 1 bit of information (i.e. parent is larger/smaller depending on if the heap is max/min heap) and comparison is needed for its main function (heapify) to maintain the heap property. 2. Could you adapt merge sort to use more information than just comparison? If so, how does your resulting algorithm relate to others we have covered in lectures (what is it similar to, etc.)? - One adaption I could think of is instead of dividing the list until it can be trivially sorted, we divide until a certain list size is achieved (e.g. List size of 10) and use counting sort which can provide the information of cumulative count. This also brings the advantage of reduced overhead as we do less recursive calls. Please let me know if I have any error in my logic/understanding. Thank you for your time and advice


SVG not supported

Login to reply

👍?
helpful
2:37pm Thu 8th Aug, Andrew G.

ANONYMOUS wrote:
> Hi Gozz, thank your clarification. Below I'd like to try my hand at the open-ended questions you have provided. > 1. Do you believe heap sort is a distribution sort? What is your argument to support your position? Can you formulate a counterargument? > - From a standpoint of heap sort being distribution sort, it could be stated that splitting the list into heaps can be considered as blocks.
Heap sort only uses a single heap, though. Heaps are typically implemented as binary trees with the heap property, so maybe you are talking about the subtrees of the heap? Recall that one of the defining parts of a distribution sort is that there should be no inversions between "blocks". Do the subtrees of the heap have this property? Does the heap property imply anything about inversions?
> However I believe that heap sort is mainly a comparison sort as it only provides 1 bit of information (i.e. parent is larger/smaller depending on if the heap is max/min heap) and comparison is needed for its main function (heapify) to maintain the heap property.
As demonstrated by quicksort, being a comparison sort does not mean something cannot be interpreted as a distribution sort. So the fact that heap sort is a comparison sort does not mean it is not a distribution sort.
> 2. Could you adapt merge sort to use more information than just comparison? If so, how does your resulting algorithm relate to others we have covered in lectures (what is it similar to, etc.)? > - One adaption I could think of is instead of dividing the list until it can be trivially sorted, we divide until a certain list size is achieved (e.g. List size of 10) and use counting sort which can provide the information of cumulative count. This also brings the advantage of reduced overhead as we do less recursive calls.
What you have proposed is a hybrid sort which switches from merge sort to counting sort at a particular list size. Compare this concept to introsort, which as described in the lectures switches from quicksort to heap sort at a particular depth if quicksort hasn't already hit a base case. I would argue that merge sort isn't using the extra information here, you are just switching out to one that does, but trying to construct a hybrid sort is a reasonable approach. To be a variant of merge sort, I would argue it still has to split the list without regard for the elements, and the reordering is done as part of merging. Given that merging is already linear time, even using extra information couldn't get us any wins there... At least for two lists. Perhaps there is a way to efficiently merge more than two lists by using more information than just comparison?
> Please let me know if I have any error in my logic/understanding. Thank you for your time and advice
I want to be clear that I mean it when I say these are open-ended. There is not a "correct" answer I am looking for. They are questions to reason about and see if you can come up with interesting ideas. It is possible (and perhaps even likely) that the answer to both is "no, that doesn't make sense", but the point is to have an explanation for why it doesn't make sense, or why it does (if it does). I hope you are enjoying exploring a more open-ended problem. Cheers, Gozz

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy