How to make an algorithm more efficient ? And what is more efficient operations on arrays or vectors ? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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 ;

19th Aug 2020, 9:14 PM
Peter Raafat
Peter Raafat - avatar
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.
19th Aug 2020, 9:45 PM
Steven M
Steven M - avatar