Algorithms for sorting Flashcards
What is a selection sort and how does it work?
Selection sort is a straightforward method where the list is split into sorted and unsorted parts. It repeatedly selects the smallest element from the unsorted section and swaps it with the first unsorted element. This process continues until the list is sorted.
What is a quick sort and how does it work?
Quick sort works by selecting a central element (pivot), organizing smaller elements left and larger ones right. This process continues until the list is sorted.
Which is faster, quick sort or selection sort? Is this always the case? Explain.
Selection sort might be preferred over quick sort for small datasets or when simplicity and stability are crucial.
However, for larger datasets and optimal performance, quick sort is generally favoured due to its efficiency.