Skip to main content
fixed LaTeXization
Source Link
Stephen Rauch
  • 4.2k
  • 12
  • 23
  • 36

To add to @Deduplicator suggestions, I would recommend you to improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last element of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case \$O(n^2)\$.

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically \$O(n\log n)\$). Be aware that in order to get to this you need an algorithm that finds a median in complexity of \$O(n)\$.

There are quite a lot of information sources on the subject.

You should take a look here.

I hope that's helps!

To add to @Deduplicator suggestions, I would recommend you to improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last element of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case \$O(n^2)\$.

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically \$O(n\log n)\$). Be aware that in order to get to this you need an algorithm that finds a median in complexity of \$O(n)\$.

There are quite a lot of information sources on the subject.

You should take a look here.

I hope that's helps!

To add to @Deduplicator suggestions, I would recommend you improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last element of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case \$O(n^2)\$.

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically \$O(n\log n)\$). Be aware that in order to get to this you need an algorithm that finds a median in complexity of \$O(n)\$.

There are quite a lot of information sources on the subject.

You should take a look here.

To add to @Deduplicator suggestions, I would recommend you to improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last element of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case \$O(n^2)\$.

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically \$O(nlogn\$)\$O(n\log n)\$). Be aware that in order to get to this you need an algorithm that finds a median in complexity of \$O(n)\$.

There are quite a lot of information sources on the subject.

You should take a look here.

I hope that's helps!

To add to @Deduplicator suggestions, I would recommend you to improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last element of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case \$O(n^2)\$.

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically \$O(nlogn\$)). Be aware that in order to get to this you need an algorithm that finds a median in complexity of \$O(n)\$.

There are quite a lot of information sources on the subject.

You should take a look here.

I hope that's helps!

To add to @Deduplicator suggestions, I would recommend you to improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last element of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case \$O(n^2)\$.

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically \$O(n\log n)\$). Be aware that in order to get to this you need an algorithm that finds a median in complexity of \$O(n)\$.

There are quite a lot of information sources on the subject.

You should take a look here.

I hope that's helps!

format complexity equations with MathJax/latex; use markdown style link format
Source Link

To add to @Deduplicator suggestions, I would recommend you to improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last elemetelement of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case O(n^2)\$O(n^2)\$.

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically O(nlogn\$O(nlogn\$)). Be aware that in order to get to this you need an algorithm that finds a median in complexity of O(n)\$O(n)\$.

There are quite a lot of information sources on the subject. You

You should take a look here - https://en.wikipedia.org/wiki/Selection_algorithm#Median_selection_as_pivot_strategyhere.

HopeI hope that's helps!

To add to @Deduplicator suggestions, I would recommend you to improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last elemet of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case O(n^2).

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically O(nlogn)). Be aware that to get to this you need an algorithm that finds a median in complexity of O(n).

There are quite of information sources on the subject. You should take a look here - https://en.wikipedia.org/wiki/Selection_algorithm#Median_selection_as_pivot_strategy.

Hope that's helps!

To add to @Deduplicator suggestions, I would recommend you to improve your runtime. I mean there is nothing wrong in the implementation itself but currently you are using the last element of the array as pivot - this element can be the maximum or the minimum on each iteration making the complexity of this implementation in the worst case \$O(n^2)\$.

However if you take the median as pivot in quicksort you are bound to do the job with the least operations as possible (at least asymptotically \$O(nlogn\$)). Be aware that in order to get to this you need an algorithm that finds a median in complexity of \$O(n)\$.

There are quite a lot of information sources on the subject.

You should take a look here.

I hope that's helps!

Source Link
Loading