The efficiency of an algorithm is 5n2. If each step takes 1 nanosecond (10−9 seconds), how long will the algorithm take to process an input of size 1000?
The efficiency of an algorithm is 5n2. If each step takes 1 nanosecond (10−9 seconds), how long will the algorithm take to process an input of size 1000?
Ans. For n = 1000:
5 × (1000)2 × 10−9 = 5 × 10−3 seconds = 5 milliseconds
💡 Explanation:
First, substitute n = 1000 into the efficiency expression:
5n2 = 5 × (1000)2 = 5 × 1,000,000 = 5,000,000 steps
Since each step takes 1 nanosecond = 10−9 seconds, the total execution time is:
5,000,000 × 10−9 seconds = 5 × 10−3 seconds
Since 10−3 seconds = 1 millisecond, the algorithm takes 5 milliseconds.