# AMCAT Placement Paper - 4

Passage:
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?
Question
i) 1 ii) 30 iii) 15 iv) 16

What will be the Infix form of the given Postfix notation?
ABCD/+*

Question
i) A/B+C*D ii) A*(B+C)/D iii) A*(B+C/D) iv) A/(B+C*D)

Passage:
A destructor may be invoked in which of the following situations?
Question
i) When the object is created
ii) When the object is assigned value 0.
iii) Only at the end of the code
iv) When the scope of the object is over.

Question
Which of the following options is an exception to being a part of composite data types?

i) Union
ii) Array
iii) Structure
iv) Stack

Passage:
Ravi and Rupali are asked to write a program to sum the rows of a 2X2 matrices stored
in the array A.
Ravi writes the following code (Code A):
for n = 0 to 1
sumRow1[n] = A[n][1] + A[n][2]
end
Rupali writes the following code (Code B):
sumRow1[0] = A[0][1] + A[0][2]
sumRow1[1] = A[1][1] + A[1][2]
Comment upon these codes (Assume no loop-unrolling done by compiler):
Question
i) Code A will execute faster than Code B.
ii) Code B will execute faster than Code A
iii) Code A is logically incorrect.
iv) Code B is logically incorrect.

Passage:
A variable cannot be used...
Question
i) Before it is declared
ii) After it is declared
iv) In the function it is declared in
v) Can always be used

Passage:
In which area of a class are data and function directly accessible outside the class?
Question
i) Public
ii) Private
iii) Protected
iv) None of these

Passage:
Every element of a data structure has an address and a key associated with it. A search
mechanism deals with two or more values assigned to the same address by using the
key. What is this search mechanism?
Question
i) Linear Search
ii) Binary search
iii) Hash Coded Search
iv) None of these

Question
Which of the following options is equal to the complexity given as O(n log n)?

i) n O(log n)
ii) O(n!)
iii) O(log n!)
iv) O(n )

Passage:
A complete binary tree with 5 levels has how many nodes? (Root is Level 1)
Question
i) 15
ii) 25
iii) 63
31

Passage:
Which of the following abstract data types can be used to represent a many-to-many
relation?

Question
i) Tree
ii) Stack
iii) Graph
iv) Queue

Passage:
While calculating time complexity of an algorithm, the designer concerns
himself/herself primarily with the run time and not the compile time. Why?

Question
Run time is always more than compile time.
Compile time is always more than run time.
Compile time is a function of run time.
A program needs to be compiled once but can be run several times.

For the given array, find the arrangement of elements after 3rd pass of Selection Sort. Assume that the array is being sorted in ascending order.
List: 33, 22, 11, 77, 66, 88, 55

Question
i ) 22, 11, 33, 66, 77, 55, 88
ii) 11, 22, 33, 55, 66, 77, 88
iii) 11, 22, 33, 55, 66, 88, 77
iv) 11, 22, 33, 77, 66, 88, 55

Passage:
A linear list of elements in which deletion can be done from one end (front) and
insertion can take place at the other end (rear) is known as

Question
i) Queue
ii) Stack
iii) Tree
iv) Branch

Passage:
Zenab and Shashi independently write a program to find the the mass of one mole of
water, which includes mass of hydrogen and oxygen. Zenab defines the variables:
integer hydrogen, oxygen, water // Code A
while Shashi defines the three quantities as:
integer a, b, c // Code B
Which is a better programming practice and why?

Question
i) Code B is better because variable names are shorter
ii) Code A is better because the variable names are understandable
and non-confusing
iii) Code A will run correctly, while Code B will give an error.
iv) Code B will run correctly, while Code A will give an error.

Passage:
The algorithm design technique used in the quick sort algorithm is
Question
i) Dynamic Programming
ii) Back Tracking
iii )Divide and Conquer
iv) Greedy Search

Passage:
In an implementation of a linked list, each node contains data and address. Which of
the following could the address field possibly contain?

Question
i) Address of next node in sequence

Passage:
function MyBinarySearch(array arr, integer low, integer high, integer item)
{
if ( low > high )
{
return -1
}
integer mid = (low + high)/2
if ( arr[mid] equals item )
{
return mid
}
else if ( arr[mid] > item )
{
return //missing statement 1
}
else
{
return //missing statement 2
}
}
Question
MyBinarySearch(arr, mid+1, high, item)
MyBinarySearch(arr, low+1, mid-1, item)
MyBinarySearch(arr, low, mid-1, item)
MyBinarySearch(arr, mid+1, high-1, item)
Harshul uses the given code to implement Binary Search
recursively. Find the statement that will replace missing
statement 2 in the given code such that it works efficiently.

Passage:
Stuti is making a questionnaire of True-false questions. She wants to define a data-type
which stores the response of the candidate for the question. What is the most-suited
data type for this purpose?
Question
i) integer
ii) boolean
iii) float
iv) character