8 - Algorithms 1 (Sorting) Flashcards

1
Q

What is sorting?

A

Operation that takes input values and places them in a specific order

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

Why may you need sorting?

A
  • You need to sort (for easier readability)

- Optimise other algorithms (makes efficient search of merge), median-based statistics

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

What is a comparison based algorithm?

A

Compare two elements, if not in order then exchange

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

What is the best work complexity of compare and exchange?

A

O(nlogn)

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

What does the performance of comparison based algorithms depend on?

A

The data

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

What is a serial bubble sort?

A

Repeatedly compare and exchange the adjacent neighbours if they are in the wrong order

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

What is the work complexity of a serial bubble sort?

A

O(n2) - not recommended in practical aogirithms

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

How can a serial bubble sort be modified?

A

To detect early exit

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

What is a parallel odd even sort?

A

Parallel “bubble sort” - compare and exchange all independent neighbouring pairs in two phases (odd and even)

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

What is the step complexity of the odd even sort?

A

O(n)

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

What is the work complexity of the odd even sort?

A

O(n2)

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

What are good applications of the odd even sort?

A

Good for very small sequences (tens of elements)

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

What does a sorting network consist of?

A

Comparators and wires

Wires carry values

Each comparator connects two wires and swaps the values if the top wire’s value is greater

Arranged in columns each representing a single step

Output is sorted top to bottom

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

What is the speed of a sorting network proportional to?

A

Its depth (number of steps)

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

What is the goal of sorting networks?

A

To design a network such its depth and number of comparators is as low as possible

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

What do optimal sorting networks do?

A

Sort N elements in smaller than O(nlogn) operations

17
Q

What is a bitonic sequence?

A

A sequence with two tones, increasing and decreasing.

Any cyclic rotation of such sequences is also considered bitonic

18
Q

What is the special property of bitonic split?

A

If you split one bitonic sequence into two parts and perform compare and exchange operation on each element of both parts, you get bitonic sequences.

All elements in part one are smaller than those in part two

19
Q

How do you sort a bitonic sequence?

A

Recursively perform bitonic split operations on it

20
Q

What do a sequence of bitonic splits form?

A

A bitonic merge

21
Q

How do you obtain a bitonic sequence from an unordered input sequence?

A

Merge two pairs of two elements to form a bitonic sequence of length 4

Sort first two elements using a comparator

Sort the next two using a reverse comparator

Repeat but with 8 instead of 4 and so on

22
Q

What is the two step procedure to a Bitonic sort?

A

Convert an unordered sequence into a bitonic sequence (apply a set of bitonic merges)

Sort the bitonic sequence into an ordered sequence (final bitonic merge)

23
Q

What is the step complexity of bitonic sort?

A

O(log2n)

24
Q

What is the work complexity of bitonic sort?

A

O(nlog2n)