quicksort Flashcards

(20 cards)

1
Q

What is the main idea behind Treesort?

A

Insert elements into a BST, then return the inorder traversal.

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

Why does inorder traversal of a BST return a sorted list?

A

Because in a BST, left < node < right is always true.

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

What is the worst-case complexity of Treesort?

A

O(n²), if the BST becomes unbalanced.

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

How can we ensure Treesort runs in O(n log n) time?

A

Use a self-balancing tree like an AVL tree.

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

What is stability in sorting?

A

Maintaining the relative order of elements with equal keys.

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

Is BST-based Treesort stable by default?

A

No, because equal elements may be inserted in arbitrary order.

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

How can stability be preserved in a tree-based sort?

A

By consistently placing duplicates to the right or tagging entries with input order.

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

What is Big-O notation used for?

A

Describing an upper bound on algorithm growth — worst-case performance.

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

What is Big-Theta notation used for?

A

Describing the tight bound — the actual growth rate.

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

Why is it important to use Big-O and Big-Theta properly?

A

To avoid misrepresenting algorithm efficiency and complexity.

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

What is Quicksort inspired by?

A

The idea of constructing a BST and performing an inorder traversal — but done in-place.

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

How does Quicksort work?

A

It partitions the array around a pivot, then recursively sorts the subarrays.

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

What is the role of the pivot in Quicksort?

A

It divides the array into elements smaller and greater than itself.

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

What is Quicksort’s average-case complexity?

A

O(n log n)

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

What is Quicksort’s worst-case complexity?

A

O(n²), usually when the pivot is poorly chosen.

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

How can we avoid Quicksort’s worst-case performance?

A

By shuffling the input or using better pivot selection methods.

17
Q

Why is Quicksort faster than mergesort in practice?

A

Because it uses less memory and benefits from better cache usage.

18
Q

What is a practical optimization used in Quicksort?

A

Switching to insertion sort for small subarrays — a polyalgorithm.

19
Q

What is a median-of-three strategy?

A

A pivot selection heuristic that picks the median of the first, middle, and last elements.

20
Q

Why is Quicksort not stable by default?

A

Because swaps can move equal elements out of their original order.