Programming
Questions And
Answers.
, AMCAT Automata Programming Questions And
Answers
1) I have a problem to solve which takes as input a number n. The problem has a
property that given the solution for (n-1), I can easily solve the problem for n. Which
programming technique will I use to solve such a problem?
a) Iteration
b) Decision-making
c) Object Oriented Programming
d) Recursion
Ans: d
Recursion means calling again and again. Therefore problem n can be solved with the
solution n-1, by repeatedly calling it.
2) The memory space needed by an algorithm has a fixed part independent of the
problem instance solved and a variable part which changes according to the problem
instance solved. In general, which of these two is of prime concern to an algorithm
designer?
a) Fixed part
b) Variable Part
c) Product of fixed part and variable part
d) None of these
Ans: b
, AMCAT Automata Programming Questions And
Answers
Variable part, since it changes according to the problem instance solved.
3) Pankaj and Mythili were both asked to write the code to evaluate the following
expression:
a – b + c/(a-b) + (a-b)^2
Pankaj writes the following code statements (Code A):
print (a-b) + c/(a-b) + (a-b)*(a-b)
Mythili writes the following code statements (Code B):
d = (a-b)
print d + c/d + d*d
If the time taken to load a value in a variable, for addition, multiplication or division
between two operands is same, which of the following is true?
a) Code A uses lesser memory and is slower than Code B
b) Code A uses lesser memory and is faster than Code B
c) Code A uses more memory and is faster than Code B
d) Code A uses more memory and is slower than Code B
Ans: a