Câu hỏi phỏng vấn Sorting
Câu hỏi

When Merge Sort is pre...

Câu trả lời

Merge sort is preferred over quicksort in the following scenarios:

  1. 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].

  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].

  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].

  4. When sorting arrays with many repeated elements: The performance of quicksort degrades when there are many repeat...

senior

senior

Gợi ý câu hỏi phỏng vấn

junior

Classify Sorting Algorithms

junior

What are advantages and disadvantages of Bubble Sort?

entry

Why Sorting algorithms are important?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào