Given two runtime for algorithm A and algorithms B for solvi

Given two runtime for algorithm A and algorithms B, for solving the same problem. If the runtime for: algorithm A and B are given as below: T_A(N) - O(N lg N) and T_B(N) = O(N^2). Which algorithm will you prefer and why?

Solution

So if we have 2 algorithms having Runtime

TA(N)=O(NlogN)

TB(N)=O(N2)

So we will prefer the first Algorithm that is Algorithm \'A\', because in Algorithm A, for all very lage Values of N,the Value of NlogN has a very small value as compared to N2.

As NlogN is Smaller in Value as Compared to N2, so NlogN will take Smaller time as Compared to N2

So,Algorithm having runtime O(NlogN) will take less time as compared to the algorithm having runtime O(N2).

Thank You for using Chegg...

 Given two runtime for algorithm A and algorithms B, for solving the same problem. If the runtime for: algorithm A and B are given as below: T_A(N) - O(N lg N)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site