3 | Elementary operations / Asymptotics I Flashcards

1
Q

Definition:
Problem vs. instance

A

Problem: a specification of desired input-output relationship.

Instance: (of a problem) all inputs needed to compute solution to problem.

  • A problem specifies its domain of definition
    i.e., the set of instances to be considered.
  • Many interesting problems have infinitely many instances.
  • Some problems have a single instance (e.g. sink/source)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to show that an algorithm is incorrect?

A
  • find one instance for which algorithm does not find correct solution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a bit?

A

A bit (short for binary digit) is the smallest unit of data in a computer

A bit has a single binary value either 0 or 1

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

What is a byte?

A

8 bits = 1 byte
used for storing data and executing instructions

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

Steps to convert decimal number to binary?

A

Divide the number by 2.
- The modulus (remainder) is the next digit of the new binary number (in reverse order).
- The floor is carried over for the next iteration

Repeat until the floor is zero

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

size of bits needed for n = size(n)

Formula?

A

size(𝑛) = ⌊log2(𝑛) + 1⌋ (= ⌊log2(𝑛)⌋ + 1 )

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

Proof of formula:

size(𝑛) = ⌊log2(𝑛) + 1⌋

A

see notes

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

Size of an instance: formal definition?

A

Formal definition
Size of an instance corresponds to the number of bits needed to represent the instance on a computer using a precisely defined coding scheme.

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

Size of an instance: less formal definition?

A

Less formal
Size stands for any integer than measures the number of components of an instance.

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

Size of an instance:

examples?

A

Examples
In sorting, the size corresponds to the number of items.
(ignoring the fact that more than one bit may be needed to represent each integer)

In graphs, the size is the number of nodes, number of edges, or both

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

Advantages of the theoretical approach to determine efficiency

A

It does not depend on
- the computer being used
- the programming language employed
- the skills of the programmer

It allows to study the efficiency of an algorithm on instances on any size

Empirical approach – small vs. large instances

Expressing efficiency
storage – bit
time – seconds, minutes, etc. (no convention)

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

Algorithm efficiencey - Principle of invariance?

A

Two different implementations of the same algorithm will not differ in efficiency by more than some multiplicative constant.

The running time of either implementation is bounded by the running time of the other

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

Algorithm efficiencey - Principle of invariance?
formulas?

A

If 𝑡1(𝑛) and 𝑡2(𝑛) (seconds) are the running times of two implementations of an algorithm, then there exist two positive constants 𝑐 and 𝑑 for which

𝑡2(𝑛) /𝑑 ≤ 𝑡1(𝑛) ≤ 𝑐𝑡2(𝑛)

whenever 𝑛 is sufficiently large.

1/𝑑 = 𝑑′ ≤ 𝑡1(𝑛)/𝑡2(𝑛) ≤ 𝑐 (assuming 𝑡(𝑛) ≠ 0

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

1.
Principle of invariance remains true…

2
… what allows constant speed up?

3.
Only change in ____ allow us a marked speed up which reflects the change in the size of the instance

A

The principle remains true irrespective of
change of computer
change of programming language / compiler

Change in implementation detail may allow us a constant speed up

Only change in algorithm allow us a marked speed up which reflects the change in the size of the instance

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

An algorithm takes time in the order of …..

A

An algorithm takes a time in the order of 𝒕(𝒏) , if there
exists a positive constant 𝒄 and an implementation of the
algorithm capable of solving every instance of size 𝒏 in
not more than 𝒄𝒕(𝒏) seconds.

No unit for expressing theoretical efficiency!

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

Name 4 types of algorithms based on efficiency

A

Linear algorithms
𝑐𝑛
Quadratic algorithms
𝑐𝑛2
Polynomial algorithms
𝑐𝑛𝑘
Exponential algorithms
𝑐𝑛

16
Q

Issue with the multiplicative (hidden) constants in algorithm efficiency?

A

e.g. 𝑛2 days vs. 𝑛3 seconds for the same algorithm

when is 𝑛2 𝑑𝑎𝑦𝑠 < 𝑛3 𝑠𝑒𝑐𝑜𝑛𝑑𝑠?

asymptotically the first is better than the second, practically not

17
Q

Average case analysis - definition? Issues?

A

Average-case analysis: average over all possible instances

but are all instances equally likely?

requirement for an adequate distribution of instances

–> more difficult than worst-case analysis

18
Q

Insertion sort - principle?

A

For each element, from the second to the last, we find the appropriate place among its predecessors

19
Q

Insertion sort - pseudocode?

A

procedure insert(𝑇[1. . 𝑛])
~~~
for 𝑖 ← 2 to 𝑛 do
𝑥 ← 𝑇[𝑖]
𝑗 ← 𝑖 − 1
while 𝑗 > 0 and 𝑥 < 𝑇[𝑗] do
𝑇 [𝑗 + 1] ← 𝑇 𝑗
𝑗 ← 𝑗 − 1
𝑇[𝑗 + 1] ← 𝑥
~~~

20
Q

Selection sort – principle?

A

Find the smallest element in the array and bring it to the front;
continue applying the principle to the array from the second position.

21
Q

Selection sort - pseudocode?

A

procedure select(𝑇[1. . 𝑛])
~~~
for 𝑖 ←1 to 𝑛 − 1 do
𝑚𝑖𝑛𝑗 ← 𝑖
𝑚𝑖𝑛𝑥 ← 𝑇[𝑖]
for 𝑗 ← 𝑖 + 1 to 𝑛 do
if 𝑇[𝑗] < 𝑚𝑖𝑛𝑥 then
𝑚𝑖𝑛𝑗 ← 𝑗
𝑚𝑖𝑛𝑥 ← 𝑇[𝑗]
𝑇[𝑚𝑖𝑛𝑗] ← 𝑇[𝑖]
𝑇[𝑖] ← 𝑚𝑖𝑛𝑥
~~~

22
Q

Worst case complexity:

Insertion sort?

Selection sort?

A

O(n2)

23
Q

Linear algorithms

A

cn

24
Q

Polynomial algorithms

A

𝑐𝑛𝑘

25
Q

Exponential algorithms

A

𝑐n

26
Q

Quadratic algorithms

A

𝑐𝑛2

27
Q

Insertion sort complexities?

A

O(n2)
Θ(n2)
Ω(n)

28
Q

Selection sort complexities?

A

all n2

O(n2)
Θ(n2)
Ω(n2)

29
Q

best case symbol

A

Ω

30
Q

average case symbol

A

Θ