3 ms·
A difference is in the number of times you use some operation. For example, you expect to do a lot of pushes in vector so you can say about amortized time beca
by vient 4y ago
A difference is in the number of times you use some operation.
For example, you expect to do a lot of pushes in vector so you can say about amortized time because it will hold on average and you can calculate running time from it and expected number of pushes somewhat precisely (with unknown constant multiplier which is independent of input data, on theoretical hardware at least).
On the other hand, an individual array is usually sorted only once. Here it is more appropriate to speak about average or expected complexity of quicksort which is O(NlogN) but in you particular run it may become either better or worse and this will noticeably affect running time, by a factor dependent of N value.
You can say about amortized time of quicksort though if you expect to sort different arrays a lot of times and you know their distribution, or at least the fact that they are sufficiently random shuffled or maybe sufficiently sorted beforehand.
- ctrlmeta 4y agoAh! Finally it clicked! Thanks for the nice example in your comment.