inst/snippet/search-expval.R

# expected value of binary search
vals <- 1:8
probs <- 2^(vals-1) / 255
sum(vals*probs)

# expected value of linear search
vals <- 1:255
probs <- rep(1/255,255)
sum(vals*probs)

Try the fastR package in your browser

Any scripts or data that you put into this service are public.

fastR documentation built on May 2, 2019, 5:53 p.m.