2.3.1 - Algorithms (Big-O) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the purpose of Big-O

A
  • Used to measure the efficiency/complexity of an algorithm.
  • Can be used to measure the speed and/or memory requirements of an algorithm.
  • N represents the number of items/elements.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name and describe the complexity shown below

A

Logarithmic Complexity

Describes an algorithm whose growth rate decreases as the size of the data set increases, following a logarithmic curve. Scales well.

Example: Good for large data sets. A binary search where searching 200 values will just need one more iteration than if the data set only contained 100 values.

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

Name and describe the complexity shown below

A

Linear Complexity
Describes an algorithm where the execution time grows in direct proportion to the size of the data set it is processing

Example: Algorithms, which are based on a single loop to iterate through each value of the data set (Linear Search)

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

Name and describe the complexity shown below

A

Exponential Complexity

Describes an algorithm whose growth doubles with each addition to the data set. One item might take 1 second, two items would take two seconds, three items 4 seconds, and so on…

Example: Intractable Problems i.e. Travelling Salesperson

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

Name and describe the complexity shown below

A

Constant Complexity

Describes an algorithm that will always execute in the same execution time regardless of the size of the data set

Example: Returning the first item in an array, this remains the same regardless of the size of the array.

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

Name and describe the complexity shown below

A

Polynomial Complexity

Include quadratic algorithms O(N2), cubic algorithms O(N3) and so on… proportional to the polynomial of n

Example: Algorithms which are based onnested loopsare more likely to have a quadratic O(N2), or cubic O(N3) depending on the level of nesting used.

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

What are the possibles cases for the execution time of an algorithm.

A

The BEST CASE running time of an algorithm is the function defined by the minimum number of steps taken on any instance of size n.

The WORST CASE running time of an algorithm is the function defined by the maximum number of steps taken on any instance of size n.

The AVERAGE CASE running time of an algorithm is the function defined by an average number of steps taken on any instance of size n.

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

Give an example of the best and worst case for a bubble sort.

A

Best Case - The array is order in order, so just requires one pass through.

Worst Case - The array is in the total opposite order to the one required

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

What is the order of the complexities ranked from best to worst

A

BEST
Constant
Logarithmic
Linear
Polynomial
Exponential
WORST

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

Which algorithm/s has the following Big-O profile?

A

Linear Search

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

Which algorithm/s has the following Big-O profile?

A

Merge Sort

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

Which algorithm/s has the following Big-O profile?

A

Bubble and Insertion Sort

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

Which algorithm/s has the following Big-O profile?

A

Quick Sort

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

Which algorithm/s has the following Big-O profile?

A

Binary Search

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