[ ... ]
Because multiplication is entirely relevant to a discussion about
direct access.
No, it's really not. In particular, if scaling via multiplication needs
to be done, it'll be the same for a vector as for an array. As such,
multiplication really isn't worth discussing under the circumstances.
[ ... ]
A less condescending tone.
Then quit acting in a way that demands it.
I know O(c)=O(1), but I thought some people here did not, sorry my
mistake.
This seems (to me) a direct contradiction of your earlier statements.
[ ... ]
Amortized O(1) is not the same as non amortized O(1).
This much is true.
Amortized means
you divide by n, lol, that is commonly known as cheating.
No, it is known as averaging. Cheating implies breaking some kind of
rules -- and this doesn't do anything of the sort. Your claim that it's
cheating implies that you have the authority to make all the rules, and
anything you don't like is cheating. That's simply not the case. In
computer science (as with math in the more general sense) the rules are
simply a set of precepts. In a mathematical proof, they're stated as
axioms -- and it's generally agreed that they're unprovable. The
accuracy of a proof depends only on whether the axioms can be combined
in a way that leads inexorably to the final conclusion.
Depending on the axioms you start from, you get different kinds of math.
For example, the greeks agreed on one set of axioms that defined what is
now known as plane geometry. Since then, other sets of axioms have been
devised that have led to different types of geometry -- but neither set
is right or wrong. They're merely used to describe different systems.
The real question here is whether a mathematical system that includes
amortized constant time is sufficiently close to what you work with in
the real world that it is interesting or not. Many of us have found that
given the size of memory in current computers (among other things) that
it is a useful measurement. It might not be particularly applicable to
other circumstances -- but "inapplicable" is hardly synonymous with
"cheating."
[ ... ]
Don't be pedantic, "copying elements" then, how was I to know the
process used by std::vector.
You started by asking about a replacement for a fixed-size array. For
that situation, the time taken to resize a vector is totally, entirely,
100% irrelevant -- a fixed-size array can't be resized, and when used as
a direct replacement for a fixed-size array, the vector obviously won't
be resized either.
Under these circumstances, no copying of elements in the vector is ever
necessasry. On the theoretical side, there is NO difference in
computational complexity between accessing an element in a vector versus
accessing an element in an array. On the practical side, there seems to
be no difference in measured speed between accessing elements in a
vector versus an array.
You originally claimed that you could not replace a fixed-size array
with a vector because the computational complexity in accessing an
element in an vector was unavoidably higher than the computatinoal
complexity of accessing an element in an array. You can try to avoid it
and obfuscate it all you want, but the simple fact is that you were dead
wrong. Under the circumstances you described, the two operate with
identical computational complexity. period. full stop. Whatever
expression you prefer.
From a practical viewpoint, it's possible for there to be a minute
difference in speed. On most machines, this is likely to be immeasurably
small, if it exists at all. The place you'd be most likely to see it
would be an _extremely_ small machine in which the main memory is
roughly the same speed as the CPU itself (e.g. an embedded CPU using
only static RAM). IME, such a machine is unlikely to be a suitable
target for C++ in any case.
All such operations ARE >O(1), usually at least O(log n) or O(n) and
that is the "real macoy" big oh and not the "cheaters" amortised one.
In this case copying elements is O(n).
I've already addressed this. You're not in a position to set by fiat the
rules by which all must live, or anything on that order. In any case,
when you're using an vector as a replacement for a fixed-size array,
this all entirely irrelevant in any case.
[ ... ]
I do have a good understanding of big oh.
Not to put too fine a point on it, the posts I've seen you make thus far
do not make this claim particularly believable.
[ ... ]
Thanks for the code, although I get compilation errors with mine.
Please post the exact errors you're receiving, and identify the compiler
you're using. If you can't get that to compile, I'm reasonably certain
there's a fairly serious problem either with your compiler, or with how
you're using it.