5-6 Flashcards

1
Q

How does a divide and conquer algorithm work?

A

If the data structure is an atom case it is processed directly, else we divide it into two or more smaller pieces, and apply the algorithm recursively.

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

How does binary search work?

A

Needs sorted data, find the middle index and compare with what is being searched for. If the searched for item is less search the left subarray, if greater than the middle search the right subarray. If an empty array is returned we have split too much and the item is not in the array.
Has a complexity of O(log n).

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

How do we merge to sorted arrays?

A

Compare two keys, put the lower one in the array and increment the index for the main array and the sub array the lower key came from. Repeat. Merge is O(n).

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

How does mergesort work?

A

Repeatedly split an array and once at the bottom rebuild by merging the pieces.

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

How do we solve a recurrence?

A

We need to get rid of the f(n) on the right hand side of the equation, try to simplify the pattern and then substitute, turning the f(n-k) into f(1), e.g by making k = n-1. This is not proof yet.
We must show that f and the new function g are the same function. Do this using induction.

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