Sorting Flashcards

1
Q

downside of most most worst-case sorting algorithms that do optimally well in the worst-case

A

(notably heap sort and merge sort), do not take existing order within their input into account,

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

how to rectify mergesort not taking into account existing order of its input?

A

by checking if the last element of the lefthand group is less than (or equal) to the first element of the righthand group, in which case a merge operation may be replaced by simple concatenation – a modification that is well within the scope of making an algorithm adaptive.

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

list 8 adaptive sort algorithms

A

adaptive heap sort, adaptive merge sort, patience sort,[1] Shellsort, smoothsort, splaysort, straight insertion sort, and Timsort.

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

why are adaptive sorting algorithms attractive?

A

because nearly sorted sequences are common in practice

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

adaptive sort

A

A sorting algorithm falls into the adaptive sort family if it takes advantage of existing order in its input. It benefits from the presortedness in the input sequence – or a limited amount of disorder for various definitions of measures of disorder – and sorts faster. Adaptive sorting is usually performed by modifying existing sorting algorithms.

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

Permutation

A

permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word “permutation” also refers to the act or process of changing the linear order of an ordered set.

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

How many permutations are there in a set of n elements?

A

n!

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

technically a permutation of set S is defined as what

A

a bijection from S to itself.[2][3] That is, it is a function from S to S for which every element occurs exactly once as an image value

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

The collection of all permutations of a set form what?

A

a group called the symmetric group of the set, where the group operation is the composition (performing two given rearrangements in succession), which results in another rearrangement

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

k-permutation

A

the number of arrangements of k items from n objects

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

How to denote a k permutation

A

It can be written as nPk (which reads “n permute k”)

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

nPk is equal to?

A

n(n−1)⋯(n−k+1)

aka
n!/(n−k)!

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

Insertion sort

A

InsertionSort(A) //[0, n-1]

For (i = 0 to ) 
  let j = i + 1
  while (j> 0 && A[j] > A[j-1]) 
    swap(A, j, j-1)
    j—
How well did you know this?
1
Not at all
2
3
4
5
Perfectly