+ 7

# How to make an algorithm more efficient ? And what is more efficient operations on arrays or vectors ?

I have problem with time limits ... How to make faster as fast is now not a choice ;

1 Réponse

+ 3

I think it depends on your operation(s)... Vectors are better for frequent insertion and deletion whereas Arrays are much better suited for frequent access of elements scenario. Vectors occupy much more memory in exchange for the ability to manage storage and grow dynamically whereas Arrays are memory-efficient data structures. The Big O notation defines an upper bound of an algorithm, it bounds a function only from above. For example, consider the case of Insertion Sort. It takes linear time in the best case and quadratic time in the worst case. We can safely say that the time complexity of the Insertion sort is O(n^2). So it is difficult to say with certainty every single time which is more efficient, especially in algorithm optimization, its best to choose the right tool for the job.