MCQs
MCQs
The
possible animals are dog, lion and zebra. Each one has as attributes isHerbivorous,
colour and isNocturnal. She uses the object oriented programming paradigm for this.
How will she conceptualize the system?
(a) class: Animal; objects: dog, lion and zebra; data members: is Herbivorous,
colour and is
Nocturnal
(b)class: Animal; objects: is Herbivorous, colour and is Nocturnal; data
members: dog, lion and zebra
(c)classes: dog, lion and zebra; objects: Animal; data members: is Herbivorous,
colour and is
Nocturnal
d)None of these
Ans a)class: Animal; objects: dog, lion and zebra; data members: is Herbivorous,
colour and is
Nocturnal
class is a template(logical entity) , objects are instances of class(real entity).
2. A programmar mistakenly uses the ‘for’ keyword for loops. Due to distraction
Ravi writes ‘gor’ instead of ‘for’. What will this result to?
A. Bubble Sort
B. Insertion Sort
C. Selection sort
D. Heap Sort
4. A programmar 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
options will be an efficient way of debugging?
A. Compile the whole code and step into it line by line
B. Use an interpreter on the first 25 lines
C. Compile the whole code and run it
D. None of these
function sum( n )
{
if(??)
return 1
else
return (n + sum(n-1))
end
}
Fill in ?? in the code.
Option 1 : n equals 1
Option 2 : n equals 2
Option 3 : n >= 1
Option 4 : n > 1
Ans:: Option 1
function sum( n )
{
if(n equals 2)
return 2
else
return (n + sum(n-2))
end
}
It calls the function by the statement, sum(30). How many times will the function
sum be called to compute this sum.
Option 1 : 1
Option 2 : 30
Option 3 : 15
Option 4 : 16
Choose the correct answer. A pseudo-code which is similar to that of C++ and self-
explanatory. An accessible member function or data member for an object are
accessed by the statement
Objectname.functionname or objectname.datamembername respectively.
a) Statment1
b) Statment2
c) Statment3
d) Statment4
Ans:: d
Explaination : Since, get data is private
8. A data type is stored as an 6 bit signed integer. Which of the following cannot
be
represented by this data type?
A. 22
B. 11
C. 10
D. None of these
Ans::: B
10.A stack is implemented as a linear array A[0…N-1]. Noor writes the following
functions for popping an element from the stack.
function POP( top, N )
{
if(X)
{
top = top – 1
}
else
{
print “Underflow”
}
return top
}Fill in the condition X
Option 1 : top< N-1 Option 2 : top Option 3 : top>1 Option 4 : top >= 0
Ans:: option 4
A. 42
B. 18
C. 20
D. 21
Ans:: B. 18
A. 411.4
B. 411
C. 410.4
D. 410
Ans:: B
Ans:: Option 3
14. A programmer wants to find the largest number in a given list of 20 numbers.
Which of the
following is an efficient approach to do this?
Option 1 : Use bubble sort to sort the list in descending order and then print the
first number of the series.
Option 2 : Use selection sort to sort the list in descending order and then print
the first number of the series.
Option 3 : Implement one iteration of selection sort for descending order and print
the first number in the series.
Option 4 : None of these
Ans:: Option 3
Option 1 : 2n + 1 nodes
Option 2 : log2 n nodes
Option 3 : 2n – 1 nodes
Option 4 : 2n nodes
Ans:: Option 3
integer i = 1 // statement 1
while ( i <= 3 )
{
int j // Statement 2
while ( j <= i ) // Statement 3
{
print j
print blank space
j = j + 1 // Statement 4
}
print end-of-line \takes the cursor to the next line
i = i + 1
}
Will this program function correctly? If not which one statement will you modify to
make the program function correctly?
Option 1 : Statement 1
Option 2 : Statement 2
Option 3 : Statement 3
Option 4 : Statement 4
Option 5 : Program does not have error.
Ans:: Option 2
17. A programmer writes an efficient program to sum two square diagonal matrices
(matrices with
elements only on diagonal). The size of each matrix is nXn. What is the time
complexity
of Vrinda's algorithm?
Ans:: Option 2
A. Public
B. Private
C. Protected and Private
D. Protected
Ans:: B
1. Protected
2. Public
3. Private
4. None of these
Ans:: 3
20. 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.
Option 1 : A [x+1]
Option 2 : A [x+2]
Option 3 : A [x+2x]
Option 4 : All of these.
Ans:: Option 1
21. A sorting algorithm iteratively traverses through a list to exchange the first
element
with any element less than it. It then repeats with a new first element. What is
this
sorting algorithm called?
Ans:: Option 2
22. 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?
Option 1 : 40
Option 2 : 8
Option 3 : 70
Option 4 : 30
Ans:: Option 1
23. wants to make a program to print the sum of all perfect cubes, where the value
of the cubes go from 0 to 100. She writes the following 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
Does this program have an error? If yes, which one statement will you modify to
correct
the program?
Option 1 : Statement 1
Option 2 : Statement 2
Option 3 : Statement 3
Option 4 : Statement 4
Ans:: Option 2
24. A programmer wants to make a program to print the sum of square of the first 5
whole numbers
(0...4). She writes the following 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
Is her program correct? If not, which statement will you modify to correct it?
Ans:: Option 3
25. 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.
integer a = 40, b = 35, c = 20, d = 10
Comment about the output of the following two statements:
print a * b / c – d
print a * b / (c - d)
Option 1 : Differ by 80
Option 2 : Same
Option 3 : Differ by 50
Option 4 : Differ by 160
Ans:: Option 1
Ans:: Option 2
27. Two programmers 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?
Option 1 : Code A uses lesser memory and is slower than Code B
Option 2 : Code A uses lesser memory and is faster than Code B
Option 3 : Code An uses more memory and is faster than Code B
Option 4 : Code A uses more memory and is slower than Code B
Ans:: Option 1
28.
While calculating time complexity of an algorithm, the designer concerns
himself/herself primarily with the run time and not the compile time. Why?
Ans:: Option 4
29. Which of the following sorting algorithms yield approximately the same worst-
case and
average-case running time behaviour in O (n log n)?
Ans:: Option 2
A. Integer
B. Character
C. Boolean
D. Array
Ans:: D.
31. Two programmes 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):
Option 1 : Code A will execute faster than Code B.
Option 2 : Code B will execute faster than Code A
Option 3 : Code A is logically incorrect.
Option 4 : Code B is logically incorrect.
Ans:: Option 2
A. Insertion
B. Selection
C. Exchange
D. Deletion
Ans:: D
33. The algorithm design technique used in the quick sort algorithm is
Option 1 : Dynamic programming
Option 2 : Back tracking
Option 3 : Divide and conquer
Option 4 : Greedy Search
Ans:: Option 3
34. The maximum number of nodes on level I of a binary tree is which of the
following?
(Root is Level 1)
Option 1 : 2^(l-1)
Option 2 : 3^l-1
Option 3 : 2^l
Option 4 : 2^l – 1
Ans:: Option 1
1. Data members
2. Member functions
3. Constructor and destructor
4. Data members and member functions
Ans:: 4
36. How many nodes does a binary tree with n non leaf nodes contain?
1. Log n
2. N+1
3. 2n+1
4. 2n
Ans:: 3
Ans:: Option 1
38. A language has 28 different letters in total. Each word in the language is
composed of maximum 7 letters. You want to create a data-type to store a word of
this language. You decide to store the word as an array of letters. How many bits
will you assign to the data-type to be able to store all kinds of words of the
language.
Op 1: 7
Op 2: 35
Op 3: 28
Op 4: 196
Op 5:
Ans :: Op : 2
39. A programmer X writes a piece of code, where a set of eight lines occur around
10 times in different parts of the program (Code
A). X passes on the code to Programmer Y. Y 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?
Option 1 : Code A
Option 2 : Code B
Option 3 : Code A and Code B will run with the same speed
Option 4 : None of these
Ans:: Option 1
for i= m to n increment 2
{ print "Hello!" }
Assuming m < n and exactly one of (m,n) is even, how many times will Hello be
printed?
Option 1 : (n - m + 1)/2
Option 2 : 1 + (n - m)/2
Option 3 : 1 + (n - m)/2 if m is even, (n - m + 1)/2 if m is odd
Option 4 : (n - m + 1)/2 if m is even, 1 + (n - m)/2 if m is odd
Ans:: Option 1
41. What is the function used to describe the situation, when a function in base
class is redefined in inherited class?
a.Inheritance
b.Overriding
c.Overloading
d.Encapsulation
Answer:: Option b
A. The data and operation for an object are defined and fixed.
B. The data of an object is encapsualted in its class.
C. The data is hidden for an object..
D. A class have multiple objects.
43. A Programmer writes an efficient program to add two upper triangular 10X10
matrices (elements on diagonal retained). How
Option 1 : 100
Option 2 : 55
Option 3 : 25
Option 4 : 10
Ans-option 2
Ans:: Option B
45. What is the output of the following code statements? The compiler saves the
first integer
at the memory location 4165 and the rest at consecutive memory spaces in order of
declaration. Integer is one byte long.
integer a, b
pointer c, d
a = 30
c = &a
b = *c
a = a + 10
print b
46. Which of the given statements is TRUE about a "bipartite graph" with "n" nodes?
A. It contains n edges.
B. It contains a cycle of odd length.
C. It contains no cycle of odd length.
D. It contains n2 edges.
Ans:: Option C
47. A programmer is given two codes, A and B, to solve a problem, which have
complexity θ(n3)
and ω(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?
Option 1 : Code A
Option 2 : Code B
Option 3 : Both codes have the same execution time, so deliver any.
Option 4 : None of these
Ans:: Option 1
48. Which of the given statement is true about Breadth First Search??
A. Beginning from a node all tha adjascent nodes are traversed first.
B. Beginning from a node, each adjacent node is fully explored before traversing
the next adjacent node
C. Beginning from a node, the nodes are traversed in cyclic order
D. None of the above
Ans:: Option A
Ans:: Option B
Ans:: Option 3
Option 1 : 0 to 1000
Option 2 : 0 to 1024
Option 3 : 1 to 1025
Option 4 : 0 to 1023
Ans:: Option 4
52. Identify the lower level format to which the computer converts a program in a
higher language before it executes
A. English code
B. Machinde Code
c. Assembly language
D. System language
Ans:: Option 2
53. A programmer writes a code snippet in which set of the three lines occurs 10
times in different pathway program what program concept should be used to shorten
the code length??
A. For loops
B. Functions
C. Arrays
D. Classes
Ans:: B. Functions
54. Consider a binary tree implementation. The root address is stored in variable
root. Given the address of a node is variable node, its value, right and root could
node address can be accessed using the following statements respectively node->
value ,node -> right, node-> left. Srikanth writes the following function to do a
preorder traversal of the tree.
function preordertraverse(n0de)
{
print node -> value
if(Conditon X)
{
preordertraverse(node ->left)
}
if(Condition Y)
{
preordertraverse(node ->right)
}
return
}
What is the Condition X and Condition Y ?
a. Condition X: node -> left is not equal null
b. Condition X: node -> right is not equal null,Condition Y:node -> right is not
equal null,Condition Y:node -> left is not equal null
c. Condition X: node -> left is equal null
d. Condition X: node -> right is equal null, Condition Y:node -> right is equal
null, Condition Y:node -> left is equal null.
Ans.A
55. What will happen if some indentations are made in some statements of a code
written in C++?
Ans:: Option D
56. . In an implementation of a linked list, each node contains data and address.
Which of the following could the address field possibly contain?
Op 1: Address of next node in sequence
Op 2: It's own address
Ans:: Op : 1
57. A sorting algorithm traverses through a list, comparing adjacent elements and
switching them under certain conditions. What is this sorting algorithm called?
Option 1 : insertion sort
Option 2 : heap sort
Option 3 : quick sort
Option 4 : bubble sort
Ans:: Option 4
function POP(top,N)
{
if(X)
{
top=top-1;
}
else
{
print "Underflow"
}
return top;
a. top<N-1
b. top<N
c. top>1
d. top>=0
Ans:: option d
60. 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 method called?
A. selection sort
B. insertion sort
C. heap sort
D. quick sort
Ans:: Option C
61. Which of the following data structure may give overflow error,even though the
current number of element in it is less than its size?
A. Simple queue
B. Circular queue
C. Priority Queues
D. None of these
Ans:: Option B
62. How are protected members of a base can be inherited in the derived class?
A. Privately
B. Publicly
C. Protectedly
D. Not inherited.
Ans:: A
63. A programmer writes a sorting algorithm. The algorithm takes different amount
of time to sort two different lists of equal size. What is the possible difference
between the two lists?
A. All numbers in one more list are more than 100, while in other are less
than 100.
B. The ordering of numbers with respect to magnitude in two lists has different
properties.
C. One list has all negative numbers, while the other has all positive numbers.
D. One list contains 0 as element, while the other does not.
Ans. B
64. A programmer wants to program to print the largest number out of three inputted
numbers.
She writes the following program:
Ans:: Option 2
65.
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;
}
Option 1 : Always +1
Option 2 : 1 if a > b, -1 if a < b, 0 otherwise
Option 3 : -1 if a > b, 1 if a < b, 0 otherwise
Option 4 : 0 if a equals b, -1 otherwise
Ans:: Option 2
Ans:: Two or more functions with same but different parameter list different with
type of argument.
Class rocket
{
Private:
integer height,weight
public: //statement 1
function input(int a,int b)
{
height=a;
weight=b;
}
}
function main()
{
rocket rocket 1,rocket2
}
What can we infer from this code?
Choose the correct answer. A pseudo-code which is similar to that of c++ and self-
explanatory. An accessible member function or data member for an object are
accessed by the statement object name, function name or object name data member
name respectively.
Ans- A
69. 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??
Ans:: Option D
Ans:: Option 1
71. In an implementation of a linked list, each node contains data and address.
What can the address field possibly contain?
Ans::
Option 1 : Address of next node in sequence
PUSH(1)
PUSH(2)
POP
PUSH(5)
PUSH(6)
POP
Ans:: Option B
73.
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 ( )
{
entity black
int value, value2 = 5
value = black.compare( ) // Statement 1 black.c = value2 //Statement 2
print black.a //Statement 3
}
Choose the correct answer. A pseudo-code which is similar to that of C++ and self-
explanatory. An accessible member function or data member for an object are
accessed by the statement objectname.functionname or objectname.datamembername
respectively.
(a)Statement 1 (b)Statement 2 (c)Statement 3 (d)None of these
Ans:: Option c
74. Which of the given options will create an object named pigeon of the class Bird
in c++?
A. pigeoon birs
B. bird pigeon
C. Object pigeon of bird
D. None of above