merge sort,quick sort rate question

Asked 2 years ago, Updated 2 years ago, 58 views

While studying the algorithm, I compared the speed using the clock function by implementing the quick alignment and the merge alignment as c In general, I knew that quick sorting performed better than merge sorting, but when I compiled the source and compared the time, the merge sorting came out faster.

Set the array size to 10000 or less and arrange a completely random number (0 to 10000) Is it normal for the merge alignment to come out faster than the quick alignment? Or is it because I'm not good at implementing the quick alignment?

The faster the quill sequence was approved when the pivot was woven into a well-defined algorithm (I fixed the pivot to the far left of the array).I don't think it'll matter because it's a completely random order of numbers. I'm thinking hard, but I don't get an answer

It's my first time posting a question, so please tell me if there's anything wrong. I'll fix it. :)

algorithm quick-sort merge-sort c

2022-09-22 18:47

1 Answers

Looking up doesn't seem so surprising.

Efficiency :
Merge sort is more efficient and works faster than quick sort in case of larger array size or datasets.
whereas
Quick sort is more efficient and works faster than merge sort in case of smaller array size or datasets.

In short, if the target array is large, the merge alignment is better, but in fact, an array with 10,000 elements falls on a large array axis. So, the phenomenon you experienced is more like a predictable case than a coding error.


2022-09-22 18:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.