The Student Room Group

D1 (Edexcel): Quicksort vs Bubble Sort

How would one compare the algorithms in the exam? Which algorithm is "better" or more efficient?
Quicksort is on average O(nlogn), Worst case O(n^2)

Bubblesort is on average and worst case O(n^2)

So quicksort is better.
Original post by ayyy2
Quicksort is on average O(nlogn), Worst case O(n^2)

Bubblesort is on average and worst case O(n^2)

So quicksort is better.


Thanks!!!
Could I write this in the exam, if asked to compare algorithms?
Also do you know what the advantages/ disadvantages are of each algorithm?
Original post by bluenotewitt
Thanks!!!
Could I write this in the exam, if asked to compare algorithms?
Also do you know what the advantages/ disadvantages are of each algorithm?


If asked to compare their performance, then yes, you would say that quicksort is better as it is almost always O(n log n), which is better than bubble-sort's O(n^2). The only exception is if you happen to get really bad pivots, but even then quicksort is only O(n^2), i.e. no worse than bubble-sort. Pretty much the only advantage of bubble-sort over quicksort is that it's easier to implement if you're a novice programmer. But therefore in all real-world applications, quicksort is used, because performance is by far the most important thing, and bubble-sort is pretty much confined to academic teaching, because there's just no good reason for any competent programmer writing an actual program to ever consider using it.
Original post by bluenotewitt
Thanks!!!
Could I write this in the exam, if asked to compare algorithms?
Also do you know what the advantages/ disadvantages are of each algorithm?


Quicksort requires O(log n) of memory space whereas bubble sort requires none (O(1)).

This is stuff I learnt in my algorithms and data structures class. Not sure if you cover it in A-Level Maths
Original post by Prasiortle
If asked to compare their performance, then yes, you would say that quicksort is better as it is almost always O(n log n), which is better than bubble-sort's O(n^2). The only exception is if you happen to get really bad pivots, but even then quicksort is only O(n^2), i.e. no worse than bubble-sort. Pretty much the only advantage of bubble-sort over quicksort is that it's easier to implement if you're a novice programmer. But therefore in all real-world applications, quicksort is used, because performance is by far the most important thing, and bubble-sort is pretty much confined to academic teaching, because there's just no good reason for any competent programmer writing an actual program to ever consider using it.


Original post by ayyy2
Quicksort requires O(log n) of memory space whereas bubble sort requires none (O(1)).

This is stuff I learnt in my algorithms and data structures class. Not sure if you cover it in A-Level Maths


Thanks, to both of you! I think I will be able to write a decent response to any such question now! (just hope the big O notation is allowed...)

Quick Reply

Latest