AMCAT Computer Science Questions with Answers - 3

AMCAT Computer Programming Previous Years Question answers with Solutions 1


Ques61. Pavithra is given two codes, A and B, to solve a problem, which have
complexity &theta(n3
) and &omega(n3
) respectively. Her client wants to solve a
problem of size k, which is sufficiently large. Which code should she deliver to the
client in the present scenario?
Op 1: Code A
Op 2: Code B
Op 3: Both codes have the same execution time, so deliver any.
Op 4: None of these
Op 5:
Correct Op : 1

Ques61. Code A has to execute 4*n2 + 64 program statements, while Code B has to
execute 32*n program statements for a problem of size n. The time for executing a
single program statement is same for all statements. Rajesh was given a problem
with a certain size k and he delivered Code A. What could be the possible value of k?
Op 1: 1000
Op 2: 5
Op 3: 10
Op 4: 3
Op 5:
Correct Op : 4

Ques63. Saumya writes a code which has a function which calls itself. Which
programming concept is Saumya using?
Op 1: This is bad programming practice and should not be done.
Op 2: Recursion
Op 3: Decision Making
Op 4: Overloading
Op 5:
Correct Op : 2

Ques64. Shrishti writes the code for a function that computes the factorial of the
inputted number n.
function factorial(n)
{
if(n equals 1)
return 1
else
-- MISSING STATEMENT --
end
}
Fill in the missing statement.
Op 1: return factorial(n-1)
Op 2: return n*factorial(n)
Op 3: return n*(n-1)
Op 4: return n*factorial(n-1)
Op 5:
Correct Op : 4

Ques65. Tanuj writes the code for a function that takes as input n and calculates the
sum of first n natural numbers.
Function sum( n )
{
if(??)
return 1
else
return (n + sum(n-1))
end
}
Fill in ?? in the code.
Op 1: n equals 1
Op 2: n equals 2
Op 3: n >= 1
Op 4: n > 1
Op 5:
Correct Op : 1

Ques66. Saloni writes the code for a function that takes as input n, an even integer and
calculates the sum of first n even natural numbers.
function sum( n )
{
if(n equals 2)
return 2
else
return (n + sum(n-2))
end
}
She then calls the function by the statement, sum(30). How many times will the
function sum be called to compute this sum.
Op 1: 1
Op 2: 30
Op 3: 15
Op 4: 16
Op 5:
Correct Op : 3

Ques67. Consider the following function
function calculate( n )
{
if(n equals 5)
return 5
else
return (n + calculate(n-5))
end
}
Shishir calls the function by the statement, calculate(20). What value will the
function return?
Op 1: 50
Op 2: 200
Op 3: 35
Op 4: 20
Op 5:
Correct Op : 1

Ques68. Ravi is writing a program in C++. C++ uses the 'for' keyword for loops. Due to
distraction, Ravi writes 'gor' instead of 'for'. What will this result to?
Op 1: The code will not compile.
Op 2: The code will give an error while in execution
Op 3: The code may work for some inputs and not for others.
Op 4: It will create no problems.
Op 5:
Correct Op : 1

Ques69. What does a compiler do?
Op 1: Converts code from a high level language to a low level language
Op 2: Necessarily converts the code into assembly language
Op 3: Converts code from a low level language to a high level language
Op 4: Necessarily converts the code into machine language
Op 5:
Correct Op : 1

Ques70. A program is compiled by Tarun on his machine. Whether it will run on a
different computer will depend upon:
Op 1: Operating system on the computer
Op 2: Hardware configuration of the computer
Op 3: Both operating system and hardware configuration
Op 4: The language of the program
Op 5:
Correct Op : 3

Ques71. Sakshi writes a code in a high-level programming language on a Pentium-III
machine, which she wants to execute on a Motorola chip. What of the following will
she run on the code?
Op 1: An interpreter
Op 2: A compiler
Op 3: A cross-compiler
Op 4: Linker
Op 5:
Correct Op : 3

Ques72. Shahaana has a 10,000 line code. She is trying to debug it. She knows there is a
logical error in the first 25 lines of the code. Which of the following will be an
efficient way of debugging:
Op 1: Compile the whole code and step into it line by line
Op 2: Use an interpreter on the first 25 lines.
Op 3: Compile the whole code and run it
Op 4: None of these
Op 5:
Correct Op : 2

Ques73. Farhan writes a code to find the factorial of an inputted number. His code
gives correct answer for some inputs and incorrect answers for others. What kind of
error does his program have?
Op 1: Syntactical error
Op 2: Run-time Error
Op 3: Logical Error
Op 4: None of these
Op 5:
Correct Op : 3

Ques74. Reshama is debugging a piece of code which takes several iterations of
modifying and executing code, while Mohammad has to deliver a product to the
customer, which the customer will run multiple times. Reshama wants her debug
cycle to take minimum possible time, while Mohammad wants that his products run
time is minimum. What tools should Reshama and Mohammad respectively use on
their code?
Op 1: Compiler, Interpreter
Op 2: Interpreter, Compiler
Op 3: Compiler, Compiler
Op 4: Interpreter, Interpreter
Op 5:
Correct Op : 2

Ques75. Gautam writes a program to run on a Motorola processor on his Pentium
computer. He wants to see how the program will execute on the Motorola processor
using his Pentium machine. What tool will he use?
Op 1: Compiler
Op 2: Interpreter
Op 3: Assembler
Op 4: Simulator
Op 5:
Correct Op : 4

Ques76. Consider the following code:
function modify(y,z)
{
y = y + 1;
z = z + 1;
return y - z
}
function calculate( )
{
integer a = 5, b = 10, c
c = modify(a, b);
print a
print space
print c
}
Assume that a and b were passed by value. What will be the output on executing
function calculate( )?
Op 1: 11 -5
Op 2: 10 -5
Op 3: 6 -5
Op 4: 5 -5
Op 5:
Correct Op : 4

Ques77. Consider the following code:
function modify(b,a)
{
return a - b
}
function calculate( )
{
integer a = 5, b = 12, c
c = modify(a, b);
print c
}
Assume that a and b were passed by reference. What will be the output of the
program on executing function calculate( ) ?
Op 1: 7
Op 2: -7
Op 3: Error
Op 4: 8
Op 5:
Correct Op : 1

Ques78. Consider the following code:
function modify(y,z)
{
y = y + 1
z = z + 1
return y - z
}
function calculate( )
{
integer a = 12, b = 20, c
c = modify(a, b);
print a
print space
print c
}
Assume that a and b were passed by reference. What will be the output of the
function calculate( ) ?
Op 1: 12 -8
Op 2: 13 -8
Op 3: 12 8
Op 4: 13 8
Op 5:
Correct Op : 2

Ques79. Afzal writes a piece of code, where a set of three lines occur around 10 times
in different parts of the program. What programming concept can he use to shorten
his program code length?
Op 1: Use for loops
Op 2: Use functions
Op 3: Use arrays
Op 4: Use classes
Op 5:
Correct Op : 2

Ques80. Geetika writes a piece of code, where a set of eight lines occur around 10
times in different parts of the program (Code A). She passes on the code to Deva.
Deva puts the set of eight lines in a function definition and calls them at the 10
points in the program (Code B). Which code will run faster using an interpreter?
Op 1: Code A
Op 2: Code B
Op 3: Code A and Code B will run with the same speed
Op 4: None of these
Op 5:
Correct Op : 1

Ques81. Consider the following code:
function modify(a,b)
{
integer c, d = 2
c = a*d + b
return c
}
function calculate( )
{
integer a = 5, b = 20, c
integer d = 10
c = modify(a, b);
c = c + d
print c
}
Assume that a and b were passed by value. What will be the output of the function
calculate( ) ?
Op 1: 80
Op 2: 40
Op 3: 32
Op 4: 72
Op 5:
Correct Op : 2

Ques82. Consider the following code:
function modify(w,u)
{
w = w + 2
u = u - 3
return (w - u)
}
function calculate( )
{
integer a = 10, b = 20, c
c = modify(a, b);
print a
print space
print b
}
Assume that a was passed by value and b was passed by reference. What will be the
output of the program on executing function calculate( ) ?
Op 1: 12 17
Op 2: 10 17
Op 3: 12 20
Op 4: 10 20
Op 5:
Correct Op : 2

Ques83. Consider the following function:
function run( )
{
integer a = 0 // Statement 1
while (a < 5)
{
integer c = 0 // Statement 2
c = c + 1 // Statement 3
a = a + 1
}
print c // Statement 4
}
At which statement in this program will the compiler detect an error?
Op 1: Statement 1
Op 2: Statement 2
Op 3: Statement 3
Op 4: Statement 4
Op 5:
Correct Op : 4

Ques85. Which one of the following is the lowest level format to which the computer
converts a higher language program before execution?
Op 1: English code
Op 2: Machine Code
Op 3: Assembly Language
Op 4: System Language
Op 5:
Correct Op : 2

Ques86. If you want to write a function that swaps the values of two variables, you
must pass them by:
Op 1: Value only
Op 2: Reference only
Op 3: Either A or B
Op 4: Neither A nor B
Op 5:
Correct Op : 2

Ques87. Consider the following code:
if (condition 1) {
if (condition 2)
{ // Statement A }
else
if (condition 3)
{ // Statement B }
else
{ // Statement C }
else
if (condition 4)
{ // Statement D }
else
{ // Statement E}
}
Which of the following conditions will allow execution of statement C?
Op 1: condition1 AND condition3
Op 2: condition1 AND condition4 AND !condition2
Op 3: NOT(condition2) AND NOT(condition3)
Op 4: condition1 AND NOT(condition2) AND NOT(condition3)
Op 5:
Correct Op : 4

Ques88. Consider the following code:
if (condition 1) {
if (condition 2)
{ // Statement A }
else
if (condition 3)
{ // Statement B}
else
{// Statement C }
else
if (condition 4)
{// Statement D}
else
{// Statement E}
}
Which of the following conditions will allow execution of statement E?
Op 1: condition1 AND condition3
Op 2: NOT(condition1) AND condition2 AND NOT(condition4)
Op 3: NOT(condition2) AND NOT(condition3)
Op 4: condition1 AND condition4 AND NOT(condition2) AND NOT(condition3)
Op 5:
Correct Op : 2

Ques89. Consider the following code:
if (condition 1) {
if (condition 2)
{ // Statement A }
else
if (condition 3)
{ // Statement B}
else
{// Statement C }
else
if (condition 4)
{// Statement D}
else
{// Statement E}
}
Which of the following condition will allow execution of statement A?
Op 1: NOT(condition2) AND NOT(condition3)
Op 2: condition1 AND condition4 AND NOT(condition2) AND NOT(condition3)
Op 3: condition1 AND condition2 AND condition4
Op 4: NOT(condition1) AND condition2 AND NOT(condition4)
Op 5:
Correct Op : 3

Ques90. What does the following function do?
function operation (int a, int b)
{
if (a < b)
{ return operation(b, a) }
else
{ return a }
}
Op 1: Returns the max of (a,b)
Op 2: Returns the min of (a,b)
Op 3: Loops forever
Op 4: Always returns the second parameter
Op 5:
Correct Op : 1

No comments:

Post a Comment