Determine the complexity of the expression
(I) 5n² + 3nlogn + 2n + 5 that log n <= n for n >= 1
(II) 5n⁴ + 3n³ + 2n² + 4n + 1
(I) As log n <= n, for n>=1, therefor nlog n <= n2, as far as n <= n2 and 1 <= n2 for n>=1.
So 5n² + 3nlogn + 2n + 5 <= 5n2 + 3n2 + 2n2 + 5n2 = 15n2 for n>=1.
Finally: complexity is O(n2)
(II) 1 <= n <= n2 <= n3 <= n4 for n >= 1. So 5n⁴ + 3n³ + 2n² + 4n + 1 <= 5n4 + 3n4 + 2n4 + 4n4 + n4 = 15n4 for n >= 1
Finally: complexity is O(n4)
Comments
Leave a comment