Algorithms and Complexity Flashcards

(62 cards)

1
Q

Define an algorithm

A

A finite set of computational steps that transform input into output

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

Why do we use algorithms?

A

Algorithms are effective methods for solving a class of problems

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

What are common properties of algorithms?

A
  1. The inputs to an algorithm must be finite
  2. The inputs to an algorithm represent instances of the problem
  3. An algorithm should produce the correct outcome
  4. An algorithm should terminate
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give examples of algorithm formats

A

Text, pseudocode, flowcharts, and computer code

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

What makes an algorithm better than another?

A

We evaluate algorithms based on their space and time complexity

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

Define space complexity

A

The amount of memory required by an algorithm to run to completion

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

What are the two types of the memory that is required by an algorithm?

A

The fixed and the variable memory

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

Define the fixed part of memory needed by an algorithm

A

The amount of memory required to store certain data/variables whose size is independent of the input to the algorithm

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

Define the variable part of memory needed by an algorithm

A

The amount of memory required to store variables whose size is dependent on the input to the program

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

Define time complexity

A

The theoretical relationship between the time an algorithm will take to run and the size of its input expressed as a function of the size of the inputs

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

What factors effect runtime?

A

The size of inputs, the organisation of the inputs, the optimal operating temperature and the number of processor cores

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

What case do we consider when evaluating the runtime of an algorithm?

A

The worst case scenario

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

Why is it rare to have an algorithm with the best time and space complexity?

A

Often in decreasing the time or space complexity we increase the other meaning that we either need to work out whether our program should prioritise speed or memory or we need to balance the two equally

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

Why would we not focus on the worst case scenario with regards to runtime?

A

If the worst case scenario is very rare there is little point in considering it in which case we would consider the average case

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

Describe an experimental method of determining the runtime of a program

A

Running the program for a range of inputs and plotting the runtime

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

Why do we rarely use an experimental approach to determine the runtime of a program?

A

You need to implement the algorithm for every input and also ensure that the running conditions are exactly the same for every test

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

What is an alternative methods to determining how long an algorithm will take to run that is not experimental?

A

Operation counting

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

What problem do we face with operation counting?

A

We need to determine what counts as one operation independent of which programming language it is in because there are differences between programming languages

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

What does operation counting mean?

A

Counting how many operations are in an algorithm by tracing it through and working out how many will be executed for different inputs

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

Why do we have different cases when analysing runtime using operation counting?

A

The runtime is not just dependent on the number of operations but also on the organisation of the input

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

What does the notation T(n) mean?

A

The overall program time as a function of n

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

How do we determine the average case for the runtime of a program if we cannot determine the runtime for every instance of inputs?

A

We work out the average number of times an instruction will be executed using the Nth partial sum equation and then use this to determine the average runtime

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

What is the worst case time complexity for a linear search?

A

T(N) = 3N + 3

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

How does a sentinel search work?

A

It checks to see whether the desired element is at the end of the list, if it is then it’s returned, if not then it sets the last item in the list equal to the desired element. This means that you do not have to perform the check to see whether you are out of bounds.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the worst case time complexity for a sentinel search?
T(N) = 2N + 3
26
What is the worst case time complexity for a binary search?
T(N) = C1 + C2log(N)
27
What does the growth of functions describe?
How the runtime for a function increases as the number of input elements increases
28
What does Big-Ohm represent?
The best case time complexity
29
What does Big-O represent?
The worst case time complexity
30
What does Big-Theta represent?
The average time complexity
31
What is an intractable problem?
A problem which does not have a solution with a time complexity that is less than polynomial time
32
What is a super polynomial function?
A function which has a time complexity greater than polynomial
33
Define tractable
A problem which has an algorithmic solution with a polynomial time complexity or better
34
What are P problems?
Problems for which there is a polynomial time algorithm
35
What are EXP problems?
Problems for which there is an exponential time algorithm
36
What are R problems?
Problems solvable in finite time
37
T/F: Even if a problem is intractable, checking a solution to the problem is tractable
True
38
What is an exhaustive search?
Often the process for many naive algorithms which involves checking all possible answers
39
Downsides to exhaustive search
It can lead to combinatorial explosion and an exponential running time
40
NP problems definitions
Non deterministic polynomial time = decision problems that can be checked in polynomial time
41
What would happen if we proved that NP != P?
1. Prove that for some questions there is no clever shortcut to find the right answer 2. Prove there is a way to obscure information 3. Understand a lot more about computation
42
What would happen if we could prove that P = NP?
1. We can decrypt all current internet communication 2. It will be useful for logistics and delivery (TSP) 3. Revolutionise AI leading to faster computation and enhanced optimisation algorithms 4. Possibly lead to a cure for cancer because protein folding is an NP-complete problem
43
What are heuristics?
Conditions applied to develop a suboptimal but good enough solution
44
What is a decision problem?
A problem with a yes or no answer
45
What is a decidable problem?
A decision problem that can be solved by an algorithm
46
How do we define a decision problem in terms of algorithms?
X is a binary relation mapping an instance to a solution. Decision problems are a variant of X which maps an instance to {0, 1}
47
Define non determinism
To try everything and if one attempt works then return yes
48
T/F: A deterministic algorithm will return a different value every time for a specific set of input values
False, it will always give the same output for the same input
49
What is an equivalent set of problems to NP problems?
The set of decision problems with a polynomial time certifier
50
What is the purpose of a certifier?
A certifier verifies that the solution to a problem can be executed in a certain time complexity .e.g. polynomial time
51
How do we check the efficiency of a solution using a certifier?
We check the length of the certifier and check the runtime of the certifier
52
What does NP-completeness focus on?
The hardest problems in NP
53
How do we determine which problems are NP-complete?
We can compare the relative difficulty of problems using polynomial time reductions which provide a formal means of showing that one problem is at least as hard as another to within a polynomial time factor
54
Explain how a reduction works
Let X1 and X2 be decision problems. Suppose A2 solve X2. The idea is to find a function f such that A2 can be part of an algorithm A1 to solve X1.
55
When can we say that problem X1 is polynomial time reducible relative to a problem X2?
If there is a function f, computable in polynomial time, that takes input x to X1 and transforms it to an input f(x) of X2, such that the solution to X2 on f(x) is the solution to X1 on x.
56
What does X1 <=p X2 mean?
X1 is polynomial time reducible relative to X2
57
If we know the Y <=p X and X is a member of P what does that mean for Y?
Y is also a member of P
58
How does polynomial time reduction help us determine the hardness of a problem?
If we know that Y is polynomial time reducible relative to X then we know that Y is no more hard than X is (and vice versa)
59
When is a decision problem NP-complete?
1. B is a member of NP 2. A <=p B for A where A is a member of NP (for all problems A in NP, A reduces to B in polynomial time proving B is just as hard as every other NP problem)
60
What NP-hard mean?
That a problem may not be NP but it is just as hard as any other problem in NP
61
What is the relationship between NP-complete and NP-hard?
For a problem to be NP-complete it must be NP and NP-hard
62
Give an example of an NP-complete problem
SAT