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
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
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