Successful Search
we assume that the probability of searching or finding an element at each location is same , then if we have n elements so probability is $1/n$...
Also we might need to perform $1$ comparison or $2$ or $3$ or $4$ and so on ..
Therefore average time complexity is $=1.1/n+2.1/n+3.1/n.....n.1/n$
$=(n+1)/2$
I am not getting why are we not considering the case when the element is not found at the previous indexes after reaching the current index at which the element is found .
According to me it should be $1*1/n + (1-1/n)*(1/n) + (1-1/n)(1-1/n)*(1/n)$ ............(Considering the case when element if not found at 1st index , is found at 2nd index , then if not found at 2nd index is found at 3rd index and so on .
For unsuccessful search , I am not getting the method for calculating the average case using probability ?
Also do we make any assumption while calculating the time complexity for the array , is the order of elements defined in the array is fixed or it can vary ? Please explain precisely .