28
The position of an element is called its
index.
So instead of saying, “20 is
at
position
1,” the correct terminology is, “20 is at
index
1.” I’ll use
index
to mean
position
throughout this book.
Here are the run times for common operations on arrays and lists.
Question: Why does it take O(
n
) time to insert an element into an
array? Suppose you wanted to insert an element at the beginning of an
array. How would you do it? How long would it take? Find the answers
to these questions in the next section!
Dostları ilə paylaş: