Pregunta

The time needed to find one match in sequential search is T(n)=n How about finding all matching for the key in a given array and all the element in the array are unique ?? T(n)=?

¿Fue útil?

Solución

The uniqueness constraint doesn't change the time taken, as if the element is only at the end, you're still going to have to look at every element to find it.

Finding multiple matches also doesn't change the time taken, as only going through the array once can find you all elements.

So the time taken will still be T(n) = n, or O(n).

Though I'm not really sure how there can be multiple matches and uniqueness - if the elements are unique, there can only be one match.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top