Friday, August 2, 2013

When to use Map Data Structure Over Vector

1) When an element is deleted from vector, all the elements below it have to be moved up.
When and element is inserted to vector, all the elements below it have to be moved down.

If you ave many add's and deleted in a program in a sequential list. It might be advantageous to cobnsider map. Map finds the element in logN time

2) When you ave sorted but you might not have all the elemnets in sequence.

e.g., you have edges of vertices 1,2,5,10 etc., it is better to store them in map.

Storing them in vector, you have store edges of 3,4,67,8,9 as empty.

No comments:

Post a Comment