Sorting Algorithms (Module 5) PART 2 Flashcards

1
Q

Which sorting method uses loops to process elements step by step, progressively refining the order of the array?

A

iterative sorting method

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

What are the 2 common techniques for iterative sorting methods?

A

insertion sort and selection sort

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

Which sorting algorithm builds a sorted portion by inserting each element into the correct position?

A

insertion sort

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

Which sorting algorithm repeatedly selects the smallest (or largest) element form the unsorted portion and swaps it with the first unsorted element?

A

selection sort

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

Iterative sorting methods usually have a time complexity of O(n^2), making them less efficient for ________.

A

large datasets

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

How does the mechanism for insertion sort work? (3 steps)

A

1) start with empty “sorted’ section
2) take elements from “unsorted” section and insert them into correct position in the sorted section
3) repeat until all elements are sorted

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

The worst-case time complexity for insertion sorting is when the array is in the ________ order.

A

reversed

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

What is the best-case time complexity for selection sorting?

A

O(n^2)

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

Is selection sorting a stable sort?

A

no!

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

For selection sort, there are at most ________ swaps

A

n-1

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

Recursive sorting methods use _____-___-_______ strategy

A

divide-and-conquer

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

Recursive sorting methods require ____ space for recursive calls

A

stack space

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

What are the 3 steps for the divde-and-conquer strategy

A

1) Divide (break problem into smaller problems)
2) Conquer (solve smaller problems)
3) Combine the solutions from the smaller problems into the final solution

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

Quick sort partition the array around a pivot value which yields ____ < _____ < _______

A

L < pivot < G

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

What is the mechanism for quick sort? (3 steps)

A

1) choose P (pivot) and partition L< P and G > P
2) divide-and-conquer L and G
3) merge together

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

Which pivot consists of randomly selecting a pivot?

A

random pivot

17
Q

Which pivot consists of using the first element as a pivot?

A

first element pivot

18
Q

Which pivot uses the median as the pivot?

A

median-of-three pivot

19
Q

What is the best type of pivot to use, and why?

A

median-of-three pivot because it takes O(n log n)