sorting Flashcards

1
Q

selection sort runtime

A

O(N^2)

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

number of comparisons in selection sort

A

(N-1)*N/2

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

How many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?

A

20^2 / 10^2 = 4

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

selection sort’s runtime grows _______with the input size

A

quadratically

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

insertion sort runtine

A

O(N^2)

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

in insertion sort the outer loops executes ______ times

A

N-1

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

in insertion sort the inner loop executes on average _______ times

A

N/2

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

First iteration (i = 1) requires at most 1 comparison, second iteration requires at most 2 comparison, the third 3 comparison, and so on.

A

x

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

For sorted or nearly sorted inputs, insertion sort’s runtime is …

A

O(N)

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

The worst-case performance for insertion sort is when the list elements are in…

A

descending order

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

midpoint in quicksort

A

i + (k -i) / 2

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

quicksort time complexity

A

O(N*logN)

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

If the number of elements in the numbers array is even, the midpoint value is rounded …

A

down

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

in quicksort there are ______ partitioning levels

A

log2 N

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

in quicksort there are ______ comparisons

A

N * log2 N

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

the worst case runtime for the quicksort algorithm is

A

O(N^2)

15
Q

In quickosrt the worst case, for N elements, there will be ______levels

A

N - 1

16
Q

worst case quickosrt, how many total comparisons are required to sort a list of N elements

A

N * (N-1)

17
Q

in selection sort the outer loop executes…

A

N - 1 times

18
Q

in selection sort the inner loop executes on average …

A

N/2 times

19
Q

the merge sort algorithm’s runtime is …

A

O(N log N)

20
Q

at each level, merge sort does about ___ comparisons

A

N

21
Q

merge sort has a total of ______ comparisons

A

N * log N

22
Q

Merge sort requires _____ additional memory

A

O(N)

23
Q

stable sorting algorithm

A

preserves the order of two data items with the same key