[   ^ to index...   |   <-- previous   ]

Lists vs. vectors

Lists and vectors both implement the idea of "a contiguous ordered sequence of elements". What are the tradeoffs between

for the following operations? Draw diagrams if you cannot easily figure out the costs.

Indexing

How expensive is it to find a the nth element of a linked list? A vector? Given an element e, how expensive is it to find an element in a list whose value is equal to e?

Insertion and deletion

How expensive, in terms of time, is it to insert an element near the end of a vector? Near the beginning?

What about for a linked list (end/beginning)? What if you have a pointer to the node where you want to insert the element?

What is the cost to delete an element from a vector, on average? What about from a linked list?

Space efficiency

What is the space efficiency of a vector vs. a linked list?

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Last modified: Wed Jul 12 18:21:03 PDT 2000