Algorithms for sorting Flashcards

1
Q

What is a selection sort and how does it work?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a quick sort and how does it work?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which is faster, quick sort or selection sort? Is this always the case? Explain.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly