Lecture Notes for SE 598, Data Structures and Algorithms
14 June 2000, Implementing Vectors
- operations and behavior
- create - create a vector
- delete - delete a vector
- read - place a value in a vector
- write - retrieve a value from a vector
- grow - add a new element to the end of the vector
- shrink - delete an element from the end of the vector
- size - return the number of elements in a vector
- design
- what data structures are best for implementing vectors?
- how can the operations best be implemented?
- these questions are related
- examples
- use an array
- creating is fast, deleting is interesting
- reading and writing are fast and easy
- grow is simple but slow, shrink is easy
- size is easy
- use a linked list
- creating is fast, deleting is slow
- reading and writing are slow and not so easy
- grow and shrink are easy and either fast or slow
- size is easy
- a trick - combine complimentary implementations
- use a linked list with an array index
- creating is fast, deleting is slow
- reading and writing are fast and easy
- grow is simple but slow, shrink is easy
- size is easy
- don't forget the exotics
- functional array implementation - an array is a function mapping
integers to array elements
- what will you do
- the kiss principle - keep is simple, stupid
- quickest to results
- reasonable chance of first-order success - performance issues may
be week, for example
- a working implementation gives you the most valuable data you can
have
- but: make sure your implementation is well hidden so changes can
be kept local
- use arrays
- implementation
- create - not an array
- delete - usually messy and implementation dependent
- read - simple
- write - simple
- grow - either there's room or there isn't
- shrink - error conditions
- size - simple
This page last modified on 12 June 2000.