Capgemini Pseudocodes MCQs Part 2

Capgemini Pseudo Code MCQs (previously asked)

Capgemini Pseudo Code MCQs Part 2


1) Which of the following will give the best performance?

a) O(n)
b) O(n!)
c) O(n log n)
d) O(n^C)

Ans: Option A

2)How many times the following loop be executed?
{
ch = b;
while(ch >= a && ch <= z)
ch++;
}

a) 0
b) 25
c) 26
d) 1

Ans: Option B

3) ) Consider the following piece of code.What will be the space required for this code?
int sum(int A[], int n)
{
int sum = 0, i;
for(i = 0; i < n; i++)
sum = sum + A[i];
return sum;
}
// sizeof(int) = 2 bytes

a) 2n + 8
b) 2n + 4
c) 2n + 2
d) 2n

Ans: Option A

4) What will be the output of the following pseudo code?
For input a=8 & b=9.
Function(input a,input b)
If(a return function(b,a)
elseif(b!=0)
return (a+function(a,b-1))
else
return 0

a) 56
b) 88
c) 72
d) 65

Ans: Option C

5)What will be the output of the following pseudo code?
Input m=9,n=6
m=m+1
N=n-1
m=m+n
if (m>n)
print m
else
print n

a) 6
b) 5
c) 10
d) 15

Ans: Option D

6) What will be the output of the following pseudo code?
Input f=6,g=9 and set sum=0
Integer n
if(g>f)
for(n=f;n sum=sum+n
End for loop
else
print error message
print sum

a) 21
b) 15
c) 9
d) 6

Ans: Option A

7)Consider a hash table with 9 slots. The hash function is h(k) = k mod 9. The collisions are resolved by chaining. The following 9 keys are inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are

a) 3, 0, and 1
b) 3, 3, and 3
c) 4, 0, and 1
d) 3, 0, and 2

Ans: Option A

8) You have an array of n elements. Suppose you implement a quick sort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is:

a) O(n2)
b) O(nLogn)
c) ?(nLogn)
d) O(n3)

Ans: Option A

9)Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time on Depth First Search of G? Assume that the graph is represented using adjacency matrix.

a)O(n)
b)O(m+n)
c)O(n2)
d)O(mn)

Ans: Option C

10)What does the following piece of code do? public void func(Tree root) { func(root.left()); func(root.right()); System.out.println(root.data()); }

a)Preorder traversal
b)Inorder traversal
c) Postorder traversal
d)Level order traversal

Ans: Option C

11) How will you find the minimum element in a binary search tree?

a) public void min(Tree root)
{
while(root.left() != null)
{
root = root.left();
}
System.out.println(root.data());
}
b) public void min(Tree root)
{
while(root != null)
{
root = root.left();
}
System.out.println(root.data());
}
c) public void min(Tree root)
{
while(root.right() != null)
{
root = root.right();
}
System.out.println(root.data());
}
d) public void min(Tree root)
{
while(root != null)
{
root = root.right();
}
System.out.println(root.data());
}

Ans: Option A

Comments

Popular posts from this blog

Capgemini Analyst Interview Experience | Experience 2

Capgemini Pseudocode Question Asked on 19th december 2021 | slot 2