7: Analysis Flashcards
Analysing program complexity
Define asmptotic complexity
The degree to which an algorithm (or its subprocesses) become more complex or the nuber of required operaions becomes greater in number as the length of the input lengpth increases.
Give the notations for best, worst, and average complexities
Best case = Θ(n), exact upper bound
Average case = O(n), rough upper bound
Worst case = Ω(n), lower bound
When is an algorithm in the exponential class of time compelxity?
When the exponent in an exponential is (a) variable, e.g. length of array as input.
What is loop hoisting?
Trying to refactor program loigic to remove loops to optimise complexity/ies.
What is the lower bound on sorting comparables? Assume involves comparisons of whole comparable objects being sorted and not other properties or fields, such as sort keys.
Minimum time complexity Ω(nlog(n))
What are sort keys?
Fields in items in a list that dictate the order of the list. In a database they are fields and a type of key (e.g. primary).
What’s the proof of the lower bound for sorting?
Proof for minimum time complexity Ω(nlog(n)) for sorting algorithms:
For a list of n elements, there are n! different possible orderings of the elements.
A comparison has 2 results: which of 2 elements to put 1st. With k comparisons made to sort the list and comparisons involved in the whole algorithm, this results in 2 ^ k choices.
2 ^ k must be >= n! since we have to distinguish between all the different possible orderings, of which there are n!.
This is true when k >= log2(n!)
Via Stirling’s approximation, log2(n!) is Ω(nlog(n)) worst case.
What would P != NP actually mean?
Each NP problem would have a superpolynomial lower bound of complexity.
What are P problems? What does P stand for?
P problems have proofs showing they can be solved in polynomial time by a deterministic TM. P stands for polynomial; since no N for nondeterministic, “P” problems are deterministically (and therefore also nondeterministically) solvable within polynomial (P) time.
What are NP problems? What does NP stand for?
NP problems have no proof showing they can be solved in polynomial time by a deterministic TM but do have a proof showing they can be verified in polynomial time by a deterministic TM.
Note verification is checking against previously found results, e.g. factorials of BigIntegers in a HashMap in Java so you don’t need to recalculate each time.
NP stands for Nondeterministic Polynomial, since solvable in polynomial time only nondeterministically and not deterministically.
What are NP-hard problems?
NP-hard problems are all problems that NP problems can be reduced to in polynomial time by a deterministic TM.
What are NP-complete problems?
NP-complete problems are problems in both NP and NP-hard. They have no existing proof they can be done in polynomial time by a deterministic TM, have a proof they can be verified in polynomial time by a deterministic TM, and can be reduced to from NP problems in polynomial time by a deterministic TM.
Note verification is checking against previously found results, e.g. facotorials of BigIntegers in a HashMap in Java so you don’t need to recalculate each time.
What is verification?
Verification is checking against previously found results, e.g. facotorials of BigIntegers in a HashMap in Java so you don’t need to recalculate each time.
What do divide and conquer algorithms do?
Recursively divide problems into smaller subproblems, before solving (“conquering”) the original larger problem by combining the results of solving the subproblems.
What is a recurrence relation?
Recurrence relations are equations defining each element in sequences as a function of the preceding ones. They are used to define recursive functions.