Week 2: Complexity Analysis Flashcards

1
Q

What is Complexity Analysis?

A

The time required for an algorithm to execute until completion.

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

What is a search problem?

A

In a standard search problem, we have the inputs: A sequence of numbers a1, a2, …, an A number to search, q

And the expected outputs: The index in a in which exists q, or NIL if q is not present. ​

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

What is a Linear search?

A

A linear search checks each element in the sequence sequentially.

This gives a worst case performance of O(n) if q = an or if q is not present in the sequence.

This gives an average case performance of n/2. A sorted sequence doesn’t affect the performance.

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

What is a Binary search?

A

For a binary search, the sequence, a,  must be sorted. This gives a worst case performance of log2(n). If n is 10 for example, a maximum of 4 array members will need to be checked log2(10)= 3.3~.

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

How is an algorithm executed using a computational model?

A

Usually, a generic uniprocessor random-access machine (RAM) is used.

All memory is equally expensive to access.

All instructions are executed one after another, no concurrency.

All reasonable instructions take 1 unit time.

Function calls do not use one unit.

Constant word size.

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

How are the results a function of Input Size?

A

Sorting: number of input items

Multiplication: number of involved bits

Graph Algorithms: Number of nodes and edges in graph

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

Worst and Average Case

A

Worst case: Provides an upper bound on running time. A guarantee running time will never be worse than this.

Average case: Provides the expected running time Usually very useful. Care needs to be taken to define what ‘average’ means. It could mean the average input taken from the real world (a median or mode). It could mean the average running time taken from random equally likely inputs.

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

What is Insertion sort?

A
  1. Work left to right.
  2. Examine each item and compare it to the items on its left.
  3. Insert the item in the correct position on the array.

Worst time complexity is O(n2) if the sequence is sorted decreasing then there will be n number of comparisons and n number of swaps.

Code: InsertionSort(A, n) {for i = 2 to n{ key = A[i] j = i - 1 while (j > 0) and (A[j] > key) { A[j+1] = A[j] j = j - 1 } } }

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

Big-O bound notation?

A

Big-O notation defines the upper bound for the time complexity of an algorithm.

f(n) is O(g(n)) if there exists positive constants c and n0 such that f(n) ≤ c • g(n) for all n ≥ n0.

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

Big-Ω bound notation?

A

Big-Ω defines the lower bound for the time complexity of an algorithm.

f(n) is Ω(g(n)) if there exists positive constants c and n0 such that 0 ≤ c • g(n) ≤ f(n) for all n ≥ n0

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

Big-Θ bound notation?

A

Big-Θ defines the asymptotic tight bound for the time complexity of an algorithm. f(n) is Θ(g(n)) if there exists positive constants c1, c2 and n0 such that c2 • g(n) for all n ≥ n0

If a program by Θ(g(n)) then it is both O(g(n)) and Ω(g(n))

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

Other notation?

A

o(g(n)) is like < g(n)

O(g(n)) is like ≤ g(n)

ω(g(n)) is like > g(n)

Ω(g(n)) is like ≥ g(n)

Θ(g(n)) is like = g(n)

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