Skip to main content
added 36 characters in body
Source Link
D.W.
  • 165.6k
  • 21
  • 230
  • 490

It's neither ${(n^2+3n)}/{(2n+2)}$ nor $n/2$. In fact, the question itself doesn't make much sense at all. In order to be able to talk about the average running time of an algorithm, you have to fix a probability distribution for the input. As an example, it is well known that the average running time of naive quicksort is $\Theta(n \log n)$, but that result is dependent on assuming that the input arrays are uniformly distributed over the elements of the symmetric group of size $n$. If we choose different distributions, the result changes reflecting our choice.

Therefore, it is impossible to give a reasonable answer to your question without making assumptions of statistical nature on what queries you expect. In particular, the average number of comparisons is deeply impacted by what is the ratio of the inputs for which the search fails to find a matching element.

Intuitively, if the input distribution is such that you expect to miss almost every time, your average number of comparisons will be very close to $n$.

It's neither ${(n^2+3n)}/{(2n+2)}$ nor $n/2$. In fact, the question itself doesn't make much sense at all. In order to be able to talk about the average running time of an algorithm, you have to fix a probability distribution for the input. As an example, it is well known that the average running time of naive quicksort is $\Theta(n \log n)$, but that result is dependent on assuming that the input arrays are uniformly distributed over the elements of the symmetric group of size $n$. If we choose different distributions, the result changes reflecting our choice.

Therefore, it is impossible to give a reasonable answer to your question without making assumptions of statistical nature on what queries you expect. In particular, the average number of comparisons is deeply impacted by what is the ratio of the inputs for which the search fails to find a matching element.

Intuitively, if you expect to miss almost every time, your average number of comparisons will be very close to $n$.

It's neither ${(n^2+3n)}/{(2n+2)}$ nor $n/2$. In fact, the question itself doesn't make much sense at all. In order to be able to talk about the average running time of an algorithm, you have to fix a probability distribution for the input. As an example, it is well known that the average running time of naive quicksort is $\Theta(n \log n)$, but that result is dependent on assuming that the input arrays are uniformly distributed over the elements of the symmetric group of size $n$. If we choose different distributions, the result changes reflecting our choice.

Therefore, it is impossible to give a reasonable answer to your question without making assumptions of statistical nature on what queries you expect. In particular, the average number of comparisons is deeply impacted by what is the ratio of the inputs for which the search fails to find a matching element.

Intuitively, if the input distribution is such that you expect to miss almost every time, your average number of comparisons will be very close to $n$.

Source Link
quicksort
  • 4.3k
  • 1
  • 10
  • 21

It's neither ${(n^2+3n)}/{(2n+2)}$ nor $n/2$. In fact, the question itself doesn't make much sense at all. In order to be able to talk about the average running time of an algorithm, you have to fix a probability distribution for the input. As an example, it is well known that the average running time of naive quicksort is $\Theta(n \log n)$, but that result is dependent on assuming that the input arrays are uniformly distributed over the elements of the symmetric group of size $n$. If we choose different distributions, the result changes reflecting our choice.

Therefore, it is impossible to give a reasonable answer to your question without making assumptions of statistical nature on what queries you expect. In particular, the average number of comparisons is deeply impacted by what is the ratio of the inputs for which the search fails to find a matching element.

Intuitively, if you expect to miss almost every time, your average number of comparisons will be very close to $n$.