When Merge Sort is pre...
When Merge Sort is pre...
Merge sort is preferred over quicksort in the following scenarios:
When sorting linked lists: Quicksort highly depends on randomly accessing data elements and swapping them. Since linked lists do not have continuous memory allocation, randomly accessing elements is inefficient. Merge sort is faster for linked lists because it reads data sequentially[2].
When sorting large datasets: Merge sort is more efficient and works faster than quicksort for larger array sizes or datasets. Quicksort cannot work as well with large datasets[3].
When stability is required: Merge sort is a stable sorting algorithm, meaning that elements with equal values appear in the same order in the sorted output as they were in the input unsorted array. Quicksort is unstable by default, although it can be made stable with some changes to the code[3].
When sorting arrays with many repeated elements: The performance of quicksort degrades when there are many repeat...
senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào