1.

Which of the following methods used to find the sum of first n natural numbers has the least time complexity?(a) Recursion(b) Iteration(c) Binomial coefficient(d) All have equal time complexityThe question was asked by my school principal while I was bunking the class.Asked question is from Sum of n Natural Numbers using Recursion topic in chapter Recursion of Data Structures & Algorithms II

Answer»

The correct answer is (C) BINOMIAL coefficient

For explanation: Recursion and iteration take O(n) time to find the sum of FIRST n NATURAL numbers while binomial coefficient takes O(1) time.



Discussion

No Comment Found

Related InterviewSolutions