# Big O for sequential algoritms

• Sep 15th 2010, 04:05 AM
avantimedev
Big O for sequential algoritms
If an algoritm consists of for instance two sequential calculations with a given time complexity as below, what is the total complexity for the algo?

ALGO:
calculate_one() // O(n)
calculate_two() // O(n)

Time complexity for each is O(n), is it true that the total time complexity is O(n+n) = O(n) in worst case?
• Sep 15th 2010, 05:47 AM
CaptainBlack
Quote:

Originally Posted by avantimedev
If an algoritm consists of for instance two sequential calculations with a given time complexity as below, what is the total complexity for the algo?

ALGO:
calculate_one() // O(n)
calculate_two() // O(n)

Time complexity for each is O(n), is it true that the total time complexity is O(n+n) = O(n) in worst case?

The complexity is O(n) for whatever case conditions appy to the sub-calculations, if one is worst case then its worst case, if both are average case then its average case etc

CB
• Sep 15th 2010, 05:52 AM
Traveller
Yes. It follows from the definition of the big O notation.