Chapter 2 Sorting Flashcards

(25 cards)

1
Q

What is the goal of sorting?

A

To arrange elements in non-decreasing order.

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

What does BruteSort do?

A

Tries all permutations of the array until it finds a sorted one.

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

What is the time complexity of BruteSort?

A

O(n!)

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

Why is BruteSort inefficient?

A

It checks every permutation, which grows factorially with n.

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

What is InsertionSort?

A

A sorting algorithm that inserts elements into their correct position in a growing sorted portion.

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

What is the time complexity of InsertionSort?

A

O(n^2)

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

What is the principle behind MergeSort?

A

Divide-and-conquer: divide the array, sort each half, merge them.

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

What is the time complexity of MergeSort?

A

O(n log n)

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

What does Merge do in MergeSort?

A

Combines two sorted arrays into one sorted array.

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

What is QuickSort?

A

A divide-and-conquer sorting algorithm using a pivot to partition the array.

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

What is the worst-case complexity of QuickSort?

A

O(n^2)

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

What is RandomisedQuickSort?

A

QuickSort with a random pivot to reduce likelihood of worst-case.

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

Expected complexity of RandomisedQuickSort?

A

O(n log n)

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

What is BucketSort?

A

Sorts by placing values into buckets and sorting each bucket.

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

When is BucketSort efficient?

A

When the data is uniformly distributed.

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

What is the worst-case complexity of BucketSort?

17
Q

What is the selection problem?

A

Finding the i-th smallest element in an array.

18
Q

What is RandomisedSelect?

A

A QuickSort-based algorithm to find order statistics.

19
Q

Expected complexity of RandomisedSelect?

20
Q

Worst-case complexity of RandomisedSelect?

21
Q

Why is RandomisedPartition used?

A

To reduce the chance of poor pivot selection.

22
Q

What does the partition function do?

A

Reorders array so elements ≤ pivot are on the left, others on the right.

23
Q

What is an order statistic?

A

The i-th smallest element in a sample.

24
Q

Why sort to find order statistics is inefficient?

A

Sorting takes O(n log n), but selection can be done in O(n).

25
What is a pivot in QuickSort?
An element used to divide the array into two partitions.