Sample-Questions_Computer-Programming_741
Sample-Questions_Computer-Programming_741
Computer Programming
Q1. A programmer is given an efficient code to sum two nXn matrices and store the result in a
third matrix. She is asked to find its time complexity. She realizes that the number of iterations
required is more than n. What can she claim regarding the complexity of the code?
A. It is O(n)
B. It is O(n2)
C. It is Θ(n)
D. It is ω(n)
integer i = 0, j
while (i<2)
{
j = 0;
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
}
Q3. A programmer writes a program to find an element in the array A[5] with the elements: 8
30 40 45 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
Q4. Refer to the given pseudocode. 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 the error in it?
rcode
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