150+ MCQs For OAs of Placements - GATE
150+ MCQs For OAs of Placements - GATE
A. Anonymous Function
B. Generic Function
C. Void Function
D. Null Operator
2) A complete binary tree has a property that
the value at each node is at least as large as the
values at its children nodes. What is this binary
tree known as?
A. Integer
B. Character
C. Boolean
D. Array
4) Which of the following sorting algorithms
yields approximately the same worst-case and
average-case running time behavior in O(n
long)?
A. It has no elements
B. It has one element
C. There is an error
D. None of the above
8) Consider the code given below. Assume that “a” and “b” are
passed reference. What will the output of the program be when the
function calculate() is executed?
function modify(b,a)
{
return a –b
}
function calculate()
{
integer a = 5, b = 12, c
c = modify(a,b):
print c
}
A. 7
B. -7
C. 8
D. Error
Passage
functionmyfunc()
{
constant integer i=5
if (i> 3)
print “i am smali”
if ( i-- > 5 )
print “i am iarge”
eise print “i am different”
}
A pseudo-coed is used which is self explanatory.
9) What will be the output of the given code?
A. I am small
B. I am small am large
C. I am small am different
D. This code will generate an error
10) A librarian has to rearrange 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’s ideal
choice?
A. Bubble sort
B. Insertion sort
C. Selection sort
D. Heap sort
11) A tree has 5 levels and each node has either
4 or no children. All nodes on the same level
have the same number of children. How many
nodes are there in the tree?
A. 341
B. 256
C. 1024
D. None of the above
12) Why is an algorithm designer concerned
primarily about the run time and not the
compile time while calculating time complexity
of an algorithm?
A. Radix search
B. Breadth fist search
C. Recursion
D. None of the above
14. Passage
Function print_me(integer n) // Statement 1
{
if ( n < 1 ) return // Statement 2
print n // Statement 3
print_me(n-1) //Statement 4
}
A. 410
B. 410.4
C. 411.4
D. 411
17. Passage
while (j<=3*i)
{
print j
print blank space
j=j+3
}
print end-of-line //takes the cursor to the next line
i=i+1
}
A. 0
03
B. 0 3
036
C. 0 3
036
0 3 69
D. 0 3 6
0369
036912
18. What does the following function do?
A. (n+1)/2
B. log 2n
C. n(n+1)/2
D. n 2
20. How are protected members of a base class
accessed in the derived class when inherited
privately in C++?
A. Privately
B. Publicly
C. Protectedly
D. Not inherited
21. How many nodes does a full binary tree
with n” non-leaf nodes contain?
A. log n
B. n + 1
C. 2n + 1
D. 2n
22. A programmer mistakenly writes “gor”
instead of the keyword “for” used in loops,
while writing a program in C++. What will this
result in?
A. Union
B. Array
C. Structure
D. Stack
24. Which characteristic of data does a binary
search use and a linear search does not?
A. Insertion sort
B. Selection sort
C. Heap sort
D. Quick sort
26. In which of the following methods is sorting NOT
possible?
A. Insertion
B. Selection
C. Exchange
D. Deletion
27. A programmer is making a database of animals in a
zoo along with their properties. The possible animals
are dog. Lion and zebra each one has attributes as
herbivorous. Color and nocturnal. The programmer
uses the object‐ oriented programming paradigm for
this. How will the system be conceptualized?
a. Integer
B. Boolean
c. float
d. character
30. Parthiv has included several classes and
their subjects in his project. Now he wants to
use something that will hold all these objects
(of different classes). Which of the following
options provides him with the best iterative?
A. i = 5
B. i = 5 *I
C. i = i + 1
D. i = i + 5
32. 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?
A. Insertion sort
B. Heap sort
C. Quick sort
D. Bubble sort
37. What is the space complexity of a program?
A. 40
B. 8
C. 70
D. 30
39. Saloni writes the code for a function that
takes as input n, an even integer and calculates
the sum of 1st n natural numbers
function sum (n)
{
if(n equals 2)
return 2
else
return ( n+ sum( n-1))
}
She then calls the function by the statement,
sum(30). How many times will the function
sum be called to compute this sum? Choose the
correct answer?
40. Shalini wants to programme to print the largest
number out of 3 inputted numbers. She writes the
following programme
Int 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
41. How many pointers will have to be changed
when a new node is to be added in a linear
linked list in the middle?
A. 0
B. 1
C. 2
D. All the pointers will be changed
42. A variable cannot be used?
A. Before it is declared
B. After it is declared
C. In the function it is declared in
D. Can always be used
43. In which area of a class are data and
function directly accessible outside the class?
A. Public
B. Private
C. Protected
D. None
44. Which of the following options is true
regarding inheritance in Object Oriented
Programming ? Choose the correct answer?
A. Linear search
B. Selection search
C. Hash coded search
D. Binary search
E. None of this
46. Which of the following abstract data types
can be used to represent many – to- many
relations? Choose the correct answer?
A. Tree
B. Stack
C. Graph
D. Queue
47. Pragya sells footballs. She has a large
container to store footballs which is closed
from below. Footballs are piled one on top of
the other in the box. When new balls are
supplied, Pragya puts the balls in the box from
the top. When a customer buys a ball, she
delivers the ball at the top of the pile to the
customer. Each ball has a code. She wants to
store the ball codes in the data structure to
keep track of her inventory. What data
structure should she use? Choose the correct
answer?
48. For the given array, find the arrangement of
the 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
A. Dynamic programming
B. Back tracking
C. Divide and conquer
D. Greedy search
51. How can call to an overloaded function be
ambiguous?
A. TTF
B. TTT
C. TFF
D.FTF
53. Which of the following options gives the
lower bound on running time for an algorithm?
A. We are equal
B. I am greater
C. I am lesser
D. This code will generate an error
55. Consider an array on which bubble sort is
used. The bubble sort would compare the
element A[x] to which of the following
elements in a single iteration?
A. A[x+1]
B. A[x+2]
C.A[x+2x]
D. All of these
56. Choose the correct answer. Consider the
statement
A. a < 1.0
B. a <sqrt (10)
C. a >sqrt (10)
D. a = 0
57. Choose the correct answer. Ankita takes as
input 2 integer numbers, a and b, whose value
can be between 0 and 31. He stores them as 5
bit numbers. He writes the following code to
process these numbers to produce a third
number c.
c = 2*(a – b)
In how many minimum bits should Ankita
store c?
A. 6 bits
B. 7 bits
C. 8 bits
D. 9 bits
58. Recursive function is executed in a
___________________________
A. Public
B. Private
C. Protected
D. An error will be generated
60. Which of the following statements are true?
A. Both 1 and 2
B. Both 3 and 4
C. 1, 2 and 3
61. Choose the correct answer. A Queue is
implemented by a linear array of size 10 (and
not as a circularly connected array). Front and
Rear are represented as an index in the array.
To add an element, the rear index is
incremented and the element is added. To
delete an element, the front index is
incremented. The following operations are
done on an empty queue.
ADD 1; DELETE; ADD 2; ADD 3; ADD 4; DELETE,
DELETE.
After this set of operations, what is the
maximum capacity of the queue?
A. 6 B. 7
62. A 8-bit signed integer has the following
range?
C. Statement 4 D. statement 6
64. Here is an infix notation: ((A+B)*C-(D-E))^(F+G)
Choose the correct postfix notation of the above from
the given options?
A. AB+CD*E–FG+^
B. AB+C*DE–FG+^
C. AB+C*DE-FG-+^
D. A+BC*DE-FG-+^
65. One of the following options is a form of
access used to add and remove nodes from a
queue.
A. LIFO
B. FIFO
D. None of these
66. What is the time complexity of adding three
matrices of size NXN cell-by-cell?
A. O (N)
B. O (N^2)
C. O (N^3)
D. None of these
67. What is the output of the pseudocode statements
given below?
(Note: Assume that when two data types are processed
through an operator, the answer maintains the same
data type as that of the input. Also, all data types have
enough range to accommodate any number. If two
different data types are operated upon, the result
assumes the data type that is more expressive.)
integer a=984, b=10
//float is a data type to store real numbers.
float c
c=a/b
print c
A. 984
B. 98.4
C. 98
68. What will be the output generated when the given code is
executed?A pseudo- code is used which is self explanatory.
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
69. A language has 28 different letters in total.
Each word in the language consists of a
maximum of 7 letters. A programmer wants to
create a data type to store a word of this
language. She decides to store the word as an
array of letters. How many bits should she
assign to the data type to store all kinds of
words of the language?
A. 7
B. 35
C. 28
D. 196
70. How can the largest number in a list of
twenty numbers be found?
A. O(n2)
B. O(n)
C. O(n*log(n))
D. None of the above
72. 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
73. Refer to the pseudocode 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 andobjectname. datamembername,
respectively. Which statement should be deleted from
the code to rectify the error in it ?
A. Statement 1
B. Statement 2
C. Statement 3
D. Statement 4
74. The following values are to be stored in a
hash Table-15,22,41,19,102,18,37
Using the division method of hashing with a
table size of 10 (use sequential method of
resolving collision),give the contents of Hash
Table.
C. 41,22,102,15,37,18,19
A. (n – m + 1)/2
B. 1 + (n –m)/2
A.410
B. 410.4
C. 411.4
D. 411
2.Q) The function given below takes a number “n” as the input
and calculates the sum of first “n” natural numbers. Which of the
following statements should be inserted in place of “??” to get
the required output?
function sum(n)
{
if (??)
return 1
else
return (n + sum(n‐1))
end
}
A. n equals 1
B. n equals 2
C. n>= 1
D. n>1
3.Q) Which of the following implies that there are two loops that
are nested?
A. 43210
B. 54321
C. This code will enter an infinite loop
D. This code will generate an error
5.Q) The function given below takes an even integer “n” as the input and
calculates the sum of first “n” even natural numbers. The function is called by
the statement “sum (30)”. How many times will the function “sum” be called
to compute the sum?
function sum(n)
{
if (n equals 2)
return 2
else
return (n + sum(n‐2)
end
}
A. 1
B. 30
C. 15
D. 16
Passage
Class rocket
{
private:
integer height, weight
public: \\statement 1
function input a, int b)
{
height = a;
weight = b;
}
}
function main( )
{
Rocket rocket1, rocket2
}
6.Q) Refer to the pseudocode given in the ‘Passage’. The
code is similar to that in C++ and is self-explanatory. An
accessible member Funcction and a data member for
an object are accessed by the statements objectname.
Functionname and objectname. Datamemnername,
respectively.
What can be inferred from this code?
A. 1,4
B. 2,5
C. 1,5
D. 2,4
12.Q) Which of the following can be inherited
by a derived class from a base class?
A. Data members
B. Member functions
C. Constructors and destructors
D. Data members and member functions
13.Q) A programmer wants the program given below to print the
largest number out of three numbers entered by the user.
int number1, number 2, number 3, temp;
input number 1, number 2, number 3;
if (number1>number2)
temp = number 1
else
temp = number 2
end if
if (??) // Statement 1
temp = number 3
end if
print temp
Which of the following should be substituted in place of “??” in
Statement 1 in the code?
A. number3> number2
B. number3> temp
C. number3> temp
D. number3> number1
14.Q) Which of the given function prototypes can be considered to be
overloaded (no ambiguity)?
A. function my Func(integer Num, float me) // does not return anything
B. function my Func(integer Num, double me) // does not return anything
C. function my Func(character Num, float me) // does not return anything
D. function my Func(integer Num, float me) // return an integer
Passage
function moify(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
{
15.Q) Consider the code given in the ‘Passage’. Assume that “a” and
“b” are passed by value. What will the output of the program be
when the function clculate () is executed?
A. 11 -5
B. 10 -5
C. 6 -5
D. 5 -5
Passage
function preordertraverse(node)
{
print node value
if (condition x)
{ preoedertraverse(node left)}
if condition y)
{ preordertraverse(node right)}
return
}
16.Q) Consider a binary tree implementation. The root address is
stored in the vatiable root. The address of a node is given in the
variable node. The value of the node and its right and left child
nodes can be accessed usina the statements given below.
node value,
node right,
node left.
A programmer writes the function given in the ‘Passage’ to do a
preorder traversal of the tree.
What are Condition X and Condition Y ?
A. Condition X: node left isnotequal
Condition Y: node right isnotequal
B. Condition X: node right isnotequal
Condition Y: node left isnotequal
C. Condition X: node left isequal
Condition Y: node right isequal
D. Condition X: node right isequal
Condition Y: node left isequal
17. Q) The following operations are performed on an
empity R “A”.
PUSH( 1)
PUSH (2)
POP
PUSH(5)
PUSH(6)
POP
What will the stack contain after these operations?
(Note: The top of the stack is underlined in the options
below.)
A. 5 6
B. 1 5
C. 5 6
D.1 5
18.Q) How may nodes does a full binary tree
with “n” non-leaf nodes contain?
A. log n
B. n + 1
C. 2n + 1
D. 2n
19.Q) A programmer mistakenly writes “gor”
instead of the keyword “for” used in loops.
While writing a program in C++. What will this
result in ?
A. Linear search
B. Binary search
C. Hash coded search
D. None of the above
21.Q) Which of the following abstract data
types can be used to represent a many-to-many
relation?
A. Tree
B. Stack
C. Graph
D. Queue
22.Q) Why is an algorithm designer concerned
primarily about the run time and not the compile time
while calculating time complexity of an algorithm?
A. 0
B. 1
C. Garbage Value
D. This code will generate a compile time error
24. Q) In which of the following methods is
sorting NOT possible?
A. Insertion
B. Selection
C. Exchange
D. Deletion
25.Q) Which of the following algorithm design
techniques is used in the quick sort algorithm?
A. Dynamic programming
B. Back tracking
C. Divide and conquer
D. Greedy search
26.Q) A programmer is making a database of
animals in a zoo along with their properties.
The possible animals are dog, lion and zebra.
Each one has attributes as herbivorous, color
and nocturnal. The programmer uses the object-
oriented programming parasigm for this. How
will the system be conceptualized?
A. Class: Animal; objects: lion and zebra;
data members: herbivorous, color and
nocturnal
B. Class: Animal; objects: herbivorous, color
and nocturnal; data members: dog, lion and
zebra
C. Classes: dog, lion and zebra; objects: Animal;
27.Q) The program to print the sum of all cubes that lie
between 0 and 100 is given below. Does this program have
an 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 (1<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
28.Q) What is the output of the pseudocode statements
given below?
(Note: Assume that when two data types are processed
through an operator, the answer maintains the same
data type as that of the input. Also, all data types have
enough range to accommodate any number. If two
different data types are operated upon, the result
assumes the data type that is ore expressive.)
integer a = 984, b=10
//float is a data type to store real numbers.
float c
c=a/b
print c
A.984
B. 98.4
C. 98
D. Error
29.Q) Code a contains a set of eight lines that occur ten times
in different points of the program. This code is passed to a
programmer who puts the set of eight lines in a function
definition and calls them at the ten points in the program.
Assume this new code to be Code B. Which code will run
faster using an interpreter?
Code A
Code B
Both the codes would run at the same speed
None of the above
Passage
function MyFunc 1(integer n)
{
return n*2
}
function MyFunc2(integer n)
{
print “The value is “ n
}
30.Q) Which of the given two functions can be
categorized as procedure?
A. My Func 1
B. My Func 2
C. Both MyFunc1 and MyFun2
D. A function cannot be a procedure
31.Q) Which of the following statements is
TRUE about a breadth first search?
For i= m to n increment 2
{ print “Hello!”}
A. (n – m + 1)/2
B. 1 + (n – m)/2
C. 1 + (n – m )/2 if m is even, (n – m + 1)/2 if m is
odd
D. (n – m + 1)/2 if m is even, 1 + (n – m )/2 if m is
odd
34.Q) A data type is stored as a 6-bit signed
integer. Which of the following cannot be
represented by this data type?
A. -12
B. 0
C. 32
D. 18
35.Q) Consider the code given below. Assume that “a”
and “b” are passed by reference. What will the output
of the program be when the unction calculate() is
executed?
function modify(b,a)
{
return a – b
}
function calculate ()
{
Integer a = 5, b = 12, c
c = modify(a,b);
print c
}
A.7
B. -7
C. 8
36.Q) Each bucket in a Hash Table is the head of
______________.
A. A Heap
B. A Stack
C. An Array
D. A Queue
37.Q) A programmer implements a queue as a singly‐
linked list. He queue has “n” elements. What will be the
time complexity to ADD an element to the queue?
A. O(1)
B. O(log 2n)
C. O(n)
D. O(n log 2n)
passage
class entity
{
private:
integer a,b
public:
integer c
function entity () {a= 0; b=0}
function compare ( )
{if (a>b) return 1;
return 0
}
}
function main( )
{
entityn black
int value 2 = 5
value = black. compare() // Statement 1
black.c = value02 // Statement2
print black a // Statement 3
38.Q) Refer to the pseudocode 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.
datamemnername, respectively. Identify the
statement with an error.
A. Statement 1
B. Statement 2
C. Statement 3
D. Statement 4
E. None of the above
39.Q) What is the maximum number of edges
in an undirected graph with “n” vertices?
A. n*(n-1)/2
B. n*(n+1)/2
C. n*n
D. 2*n
40.Q)What will be returned if f(a,b) is called in the following
functions?
function g(int n)
{
if (n>0) return 1;
else return ‐1;
}
function f(int a, int b)
{
if (a>b) return g(a‐b);
if (a<b) return g(‐b+a);
return 0;
}
A. Always +1
B. 1 if a>b, ‐1 if a<b, 0 otherwise
C. ‐1 if a>b, ‐1 if a<b, 0 otherwise
D. 0 if a equals b, ‐1 otherwise
41.Q) In the execution process of a program,
this technoque involves the intermediate
representation to be compiled to native
machine code at runtime. What is the name of
this technique?
A. Static compilation
B. Run time interpretation
C. Static interpretation
D. Just in time compilation
42.Q)Choose the correct answer.
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
43. Q) The following operations are performed
on an empty stack “A”.
PUSH( 1)
PUSH (2)
POP
PUSH(5)
PUSH(6)
POP
What will the stack contain after these
operations?
(Note: The top of the stack is underlined in the
options below.)
A. 5 6
B. 1 5
C. 5 6
44.Q) What will happen if some indentations
are made in some statements of a code written
in C++?
A. Tree
B. Stack
C. Graph
D. Queue
46.Q) A librarian has to rearrange 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’s ideal
choice?
A. Bubble sort
B. Insertion sort
C. Selection sort
D. Heap sort
47.Q)Tricha needs to store a list of binary data.
Which of the following data types should she
use?
A. Integer
B. Float
C. Character
D. Boolean
48.Q) A programmer writes an efficient program to add
two upper triangular 10X10 matrices with the elements
on the diagonals retained. How many total additions
will the program make?
A. 100
B. 55
C. 25
D. 10
49.Q) A problem to be solved is broken into a
sequence of smaller sub-problems until a stage
where the sub-problem can be easlved. What is
this design approach called?
A. Top-Down approach
B. Bottom-Up approach
C. Procedural programming
D. None of the above
50.Q)Consider an array on which bubble sort is
used. To which of the following elements will
the bubble sort compare the element A[X] with,
in a single iteration?
A. A[x + 1]
B. A[x + 2]
C. A[x + 2x]
D. All of the above
A. 40
B. 8
C. 70
D. 30
A. top<N-1
B. top<N
C. top>1
D. top>=0
54.Q) What is the difference between a function
and a method?
A. Statement 1
B. Statement 2
C. Statement 3
D.Statement 4
57.Q) A developer writes the program given below to
print the sum of the squares 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
A. No error, the program is correct
B. Statement 1
C. Statement 4
D. Statement 6
A. 1105
B. 1060
C. 1160
D. 1085
62.Q) What is implied by the argument of a
function?
A. 2n + 1 nodes
B. log 2n nodes
C. 2n – 1 nodes
D. 2n nodes
A. Selection sort
B. Insertion sort
C. Heap sort
D. Quick sort
A. Compiler
B. Decompiler
C. Interpreter
D. Executer
E. Cross compiler
66.Q)A programmer prepares a questionnaire
with “true or false” type of questions. He wants
to define a data type that stores the responses
of the candidates for the questions. Which of
the following is the most suited data type for
this purpose?
A. Integer
B. Boolean
C. Float
D. Character
67.Q) Which of the following is NOT a data type?
A. Integer
B. Character
C. Boolean
D. Array
A. n*(n-1)/2
B. n*(n+1)/2
C. n*n
D. 2*n
A. 4
B. 5
C. 6
D. 7
73.Q) Which of the following sorting algorithms
yields approximately the same worst-case and
average-case running time behavior in O(n
logn)?
A. 2 I-1
B. 3 I-1
C. 2I
D. 2I -1
Passage
Integer num 1, num2
Input num1, num2
Integer k=0, final=num1
//missing statements
Print final
Choose the correct answer:
A pseudo-code is used which is self explanatory.
//in pseudo code refers to comment
77.Q)Reema wanted to multiply two numbers but the * key of her
keyboard is broken. She decides to write the program without
using * operator. She writes the given code, where some
statements are missing.
What should be the missing statements in the given code?
A. While(k++ < num1)
final+=num1
B. While(k++ < num2-1)
final+=num1
C. While(k++ < num2)
final+=num1
D. While(k++ < num2)
final+=num2
78Q) The program to print the sum of all cubes that lie between 0
and 100 is given below. Does this program have an 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 (1<100) // Statement 2
{
sum = sum + a // Statement 3
i=i+1
a = (i * i * i ) // Statement 4
}
printsum
A. Statement 1
B. Statement 2
C. Statement 3
D. Statement 4
E. No error
A. Radix search
B. Breadth first search
C. Recursion
D. None of the above
A. Only 1
B. Only 2
C. Only 3
D. Both 1 and 2
E. Both 1 and 3