Efficiency and Complexity Flashcards

1
Q

How does selection sort work?

A

Find the smallest item in the unsorted part of the list and put it at the beginning by making a swap

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

How do we analyse how “fast” an algorithm is?

A

The efficacy of implementations of an algorithm depend on the language used, the compiler used, and the processor executing the code
Therefore we analyse the ALGORITHM instead, expecting that our analysis will be machine independent

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

Why is it not possible to formally define the time taken by an algorithm?

A

We don’t have a formal definition of pseudocode. We work around this by hiding and working around irrelevant details

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

What fundamental assumptions do we make when analysing program efficiency

A

Any basic algorithmic operation takes at most “c” units of time
“output A” takes c*len(A) units of time
The cost of following the control flow is 0
Input numbers will always be small enough to not cause overflow

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

How do we express the worst-case upper bound on an algorithm’s run-time?

A

As a function f(n) where n is the size of the input
The algorithm terminates in at most f(n) units of time
Fundamental assumption: The size of an input is the number of basic objects it contains

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

If f and g are functions, what does it mean if f is O(g)?

A

There are constants C and k such that |f(x)| <= C|g(x)| when x >= k
This essentially means that after a certain point, f(x) never goes above C
g(x)

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

What is the reasoning behind the use of Big-O notation?

A

The bound “x >= k” caters for when one algorithm might be faster than another but only up until a certain input size
The constant C allows us to disregard c, and think of all functions that only differ by a multiplicative constant as the same

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

When is worst-case asymptotic time complexity not a good indication of how practical an algorithm is?

A

When the hidden constants are large enough to have a significant impact
When the average-case time complexity is much better than the worst-case time complexity (e.g. quick sort)
Some algorithms are more memory-efficient
Some algorithms are “online” while others aren’t

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

What are efficiently solvable/tractable problems (P)?

A

Problems that can be solved by an algorithm of time complexity O(n^k)

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

Which well-known problems aren’t tractable?

A

Travelling salesman, colouring

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

What are NP problems?

A

If a problem is NP, then we can check whether or not a witness for an instance implies that that instance is a yes-instance. P problems are a subset of NP-problems.

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

What is a polynomial-time reduction algorithm?

A

An algorithm that takes an instance I of a decision problem X, and converts it into an instance J of a second decision problem Y, such that I is a yes-instance if and only if J is a yes-instance. Y is a polynomial-time reduction of X.

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

What is an NP-complete problem?

A

An NP problem Y which is a polynomial-time reduction of any NP problem X (e.g. TSP)

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

How could we prove that P = NP?

A

Finding an NP-complete problem which is also in P

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

What is an NP-hard problem?

A

A search or optimisation problem whose solution in polynomial time would imply that P = NP (e.g. TSP, colouring, longest cycle in a graph)
Example: if we could solve the TSP in polynomial time, then we could solve the decision version in polynomial time too. Since TSP is NP-complete, it being in P would mean that P = NP

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

How can we solve the TSP?

A

Brute force using recursion, this is pretty much the situation for all NP-complete problems

17
Q

What is Ant Colony Optimisation (ACO)?

A

The optimisation problem is transformed into the problem of finding the best path in a weighted graph. Artificial ants traverse the graph, leaving pheromones. Popular, efficient paths will have lots of pheromones and will end up attracting more ants who will in turn leave pheromones.

18
Q

What is a genetic algorithm?

A

A way of solving optimisation problems, based off evolution
Solutions to the problem are the “individuals”, and the better the solution is, the “fitter” it is. New solutions are formed by individuals “breeding”, and fitter individuals are more likely to be selected for breeding.