Two technical times in one sentence

Which of these sentences should I use?

Algorithms 1 and 2 work in time O(n) and O(n^2) respectively.

Or

Algorithms 1 and 2 work in times O(n) and O(n^2) respectively.


Solution 1:

"Algorithms 1 and 2 work in times O(n) and O(n^2) respectively." is correct.

The two algorithms (pl) work in the two times. The sequence of the times correlates to the sequence of the algorithms, i.e. it is respective.

You can omit "respectively" in such a short sentence, or say "Algorithm 1 works in time O(n), and algorithm 2 works in time O(n^2)." to be very clear.

Cheers

Solution 2:

I don't think "rules of grammar" are concerned with such fine points - both singular and plural are used in OP's context, so it's really just a matter of stylistic preference. But OP's specific word "time" is just one of many - the same construction arises in, for example...

Smith and Jones won first and second prize, with pumpkins of weight[s] 24kg and 18kg respectively.

...where again, either form works. But with some slight changes, only plural works...

Smith and Jones were the richest, with fortunes of £86M and £71M respectively.

Smith and Jones were the most generous, making donations of £86K and £71K respectively.

If you parse time/weight/etc. as a noun modified by the two numeric values following, you naturally pluralise it. But if you parse the numbers themselves as the relevant "nouns", the preceding term becomes a modifying "adjective" - a singular attribute applicable to both values.

Without doing any research into actual usage I suspect that the plural is more common, if only because it works better in a broad range of closely-related constructions.