Consider a set of n elements whose key values are $$0, 1, ..., n−1.$$ Let $p(i) (0 ≤ i ≤ n−1) $ be the probability that the element with key i is searched. Assume the following distribution of $p(i)’s$:
$$p(i) = \begin{cases} 1/2^{n−1}, & \text{if i = 0} \\ 1/2^i, & \text{otherwise} \end{cases}$$
Assume linear search is used and every search is successful - every element we look for exists.
What is the average number of nodes inspected for a search under random(elements in the linked list are stored in a random order) organisation and what is the average number of nodes if sorted based on their decreasing probability(i.e., it starts with the element ‘1’, followed by element ‘2’, then ‘3’, and so on, with the last node containing element ‘0’.) for large values of n?
I know the answer for the first part is surely not $n/2$(since the probability is not the same for all of the elements) but I do not really know much more than that... but when sorted, I suspect it should be something close to $$\sum_{i=1}^{n-1} i*{1/2^{i}} + n * 1/2^{n-1}$$ because it takes one comparison to get to first element, two to the second, etc. and the last one takes n comparisons times the probability of 0. I also found the $$\sum_{i=o}^{∞} a*b^a = b/(1-b)^2$$ which in this case would be equal to 2 (b = 1/2) but I have no clue how to tackle the edge case - '0'. :(
I am also aware of this thread but there each of the numbers had the same probability and it is not exactly the same.
I hope to find an answer to this as it has been bothering me for quite a while and I am truly curious about the result.
Any hint will be greatly appreciated!