Humam Helfawi - 7 months ago 75

C++ Question

What is the most efficient and standard (C++11/14) way to find the max/min item of vector of vectors?

`std::vector<std::vector<double>> some_values{{5,0,8},{3,1,9}};`

the wanted max element is

the wanted min element is

Answer

Any efficient way to calculate the maximum element in a 2-D array(or vector in your case) involves a complexity of `O(n^2)`

irrespective of what you do, as the calculation involves a comparison between `n*n`

elements.Best way in terms of ease of use is to use `std::max_element`

on the vector of vectors.I will not delve into details.Here is the reference.

Source (Stackoverflow)