New Technical AMCAT Q&A June 2019
New Technical AMCAT Q&A June 2019
1. Consider the given code. Assume that “a” and “b” are passed by value. What will be the output of the
program when the function calculate is executed?
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;
}
a. 80
b. 40
c. 32
d. 72
Ans : 40
2. A programmer prepares a questionnaire with true or false type of questions. He wants to define the data
type that stores the response of the candidates for the questions. Which id the most suited data type for
this purpose?
a. Integer
b. Boolean
c. Float
d. Character
Ans : b
3. Following are listed the similarities between classes and structure.
a. Both can have a constructor
b. Both can implements interfaces.
c. Both can use the access specifiers for the members – public , private and protected.
Which of the above mentioned statement is/are true?
a. Only a
b. Only b
c. Only c
d. Only a and b.
e. Only b and c.
Ans : C
4. A linear list of elements in which deletion can be done from one end (front) and insertion can take place
only at the other end (rear) is known as a :
a. Queue
b. Stack
c. Tree
d. Branch
Ans : a
5. What is the first step for developing a working program to solve a problem :
a. To write the program in working language
b. To write a step by step algorithm to solve a problem.
c. To compile required libraries.
d. To debug the code.
Ans : b
6. How many nodes does a complete binary tree with 5 levels have, if the root is considered to be at level 1.
a. 15
b. 25
c. 63
d. 31
Ans : d
Explanation: 2n -1
7. Merge sort requires O(n) space when implemented using __________.
a. Array
b. Linked List
c. Both Array and Linked List
d. Merge sort can be implemented using constant space irrespective of the implementing
data structure :
Ans : a
8. A programmer mistakenly write “gor” instead of the keyword “for” used in loops. While writing a program
in C++, what will this result in?
a. The code would not complete.
b. The code would give an error while execution
c. The code may work for some inputs and not for the others.
d. The code would not create any problem.
Ans : b
12. A programmer is making a database of animals in a zoo along with their properties. The possible animals
are dog, lion and zebra with attributes color and nocturnal. The programmer uses the object oriented
programming paradigm for this. How we can conceputlized?
a. Class: animal; Object dog, lion and zebra; data members : color and nocturnal.
b. Class: animal; data members dog, lion and zebra; objects : color and nocturnal.
c. Class: dog, lion and zebra; Objects : animals; data members : color and nocturnals.
d. None of the above.
Ans : a
Explanation: One class has many attributes and it is possible to declare multiple objects of a single class and
all these objects have same properties i.e. herbivorous, color and nocturnal
16. The program to print the larger of the two numbers entered by a user given below. What should be used in
place of “??” in statement1 of the code to get the desired output?
int number1,number2;
input number1, number2;
if(??) // statement1
print number1
else
print number2
end if;
a. number1>number2
b. number2>number1
c. number2 equals number1
d. number1<=number2
Ans : a
18. What is the time taken to insert an element at position k(1<k<n) in an array with n elements?
a. O(n-k)
b. O(k)
c. O(n)
d. O(1)
Ans : c
19. In which areas of a class are data and functions are directly accessible outside the class?
a. public
b. private
c. protected
d. none of the above.
Ans : a
20. Assume that the following precedence (high to low). Operators in the same row have the same
precedence.
()
*/
+-
AND
OR
The precedence is from left to right for the operators will equal precedence.
What will be the output of the following code statements?
int a=50,b=25,c=5;
print a*b/c+c;
a. 120
b. 125
c. 255
d. 250
Ans : c
21. A football seller stores all the footballs in a large container that is closed to bottom. The footballs are
stacked on top of each other in the box. The new supply of balls is put in the box from the top. When a
customer buys a football the one at the top of the stack is given to the customer. Each football has a code.
The seller wants to store the codes of all the footballs in a data structure to keep track of the inventory.
Which data structure should be used for this purpose?
a. Queue
b. Stack
c. Array
d. Graph
Ans : b
22. Which of the given function prototypes can be considered to be overloaded(no ambiguity)?
a. Function myFunction(int num,float me) // does not return anything
b. Function myFunction(int num,double me) // does not return anything
c. Function myFunction(char num,float me) // does not return anything
d. Function myFunction(int num,float me) // return an integer
a. a and b
b. a,b and c
c. a,c and d
d. b,c and d
e. a,b,c and d
Ans : b
23. In a linear list of elements, a deletion can be made from one end(front) and an insertion can be made at
the other end. What is this linear list known as?
a. Queue
b. Stack
c. Tree
d. Branch
Ans : a
24. Raj has a list of n numbers each of a fixed size k. He sort them using radix sort technique. What is the
complexity of this operation?
a. O(n-k)
b. O(nk)
c. O(k log n)
d. k O(log n)
Ans : c
25. Two programmers independently write a program to find the mass of one mole of water that includes the
masses of hydrogen and oxygen.
The first programmer defines the variable as:
integer hydrogen,oxygen,water// code A
26. Why is an algorithm designer concerned primarily about the run time not the compile time while
calculating time complexity of an algorithm?
a. Run time is always more than compile time
b. Compile time is always more than run time
c. Compile time is a function of run time.
d. A program needs to be compiled once but can be run several times.
Ans : d
Explanation: Because the execution time is more important .if a program will take more time than that code
can‟t be an efficient code.
Answer : D
28. In which of the following method sorting is not possible
a) Insertion
b) Selection
c) Exchange
d) Deletion
Answer : C
29. How can a call to an overload function be ambiguous
a) The name of the function might have been misspelled
b) There might be two or more function for the same name
c) There might be two or more function with equally appropriate signatures
d) None of the above
Answer : C
Explanation: Function overloading means same name function can be called multiple times but with
difference in number or type of arguments
31. What is the name given to the function having no memory or I/O side effects
a) Pure function
b) Methods
c) Subroutine
d) Procedure
Answer :
32. Which of the given option implies that there are two loops that are nested
a) Two loops , one after the other
b) Two loops , one inside the other
c) One loop with two different iteration counts
d) Two loops with same iteration count
Answer : B
33. In an implementation of a linked list , each node contain data and address .what can be the address field
possibly contain
a) Address of the next node in the sequence
b) Its own address
c) Address of the last node
d) Address of the first node
Answer : A
Explanation: In linked list,each node contains two parts: data and address.Data part contains data available in
that node & Address part contains address of the next node which is needed to traverse.
34. In which areas of the class are data and function directly accessible outside the class
a) Public
b) Private
c) Protected
d) None of the above
Answer : A
35. Piyush wrote a Binary Search program which ask the user for two inputs : the list of numbers and items to
be searched for : the list entered is (5,7,11,12,19,20,25)
Number to be searched :19
How many comaprisons would be brought out by the program for searching this item by Binary Search
a) 2
b) 3
c) 5
d) 7
Answer : A
36. Passage
Union Myunion
{
Structure Mystructure
{
Interger m
Float n
Character o
}Mystr
Integer p
}Myun
Given that the size of integer is 2 units , float is 4 units and character is 1 unit ,what will be the amount of
memory occupied by Myun object
a) 2 units
b) 6 units
c) 7 units
d) 9 units
Answer : C
37. A programmer writes a sorting algorithm that takes different amount of time to sort two different lists of
equal size .What is the possible difference between the two list
a) All number in one list are more than 100 while in the other are less than 100
b) The ordering of number with respect to magnitude in the two list has different properties
c) One list has all negative numbers while the other list has all positive numbers
d) One list contain 0 as an element while other does not
Answer : B
38. Which of the following statements refers to data hiding in Object Oriented Programming
a) A class does not have functions as private members
b) A class has both data and functions in the data in the class
c) A single class can have many objects
d) Data in the private and protected area of a class is not directly accessed through member functions in the
public area of class
Answer :
39. Assume the following precedence (high to low) , operators in the same row has the same precedence
()
/ *
+
AND
OR
The precedence is from left to right for the operators with equal precedence
Answer : C
40. Yukta created an interface to use in different parts of the program by implementing it . but she forgot to
specify access specifier for each contained method . What will be the access specifier of the method that
will be inherited/implemented ?
a) Public
b) Private
c) Protected
d) Aa error will be generated
Answer : A
41. What will happen if some indentations are made in some statements of a code written in C++
a) Faster execution of the code
b) Lower memory requirement of the code
c) Corrections of error in the code
d) Better readability of the code
Answer : D
. Explanation: neat and clean Programs.
42. Which of the given sorting techniques has the worst case functioning time less than O(n*n)
a) Heap Sort
b) Quick Sort
c) Insertion Sort
d) Selection Sort
Answer : A
43. Which abstract data type can be used to represent many-to-many relation
a) Tree
b) Stack
c) Graph
d) Queue
Answer : C
44. Which of the following factors does NOT matter when dealing with a function call
a) Number of formal parameters and informal parameters
b) Return type of the function
c) Respective data type of formal parameters and informal parameters
d) Operation bought out in the function’s body
Answer : B/D
45. What will be the values of FRONT and REAR respectively if the following operations takes place on the
queue shown in the given figure starts from B and moves in the anticlockwise direction :
B=1 A
1. ADD D
2. REMOVE A,B
3. ADD X,Y
a) 2,5
b) 0,6
c) 7,2
d) 0,4
Answer :
Ans: b
47. The program to print the sum of all cubes that lie between 0 and 100 is given below.Does this program
have any error?If yes, which statement should be modified to correct the program?
Integer i=0,a //Statement 1
Integer sum=0
a=(i*i*i)
while(i<100) //Statement 2
{
sum=sum+a; //Statement 3
i=i+1;
a=(i*i*i); //Statement 4
}
Print sum;
a) Statement 1
b) Statement 2
c) Statement 3
d) Statement 4
e) None of these
Ans: b
48. Assume the following precedence (high to low).
Operators in the same row have the same precedence:
(.)
*/
+-
AND
OR
For operators with equal precedence, the precedence is from left-to-right in expression. What will be the
output of the following code statements?
integer a = 40, b = 35, c = 20,d=0
print a*b/c-d
Print a*b/(c-d)
a) The output differ by 80
b) The outputs are the same
c) The output differ by 50 4.
d) The output differ by 150
Answer: b
Explanation: In both the print statement the expression will evaluate from L->R.and the statement „b/c- d‟
and b/(c-d) give same result because 20-0 =20
Ans: d
Explanation: Case b…..Only constant expression are valid with switch cases
52. Ananya has a linked list with 10 elements. Using an algorithm, she has currently accessed 6 elements with
her pointer pointing to the seventh element. She wants to insert a node after the seventh node. What will
be the time taken to bring out the same?
a) O(1)
b) O(n)
c) O(log n)
d) n O(log n)
Ans: O(1)
53. Which will be the most efficient approach to find the largest number in a given list of 20 numbers?
a) Use bubble sort to sort the list in descending order and then print the first number of the series.
b) Use selection sort to sort the list in descending order and then print the first number of the series.
c) Implement one iteration of selection sort for descending order and print the first number in the series.
d) None of these
Answer: 3
Explanation: In selection sort if we arrange in descending order, in very first iteration the largest no will be
placed at first position because we select largest no and put to the first position.
54. A sorting mechanism uses the binary tree concept such that any number in the tree is larger than all the
numbers in the sub tree below it. What is this method called?
a) Selection Sort
b) Insertion Sort
c) Heap sort
d) Quick Sort
Answer: 3
Explanation: In Max heap, the root node is larger than all the elements below it in the sub tree
Explanation: The heap is often placed in an array with the layout of a complete binary tree
55. A programmer wants the program given below to print the largest number out of 3 numbers entered by
user.
Integer number 1, number 2, number 3,temp; Input number 1, number 2,
number 3;
If ( number 1 > number 2)
Temp = number 1
Else
Temp= number 2
End if
If ( ??) // statement 1
Temp = number 3
End if
Print temp
Fill in the ?? in statement 1 ?
Choose the correct answer?
a) Number 3> number 2
b) Number 3> temp
c) Number 3< temp
d) Number 3> number 1
Answer: 2
Explanation: number 3>temp ,after first condition checking, temp will hold the largest value, so in stmt 1 third
no. will be compared with temp and if it is greater than temp will hold the largest no.
56. How many nodes does a full binary tree with “n” leaves contain?
a) 2n+1 nodes
b) Log2n nodes
c) 2n-1 nodes
d) 2n nodes
Answer: 3 Explanation: For example a full binary tree with 4 leaves contain 7 nodes.i.e;2*4-1=7.
57. A programmer writes a program to find an element in the array A[5] with the following elements in order:
8 30 40 45 70. She runs the program to find a number X. X is found in the first iteration of binary search.
What is the value of X?
a) 40
b) 8
c) 70
d) 30
Answer: a
Explanation: In binary search technique, mid-point is searched first of all. Then, Left and Right nodes are traversed.
58. Refer to the pseudo code given in the passage. The code is similar to that in C++ and is self-explanatory.
An accessible member function and a data member for an object are accessed by the statements
objectname.functionname and objectname.datamembername , respectively. Which statement should be
deleted from the code to rectify error in it?
Class Brush
{
Private:
Integer size,c
Function getdata(){} //statement 1
Public:
integer name //statement 2
Function putdata(){}
}
Function main()
{
Brush b1,b2
Print b1.name //statement 3
b2.getdata() //statement 4
}
a) Statement 1
b) Statement 2
c) Statement 3
d) Statement 4
Ans: Statement 4 , since the private members of a class cannot be accessed outside the class.
59. A queue is implemented as a singly linked list. Each node has an element and a pointer to another node.
The rear and the front contain the addresses of the rear and the front nodes, respectively. What can be
inferred about the linked list if the condition(rear is equal front) is true?
a) It has no elements
b) It has one element
c) There is an error
d) None of the above
Answer: 2
60. The following operation are performed on an empty stack “A”
PUSH(1)
PUSH(2)
POP
PUSH(5)
PUSH(6)
POP
What will stack contain after these operations?
Note: The top of the stack is underlined in the option below)
a) 5 6
b) 1 5
c) 5 6
d) 1 5
Answer: 2
Explanation: Stack uses LIFO (Last In First Out) technique. All elements are inserted and deleted from
top of stack.
61. What will be the output of the following pseudo-code statements?
integer a = 984, b=10,
float c
c=a/b
print c
a)984
b) 98.4
c)98
d) error
Ans: c
62. The given binary tree refers to which of the given formula?
+ -
z *
x y
m n
a) (x+y)(z-(m*n))
b) [(x+y/)z]-(m*n)
c) x+(y/[z-(m*n)])
d) (x+y)/[z-(m*n)]
Ans: d
63. A function in the base class is re-defined in the inherited class. Which term is used to describe this
situation?
a) Inheritance
b) Overriding
c) Overloading
d) Encapsulation
Ans: b)
Explanation: Overriding is the process of redefining parent class method in child class with same signature.
In this process, child class method will override the method of parent class.
Answer: a)
65. A programmer wants to make a function that is not bound to any identifier.Which type of the function
should be incorporated in the program?
a) Anonymous Function
b) Friend function
c) Null function
d) Global Function
66. Which of the following implies that there are two loops that are nested?
a) Two loops, one after the other.
b) Two loops, one inside the other.
c) One loop with two different iteration counts
d) Two loops with same iteration count
Answer: b
Explanation: In nested loop, the outer loop contains the inner loop.
67. A programmer 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?
a) Use for loops
b) Use functions
c) Use arrays
d) Use classes
Explanation: Because function is used for reusability. Function is a block of statements that can be called
multiple times and at any place in the program.
68. The function given below computes the factorial of the number “n” entered by a user. What should be
the missing statement in order to make the code work properly?
function factorial(n)
{
if(n equals 1)
return 1
else
missing statement
end
}
a. return factorial(n-1)
b. return n*factorial(n)
c. return n(n-1)
d. return n*factorial(n-1)
And : d
Explanation: return n*fact(n-1) since it’s a recursive factorial(n) then there is a need to call the factorial(n)
every time.
69. Comment about the output of the following two statements:
integer a = 40, b = 35, c = 20, d = 10
print a * b / c - d
print a * b / (c - d)
a) Differ by 80
b) Same
c) Differ by 50
d) Differ by 160
Answer: 1
70. Every element of a data structure has an address and a key associated with it. A search mechanism does
with two or more values assigned to the same address by using the key. What is this search mechanism?
a) Linear search
b) Binary Search
c) Hash coded search
d) None of the above
Answer c
Explanation: Hash Coded Search uses a hash key and hash address in hash table.
71. Ritika was asked to include concrete objects in her project. Which of the given statements defines the
concrete objects?
a) All the objects created as the instance of the class.
b) Objects created using new keyword
c) Variable and objects that include concrete keyword
d) Objects created under conditional statements
72. A programmer writes a program to find an element in the array A [5] with the elements 8,
30, 40, 50, 70. The program is run to find a number “X”, that is found in the first iteration of binary
search. What is the value of “X”?
a) 40
b) 8
c) 70
d) 30
Ans: a)
Explanation: In this technique, first of all, value in mid position is searched (as a first step).If it is not found,
and then we will check left part and right part respectively. So, if the value is found in first iteration, it can
be mid value only.
73. Which of the following gives the maximum number of nodes at level “I” of a binary tree?
(Note: The root is at level 1.)
a) 2I-1
b) 3I-1
c) 2I
d) 3I
Ans: a)
74. What will be the output generated when the given code is executed?
Passage
function main()
{
integer a=5
switch(a)
{
default: print ”hello”;
case 5: print “How are you?”;
break;
}
}
a) hello
b) How are you?
c) helloHow are you?
d) This code will generate a compile time error
Ans: b)
75. 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.
a) 1
b) 30
c) 15
d) 16
Ans: c)
Explanation: In question they specifically told even numbers only. So in 30 numbers there will be 15
even numbers and 15 odd numbers so the sum function called 15 times.
76. A developer writes the program given below to print the sum of the first five whole numbers (0, 4). Is the
program correct? If not, which statement should be modified to correct the program?
integer i = 0 // statement 1
integer sum = 0 // statement 2
while ( i < 5 ) // statement 3
{
sum = i*i // statement 4
i = i + 1 // statement 5
}print sum // statement 6
77. Consider a binary tree implementation. The root address is stored in variable root. Given the address of
a node is variable node. The value of the node and its right and left child nodes can be accessed using the
given statements.
Node -> value
Node -> right
Node -> left
A programmer writes the given function to do a preorder traversal of the tree.
functionpreordertraverse(n0de)
{
print node -> value
if(Conditon X)
{
preordertraverse(node ->left)
}
if(Condition Y)
{
preordertraverse(node ->right)
}
return
78. Binary Search algorithm CANNOT be directly applied to which of the given Data Structure?
a) Sorted Linear Array
b) Sorted Plain Linked List
c) Binary Tree
d) Sorted Pointer Array
Ans: d)
Sorted Pointer array may contain memory locations in sorted order which doesn’t ensure the sorted order of
elements at those locations
79. A programmer writes code snippets in which 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?
a) For loops
b) Functions
c) Arrays
d) Classes
Ans: b)
Explanation: Because function is used for reusability. Function is a block of statements that can be called
multiple times and at any place in the program.
80. Passage
class rocket
{
Private:
Integer height, weight
Public // statement 1
Function input(int a, int b)
{
Height= a;
Weight= b;
}
}
Function main()
{
Rocket rocket1, rocket2
}
Refer to the pseudo code given in the passage. The code is similar to that in C++ and is self
explanatory. An accessible member function and a data member for an object are accessed by the
statements objectname.functionname and objectname.datamembername,respectively. What can be
inferred from this code ?
a) “rocket” is class with “rocket1” and “rocket2” as its objects with “height” and “weight” as its
attributes
b) “rocket” is class with “rocket1” and “rocket2” as its objects with “height” and “weight” as its objects.
c) “rocket” is class with “rocket1” , “rocket2” ,“height” and “weight” as its attributes.
d) “rocket” is class with “rocket1” , “rocket2” ,“height” and “weight” as its objects.
Ans: a)
Ans: d)
a) Always +1
b) 1 if a > b, -1 if a < b, 0 otherwise
c) 0 if a equals b, -1 otherwise
d) -1 if a > b, 1 if a < b, 0 otherwise
Ans: b)
Ans: c)
84. A programmer prepares a questionnaire with “true or false” type of questions. He 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?
a) Integer
b) Boolean
c) Float
d) Character
Ans: 2
Explanation: Bool used for true or false
85. Which of the following option gives the lower bound on running time for the algorithm?
a) Best case of complexity of the algorithm.
b) Average case of complexity of the algorithm.
c) Worst case of complexity of the algorithm.
d) Number of iterations taking place in the algorithm.
Ans: a)
19
87. Which of the following sorting algorithms yields approximately the same worst-case and a average-case
running time behavior in O(n logn)?
a) Bubble sort and Selection sort
b) Heap sort and merge sort
c) Quick sort and Radix sort
d) Tree sort and Median-of-3 Quick sort.
Ans: b)
88. Which of the following data types does not belong to the category of abstract data types?
a) Hash table
b) Set
c) Object
d) Stack
Ans: c)
89. To solve a problem, it is broken in to a sequence of smaller sub-problems, till a stage that the sub-
problem can be easily solved. What is this design approach called?
a) Top-down Approach
b) Bottom-Up Approach
c) Procedural Programming
d) None of these
Ans: a)
90. A librarian has to arrange the library books on a shelf in a proper order at the end of each
day. Which of the following sorting techniques should be the librarian ideal choice?
a) Bubble sort
b) Insertion sort
c) Selection sort
d) Heap sort
Ans: b)
Explanation: Books in shelf‟s denotes that their not so many books in the shelf‟s and there must be
minimum no of swap (movement of hands in replacing books while arranging)so insertion sort is the best
algorithm for small no of elements. Which best case is O(n) and worst case O(n^2) which is better than
bubble and selection sort.
91. What will the output of the following pseudocode statements be?
integer a=456, b, c, d=10
b=a/d
c=a-b
print c
a) 410
b) 410.4
c) 411.4
d) 411
Ans: d)
93. Function main is the starting point of execution of a program. Which of the following options shall help
in making an executable program without the use of main function in the program?
a) Any function can be made and marked as starting point using a language dependent syntax
b) Two macros can be used. One to hold the name of a function and its working and the other to call the first
macro
c) Any program without a main function shall not do anything but can only produce a blank screen
d) It is not possible to run a program without a main function in a program
Ans: b)
94. Consider the given code to print the name on the screen. Which statement will generate an error?
Passage
Function display(string MyStr) //Statement1
{
Print “Hello My name is”
Printf MyStr //Statement2
}
Function main() //statement3
{
String str=”MrBeans”
Integer num=Display(str) //statement4
}
a) Statement1
b) Statement2
c) Statement3
d) Statement4
e) This code will run without any error
Ans: d)
95. Any program residing in the memory contains a set of instructions that need to be executed by the
computer in a sequential manner. This cycle for every instruction is known as the instruction cycle. The
cycle consist of the following steps that may or may not be the proper sequence of execution.
1. Fetch the operand from the memory
2. Execution
3. Fetch the instruction
4. Decode the instruction
5. Result
In which of the given step is the programme counter (PC) loaded with the address of the next
instruction?
a) Execution
b) Fetch the instruction
c) Result
d) Decode the instruction
Ans:b)
96. Neha wants to write a program that converts a decimal number into a binary number. Which of the
given data structure should she use to implement the same?
a) Queue
b) Stack
c) Array
d) Linked list
Ans:b)
97. Which of the following gives the maximum number of nodes at level “i” of a binary tree?
(Note: root is at level 1)
a) 2i-1
b) 3i-1
c) 2i
d) 2i -1
Ans: a)
Explanation: (2^i)-1 where 2^i is the number of nodes at level I and -1 because root has only one element.