Sorting Algorithms (Module 5) PART 1 Flashcards

1
Q

What is the process of arranging data in a specific order?

A

sorting

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

What is sorting fundamental for?

A
  • efficient data organization
  • retrieval
  • manipulation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Each sorting algorithm is optimized for and offers trade-offs to which 3 things?

A

speed, memory usage, complexity

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

Why might we consider input size when selecting a sorting algorithm?

A

small datasets can favor simpler algorithms, while larger datasets need more efficient algorithms

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

Why might we consider time complexity when selecting a sorting algorithm?`

A

worst and best-case scenarios

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

What type of sorting maintains the relative order of equal elements?

A

stable sorting

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

Why might we consider the nature of input data when selecting a sorting algorithm?

A

pre-sorted, nearly sorted data, and random data might favor different sorting algorithms

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

Why might we consider real-time constraints when selecting a sorting algorithm?

A

real-time systems might prioritize algorithms with predictable performance

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

Sorting algorithms generally fall into which 2 runtime complexities?

A

O(n log n) and O(n^2)

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

What are the two O(n^2) sorting algorithms?

A

insertion sort and selection sort

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

What are the two O(n log n) sorting algorithms?

A

Quick sort and merge sort

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

Which type of sorting algorithm sorts by swapping elements within the same array?

A

in-place sorting algorithms

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

Do in-place sorting algorithms require additional memory for another array?

A

no!

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

Does out-of-place require extra memory for the output array?

A

yes!

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

What makes a sorting algorithm “stable”?

A

if the relative order of the identical keys in the input is preserved in the output

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

When is the stability of a sorting algorithm important?

A

when entries with identical keys are already ordered

17
Q

What is the formula for finding pairs of numbers?

A

(n 2) = n(n-1) / 2

18
Q

What refers to a pair of elements in a sequence that are out of their desired order?

19
Q

Why do the number of inversions matter?

A

each pair in a random ordering has an equal chance of being inverted or ordered

20
Q

The number of inversions in a list is an indicator of what?

A

how far the list is being sorted

21
Q

A sorted array has how many inversions?

22
Q

A completely reversed list has the ________ number of inversions

23
Q

Insertion sort performs better when the number of inversions is _______

24
Q

Which sorting algorithm uses inversions to calculate the number of swaps needed to sort a list?

A

merge sort