Python Forum

Full Version: Python - sorting algorithms
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I had a test today and I lost my points on one question.

The book we are using in the class says:

O - runtime complexity

Ω - lower bound

exchange sort = O(n²), Ω(n²)

selection sort = O(n²), Ω(n²)

insertion sort = O(n²), Ω(n)

bubble sort = O(n²), Ω(n)

quick sort(Hoare) = O(n²)(in most cases - O(n log n)), Ω(n)

merge sort = O(n log n)

bucket sort = O(n)

(for some algorithms there are no Ω written in the book)


Question is: Is exchange sort algorithm the easiest of all algorithms for sorting(written in book)?

I answered NO, because bucket sort has complexity O(n) and exchange sort has O(n²).


After test I was looking through the book and I found this statement without further explanation:
"Exchange sort is the easiest of all algorithms for sorting"


My final question is: Have I answered it wrong or is this some mistake in the book?

P.S.
Firstly, sorry for my bad English. I tried my best to translate terms used in the book.
Secondly, it wouldn't be the first mistake in that book. I found some mistakes earlier.


Thanks in advance,
hrca
I don't know enough about algorithms to give a proper answer, but I'm a little concerned about the word "easy". "Easy" doesn't make sense in the context big O notation or sorting speed. I think the question might be asking which algorithm is the easiest to write, and exchange is incredibly easy to write.
Quote:Question is: Is exchange sort algorithm the easiest of all algorithms for sorting(written in book)?
I'm pretty sure this would be bubble sort as it is a simple swap.

However, If the book states what you show verbatim, I'd show it to the prof and If a reasonable person, will change your grade.
(Nov-06-2018, 06:50 PM)nilamo Wrote: [ -> ]I don't know enough about algorithms to give a proper answer, but I'm a little concerned about the word "easy". "Easy" doesn't make sense in the context big O notation or sorting speed. I think the question might be asking which algorithm is the easiest to write, and exchange is incredibly easy to write.

The whole test was with the goal to test the knowledge in complexity of algorithms, so I don't think that "easy" means the complexity to write algorithm. Whole procedure of calculating complexity is based on the number of operations that computer must do.

(Nov-06-2018, 06:53 PM)Larz60+ Wrote: [ -> ]
Quote:Question is: Is exchange sort algorithm the easiest of all algorithms for sorting(written in book)?
I'm pretty sure this would be bubble sort as it is a simple swap. However, If the book states what you show verbatim, I'd show it to the prof and If a reasonable person, will change your grade.

I have a class tomorrow and I have to get a proof that my answer is also correct(I agree with nilamo that it is easy to write).

(btw that is why I started this thread because I am sure that here must be some experienced people that agree with my answer)