recurrence relations Flashcards

1
Q

insertion sort algorithm

A

Step 1 − If it is the first element, it is already sorted. return 1;
Step 2 − Pick next element
Step 3 − Compare with all elements in the sorted sub-list
Step 4 − Shift all the elements in the sorted sub-list that is greater than the value to be sorted
Step 5 − Insert the value
Step 6 − Repeat until list is sorted

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

insertion sort time complexity

A

O(n^2)

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

merge sort running time

A

worst case time complexity O(n log n)

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

merge sort algorithm

A

Step 1 − if it is only one element in the list it is already sorted, return.
Step 2 − divide the list recursively into two halves until it can no more be divided.
Step 3 − merge the smaller lists into new list in sorted order.

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

Substitution method advantages and disadvantages

A

Guess a solution and check if it is correct
Pros: rigorous, formal solution
Cons: requires induction, how do you guess?

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

Recursion trees advantages and disadvantages

A

Build a tree representing all recursive calls, infer the solution
Pros: intuitive, visual, can be used to guess
Cons: not too formal

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

Master method advantages and disadvantages

A

Check the cookbook and apply the appropriate case
Pros: formal, useful for most recurrences
Cons: have to memorize, useful for most recurrence

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

substitution method steps

A

Steps
*Guess the solution
*Use induction to show that the solution works

What is induction?
A method to prove that a given statement is true for all-natural numbers 𝑘
Two steps
Base case: show that the statement is true for the smallest value of 𝑛 (typically 0)
Induction step: assuming that the statement is true for any 𝑘, show that it must also hold for 𝑘+1

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

master method recurrence function template

A

𝑇(𝑛)=𝑎𝑇(𝑛/𝑏)+𝑓(𝑛)
Compare 𝑛^log_𝑏⁡𝑎 vs. 𝑓(𝑛)

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

master method case 1

A

if f(n) < n^log_b(a)
then theta(n^log_b(a))

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

master method case 2

A

if f(n) = n^log_b(a)
then theta( n^log_b(a) * log(n))

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

master method case 3

A

if f(n) > n^log_b(a)
then theta(f(n))
and a.f(n/b) ≤ k.f(n)

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

master method, all three cases

A

Intuition: the larger of the two functions determines the solution

The three cases compare 𝑓(𝑛) with 𝑛^log_𝑏⁡(𝑎)
Case 1: 𝑛^log_𝑏⁡(𝑎) is larger – 𝑂 definition
Case 2: 𝑓(𝑛) and 𝑛^log_𝑏⁡(𝑎) grow at the same rate – Θ definition
Case 3: 𝑓(𝑛) is larger – Ω definition

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

columns in recurrence tree method

A

recursive call
#nodes
tree
row sum

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