Home Ask Login Register

Developers Planet

Your answer is one click away!

Mehno February 2016

What is more expensive? Reading or comparing integers, doubles

I asked myself, which Big O Notation C++ min has.

I want the minima from a Set of integers.

I saw in stackoverflow a similar question.

The answer was O(n), because you have to read n numbers.

But this is only correct, if reading is the critical operation.

My question is: What is more expensive? (in cpu clocks or whatever) Reading or comparing?


Jim Buck February 2016

It depends on the platform, but almost surely reading values from memory is more expensive than the operations on the CPU. But, on the topic of big o notation - it's not about which operation is more expensive. It's about the fact that the algorithm scales with the number of inputs (i.e. n).

Post Status

Asked in February 2016
Viewed 2,264 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life