Tuesday, October 20, 2015

Computer Programming Sample Questions


questionStatement
answerA
answerB
answerC
answerD
answerE
Shravanti writes the following program:
integer i = 0, j
while ( i < 2 )
{
j = 0;
while ( j <= 3*i )
print j
print <i>blank space</i>
 j = j + 3
}
print \takes the cursor to the next line
i = i + 1
What will be the output of the program?
0<br/>0 3
0 3<br/>0 3 6
0<br/>0 3 6<br/>0 3 6 9
0 3 6<br/>0 3 6 9<br/>0 3 6 9 12

Consider the following code: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
Assume that a and b were passed by value. What will be the output of the function calculate( ) ?
80
40
32
72

Smallest element of an array's index is called its
lower bound
range
upper bound
extraction

For a path to be Eulerian, which of the following conditions are necessary and sufficient?
Degree of each vertex in the graph should be even.
Degree of each vertex in the graph should be odd.
The graph should have even edges.
The graph should have odd edges.

A hash table can store a maximum of 10 records. Currently there are records in locations 1, 3, 4, 7, 8, 9, 10. The probability of a new record going into location 2, with a hash function resolving collisions by linear probing is
0.6
0.1
0.2
0.5

We have a max heap with n elements. We insert an element which is larger than all elements in the heap. Where will it be inserted?
Top of the heap
Bottom of the heap
Some where in between the heap.
Cannot be determined

A list is implemented as a singly linked link-list. The address of the first and last node are stored in variables <i>first</i> and <i>last</i>. Given the address of a node is given in the variable <i>node</i>, the element stored in the node can be accessed by the statement <i>node->data</i> and the address to the next node can be accessed by <i>node->next</i>. Yusuf writes the code to delete the first element from the linked-list. He writes the following function, where first and last are passed by reference.
function deleteElement(first, last)
 if (first isequal null
 { print "List empty" }
else
{
first = first->next
 }
}
In which of the following scenarios will the code not work properly?
When the list has no elements
When the list has a single element
When the list has two elements
It will work well in all possible cases.

Q is an empty queue. The following operations are done on it:
ADD 5
ADD 7
ADD 46
DELETE
ADD 13
DELETE
DELETE
ADD 10
What will be the content of Q after these operations. Front is marked by (F) and Rear is marked by (R).
10(R) 13(F)
5(R) 10(F)
13(R) 10(F)
10(R) 5(F)

Time complexity of linear search algorithm is
O (log n)
O (n)
O(n^2)
O(1)

Postfix form of ((A + B) * C - (D - E) ^ (F + G)) is
AB + C * DE - FG + ^ -
AB + C * DE - F - G + ^
ABC + * DE - - FG + ^
^ - * +ABC - DE + FG

No comments:

Post a Comment