Depends on probabilistic outcomes we get expected bounds
Assumption: uniformly random input - randomization to avoid “bad” input sequences
Indicator random variable: if event occurs, otherwise
Sample space , event ,

Example

Compute expected number of heads in tosses of a fair coin
… indicator random variable that H appeared in toss
… number of heads in flips

Pseudo-random numbers

Hardware RNG
Pseudo RNG: initialized with seed get a large repeatable “random” number sequence

Linear congruential generators

; … period
; … maximum
Simbple but bad - if current number is small, then the next will also be small

BBS

; , … large prime numbers,
If you find the primes you can reverse engineer generation (only on quantum computers in polynomial time)





























Amortized analysis of computational complexity

Aggregated analysis

Aggregate all possible functions

Stack with multipop operation

operations of PUSH, POP - worst case per operation:
operations of PUSH, POP, MULTIPOP - worst case per operation:
operations of PUSH, then MULTIPOP(n-1) - worst case per operation:

Accounting method

Assessing worst-case upper bound for a series of operations
Amortized cost actual cost

  • found upper bound for amortized cost upper bound for actual cost

Stack with multipop operation

Each PUSH/POP costs 1 coin; if you put coins all push, all possible future pops are already paid for

| operation | actual cost | amortized cost |
| ---------- | --------- | --- |
| PUSH | | |
| POP | | |
| MULTIPOP | | |
operations of PUSH - worst case:
Worst case per operation:

Potential method

Data structure has a “potential” that pays for more expensive operation

  • after operation applied to
  • … amortized cost

Stack with multipop operation

… number of elements on the stack

  • … assume empty stack
  • … number of elements on the stack after operation

| operation | actual cost | | amortized cost |
| ---------- | --------- | --- | --- |
| PUSH | | | |
| POP | | | |
| MULTIPOP | | | |

Worst sequence of operations: \frac{2n}n=2=O(1)$