Quiz 2 Flashcards

1
Q

Is heapsort a stable sorting algorithm?

A

No, it is not stable.

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

Does heapsort sort in place?

A

Yes, it sorts in place.

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

Is insertion sort stable?

A

Yes, insertion sort is stable.

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

Is insertion sort in-place?

A

Yes, insertion sort operates in place.

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

Is merge sort stable?

A

Yes, merge sort is stable.

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

Is merge sort in-place?

A

No, merge sort requires extra space.

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

What is the lower bound for comparison-based sorting algorithms?

A

Ω(n log n)

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

What is the runtime of randomized quicksort in the average case?

A

O(nlogn)

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

Is quicksort stable?

A

No, quicksort is not a stable sorting algorithm.

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

Does quicksort sort in place?

A

Yes, quicksort operates in place.

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

Is selection sort stable?

A

No, selection sort is not stable.

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

Is selection sort in-place?

A

Yes, it sorts in place.

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

What is heapsort?

A

Heapsort is a comparison-based sorting algorithm that sorts an array in place by building a heap data structure and extracting elements in order.

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

How does heapsort work?

A

Heapsort works by first organizing the data into a binary heap. The largest element is placed at the root. Then it repeatedly extracts the root and places it at the end of the sorted array. With each extraction, the heap property is restored.

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

What is the worst case runtime complexity of heapsort?

A

O(nlogn)

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

What is the space complexity of heapsort?

A

O(1). Heapsort operates in place, requiring constant extra space.

17
Q

When should heapsort be preferred over other sorting algorithms?

A

When fast in-place sorting is required. The O(nlogn) runtime is comparable to efficient algorithms like quicksort, but heapsort has the advantage of being in-place.

18
Q

What is insertion sort?

A

Insertion sort iterates through the array, swapping the current element with others to insert it in the correct sorted position.

19
Q

What is the best case runtime complexity of insertion sort?

A

O(n) when the array is already sorted.

20
Q

What is the average and worst case runtime complexity of insertion sort?

A

O(n^2)

21
Q

When is insertion sort preferred?

A

For small or mostly sorted data. The simplicity provides advantages in these cases.

22
Q

What is merge sort?

A

Merge sort divides the array recursively into halves until single elements remain. It then merges the smaller sorted arrays to produce the final sorted array.

23
Q

What is the runtime complexity of merge sort?

A

O(nlogn) for all cases.

24
Q

What are the space requirements of merge sort?

A

O(n) auxiliary space is required. It is not an in-place sort.

25
Q

When should merge sort be used over other O(nlogn) algorithms?

A

When a stable sort is required. Merge sort is stable, unlike quicksort and heapsort.

26
Q

What is quicksort?

A

Quicksort picks a pivot element and partitions the array into two subarrays of elements less than and greater than the pivot. It recursively sorts the subarrays.

27
Q

What is the runtime complexity of quicksort?

A

O(nlogn) average case. O(n^2) worst case.

28
Q

How can quicksort’s worst case be improved?

A

Choosing the pivot randomly or the median of a sample.

29
Q

What are the space requirements of quicksort?

A

O(logn) space for call stack. O(n) total space. In-place.

30
Q

When is quicksort preferred over other sorts?

A

Its in-place nature and O(nlogn) average case make it one of the fastest sorts.

31
Q

What is selection sort?

A

Selection sort repeatedly finds the minimum remaining element and swaps it into the next position.

32
Q

What is the runtime complexity of selection sort?

A

O(n^2) in all cases.

33
Q

What are the advantages of selection sort?

A

Simple implementation. Minimal data movement.

34
Q

What is quick select?

A

Quick select finds the kth smallest element in an unsorted array, based on the quicksort partitioning approach.

35
Q

What is the runtime complexity of quick select?

A

O(n) average case. O(n^2) worst case.

36
Q

When should quick select be used instead of sorting?

A

When only a few order statistics are needed instead of full sorting.