Week 7 - Algorithm Complexity & Concurrency Flashcards

1
Q

What is an Algorithm?

A

An algorithm is an effective method for solving a problem expressed as a finite sequence of instructions.

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

What is the design and analysis like in the algorithm?

A

Because even if all give correct results, we must select the best one based on certain criteria.

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

What is algorithm efficiency, and what resources are typically considered?

A

Algorithms efficiency refers to the resource usuage of an algorithm. The primary resources considered are:

  • Time (runtime)
  • Space (computer memory)
  • Network Usuage
  • Hardware Requirements

Efficiency often involves trade-ffs between the resources

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

How do we measure the run-time of an algorithm?

A

Run-time is measured through:

  • Benchmarking on a representative set of inputs
  • Analysing the algorithm’s time complexity to understand its performance across different input sizes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the empirical analysis in algorithm efficiency, give an example.

A

The idea is that it implement the algorithm (a program) and time it.

Example way we can time the program:

Manual: Using a stopwatch
Auto: Using some timer function

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

What is time complexity, and how is it defined?

A

Time complexity refers to the number of operations an algorithm requires to execute, expressed as a function T(n), where n is the size of the input or problem.

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

What is the use of pseudocode?

A

Use pseudocode to remain independent of programming language and hardware.

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

What 3 key questions arise when analysing time complexity?

A
  1. What do we mean by operations? Basic computational steps like comparisons, assignments etc.
  2. What do we mean by size? The size of the input
  3. Which case do we analyse? Usually on worst-case scenario for robustness.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Examples of algorithms

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

Quadratic growth

A

F(n) = n^2
G(n) = n^2 -3n+2

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

Big-O Notation

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

What are some of common complexity classes of the Big-O notation?

A

◼O(1) = “Constant”
◼O(log2 n) = “Logarithmic”
◼O(n) = “Linear”
◼O(n log2 n) = “Log Linear”
◼O(n^2) = “Quadratic”
◼O(n^3) = “Cubic”
◼O(2^n) = “Exponential”

  • Polynomial: O(n), O(n^2), O(n^3), … – “tractable”
  • Exponential: O(n), O(n^2), O(n^3), … – “tractable”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How many operations needed for an algorithm?

A

With complexity T(n) = f(n) and input size n

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

How much time need for an algorithm?

A

Assuming 1 million operations per second

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

How do we determine the total complexities of an algorithm?

A

To determine the total algorithm complexity, consider the complexities of its components:

  1. Sequential algorithm phases: add the complexities of each phase
  2. Function/Method calls: Include the complexity of each function or method within the algorithm.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are two main components to consider in total algorithm complexity?

A
  1. Sequential algorithm: Complexity accumulates as phases are executed one after another
  2. Function/method calls: Each call adds its own complexity,which must be accounted for
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is an example of sequential algorithm phases?

A

Matrix-vector multiplication: x=A b

Complexity: O(n) + O(n^2) = O(n^2)
- It presents the maximum of complexities

18
Q

What is an example of function/method calls?

A

N array look-ups

Complexity: O(n) x O(long) = O(n log n)
- It represents the multiplication of complexities

20
Q

What are some criteria for selecting the best algorithm?

A

Efficiency, simplicity, clarity, elegance, and proofs of correctness.

21
Q

What key questions should we ask when analyzing an algorithm?

A

Is my algorithm correct? Does it always terminate?

22
Q

What fundamental question might we need to ask before designing an algorithm?

A

Does an algorithm even existence for that problem?

23
Q

What is meant by algorithm efficiency?

A

It refers to the resource usage of an algorithm, typically time (runtime) and space (memory).

24
Q

Besides time and space, what other resources might an algorithm use?

A

Network usage, hardware requirements, and more.

25
What should be considered when dealing with different resource usages?
Trade-offs between resources.
26
How do we measure the run-time of an algorithm?
By benchmarking on a representative set of inputs and analysing the time complexity
27
What is the idea behind empirical analysis of algorithm efficiency?
Implement the algorithm, run it, and time how long it takes for various input sizes.
28
How can we time a program during empirical analysis?
Manually using a stopwatch or automatically using a time function
29
What is time complexity in algorithms?
It is the number of operations an algorithm requires to execute, expressed in terms of the input size.
30
Why is time complexity based on the algorithm and not its implementation?
Because it is described using pseudocode, independent of programming languages or computer architectures.
31
How is time complexity usually expressed?
As a function T(n), where n is the size of the input.
32
In time complexity analysis, which case do we usually focus on?
The worst-case scenario
33
Why don't we usually need the exact time complexity T(n)?
Because it suffices to know the complexity class, focusing on large n and ignoring constants and lower-order terms.
34
What does Big-O notation represent?
It describes the asymptotic performance of an algorithm, focusing on how it scales with input size.
35
Give an example of a complexity class using Big-O notation.
If T(n)=n, then the complexity class is O(n).
36
What is the complexity class for T(n) = 2n^2?
It is O(n^2)
37
How do we compute the total complexity of sequential algorithm phases?
By taking the maximum complexity among the phases.
38
What is the result of combining O(n)+O(n^2)?
O(n^2)
39
How do we compute complexity when algorithms involve function or method calls?
By multiplying the complexities.
40
What is the result of multiplying O(n) x O(log n)?
O( n log n)