Algorithms Flashcards

1
Q

How to check if an algorithm has a specific complexity?

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

Difference between big O, theta, and omega notation?

A

big O describes the worst-case performance of an algorithm, it may perform better.
big Theta describes the specifically determined performance of an algorithm (down to constant level). E.g. an algorithm with runtime n^2 will always take a constant multiple of n^2 to run.
big Omega describes the best-case performance of an algorithm, it may perform worse.

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

What is a stable sorting algorithm?

A

If two elements are in a specific order before sorting and have equal values, they will be in the same order afterwards.

Examples are: merge sort, insertion sort and bubble sort.

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

What is the best case runtime for any comparison-based sorting algorithm?

A

nlogn

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

What does it mean that big Theta is symmetrical?

A

If f(n) is O(g(n)) then g(n) is O(f(n))

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

Which sorting algorithms are divide-and-conquer?

A

Quick sort, merge sort, heap sort, binary-tree sort

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

What is counting sort?

A

For an array with elements with a known maximum value k:
Create a secondary array B with k+1 positions.
Count occurrences of each number in its corresponding place in B.
Replace each number in B with the sum of the numbers before it.
Iterate over original array A, for each value look up the new index in C by indexing into B with the value.
After each insertion, decrement the value in B for that value.

It has runtime O(n).

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

Constructing a heap

A

Each node in the heap must be bigger than its children. To heapify: traverse the tree from the right side of the array to the left. If node does not fulfil heap property: heapify it.

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

Properties of heap sort?

A

heapify has runtime O(log n) and heap construction has runtime O(n log n).
Unstable.
In-place.

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

Properties of insertion sort?

A

In-place.
Stable.
O(n^2)

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

How to do radix sort?

A

Use an in-place sorting algorithm to sort the array of numbers by each digit individually, starting with the least-significant digit.

Sorts in O(d*f) where f is the runtime of the in-place sorting algorithm, and d is the number of digits in each element.

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