CS 70

Θ Abstracts Away the Choice of n (Mostly)

  • Duck speaking

    Remember for \( \mathrm{C}_{\mathrm{index}} \) we used the number of input bits for \( n \) and for other ones we used the size of the array?

  • LHS Cow speaking

    Yeah, sure. What about it?

  • Duck speaking

    Well, which one should we use?

  • LHS Cow speaking

    Great question! Asymptotically… it doesn't matter!

We decided that \( \mathrm{C}_{\mathrm{index}}(n) = \frac{ n - 128 }{ 32 } \), where \( n \) is the number of bits in the array and all three parameters.

Is \( \frac{ n - 128 }{ 32 } \in \Theta(n) \)?

Sure it is:

\[ \begin{align} \lim_{n \to \infty} \frac{ ( \frac{ n - 128 }{ 32 } ) }{ n } & = \lim_{n \to \infty} \frac{ n - 128 }{ 32n } \\ & = \frac{1}{32}. \end{align} \]

We could likewise say that \( \mathrm{C}_{\mathrm{index}}(n) = n \), where \( n \) is the number of elements in the array. And hopefully we agree that \( n \in \Theta(n) \).

So they're both \( \Theta(n) \).

  • Duck speaking

    Ah, so either way, we can see that it takes linear time!

  • LHS Cow speaking

    That's right!

  • Dog speaking

    Does that mean we can choose any quantity for \( n \)?

  • LHS Cow speaking

    No, definitely not.

A Rule of Thumb for \( n \)

The most typical notion of what \( n \) should be is the description length of the input. The description length is the number of bits needed to write down the input to the algorithm.

  • Duck speaking

    We were basically doing that when we used the number of bits in the array and the three parameters!

  • LHS Cow speaking

    That's right!

  • Duck speaking

    So, why is it okay to use the number of array elements instead?

  • LHS Cow speaking

    Well, remember that constant factors and lower-order terms don't matter in the limit…

In this case, the number of bits for the parameters is the same for every input (128), so that's a lower-order term.

The number of bits in the array is a multiple (32) of the number of elements in the array. So the number of bits per element is a constant factor.

Since \( n \in \Theta( 32n + 128 ) \), the number of elements in the array is the same order as the description length of the input.

As a result, for the purposes of asymptotic analysis, the number of array elements is just as good a choice as the description length!

  • RHS Cow speaking

    Where things can go wrong is if you start interpreting \( n \) to be a quantity that is not of the same order as the description length.

  • LHS Cow speaking

    For instance, if we had gotten confused and let \( n \) be the number of bits in the parameters without the array, then our analysis would have been very strange.

  • RHS Cow speaking

    But still, when we say \( \Theta(n) \), we don't necessarily have to be super specific about what \( n \) is. It is presumed to be something on the order of the description length of the input.

  • LHS Cow speaking

    All that said, when we ask you to do analyses, we will often specify, just to be sure we are all on the same page!

(When logged in, completion status appears here.)