Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PSUEDOCODE 2 CAPGEMINI

Total questions: 25

Worksheet time: 25mins

Name
Class
Date
1.

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+2

c)

2n+4

d)

2n

2.

Question: Point out the error in the program?

#include<stdio.h>

int main()

{

char ch;

int i;

scanf("%c", &i);

scanf("%d", &ch);

printf("%c %d", ch, i);

return 0;

}

a)

Error: suspicious char to in conversion in scanf()

b)

Error: we may not get input for second scanf() statement

c)

No error

d)

None of above

3.

Question: Consider the following iterative implementation to find the factorial of a number:

int main()


{

int n = 6, i;

int fact = 1;

for(i=1;i<=n;i++)

_________;

printf("%d",fact);

return 0;

}

Which of the following lines should be inserted to complete the above code?

a)

fact = fact + i

b)

fact = fact * i

c)

i = i * fact

d)

i = i + fact

4.

Question: What is the output of this C code?

#include <stdio.h>


int main()

{

int i=12;

int *p =&i;

printf(“%d\n”,*p++);

}

a)

Address of i++

b)

12

c)

Garbage value

d)

Address of i

5.

Question: Convert the following 211 decimal number to 8-bit binary?

a)

11011011

b)

11001011

c)

11010011

d)

11010011

6.

Question: A NAND gate has:

a)

LOW inputs and a HIGH output

b)

LOW inputs and a LOW output

c)

HIGH inputs and a HIGH output

d)

None of these

7.

Question: Comment on the output of this C code?

#include <stdio.h>

int main()

{

int a = 1;

switch (a)

case 1:

printf("%d", a);

case 2:

printf("%d", a);

case 3:

printf("%d", a);

default:

printf("%d", a);

}

a)

No error, output is 1111

b)

No error, output is 1

c)

Compile time error, no break statements

d)

Compile time error, case label outside switch statement

8.

Question: How will you find the maximum element in a binary search tree?

a)

a)

public void max(Tree root)

{

while(root.left() != null)

{

root = root.left();

}

System.out.println(root.data());

}

b)

b)

public void max(Tree root)

{

while(root != null)

{

root = root.left();

}

System.out.println(root.data());

}

c)

c)


public void max(Tree root)


{

while(root.right() != null)

{ root = root.right();

}


System.out.println(root.data());

}

d)

d)

public void max(Tree root)

{

while(root != null)

{

root = root.right();

}

System.out.println(root.data());

}

9.

Question: What is the output of the following code?void my_recursive_function(int n)

{

if(n == 0)

return;

printf("%d ",n);

my_recursive_function(n-1);

}

int main()

{

my_recursive_function(10);

return 0;

}

a)

10

b)

1

c)

10 9 8 … 1 0

d)

10 9 8 … 1

10.

For input a = 8 & b = 9.


function (input a, input b)


If (a < b)


return function (b, a)


elseif (b != 0)


return (a + function (a, b - 1))


else


return 0

a)

56

b)

78

c)

82

d)

72

11.

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

12.

Input f = 6, g = 9 and set sum = 0


Integer n if (g > f)


for (n = f; n < g; n = n + 1)


sum = sum + n


End for loop


else


print error message print sum

a)

21

b)

15

c)

9

d)

6

13.

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,1

b)

3,3,1

c)

4,0,1

d)

3,0,2

14.

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)

O(logn)

d)

O(n3)

15.

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(n2)

b)

O(nlogn)

c)

O(logn)

d)

O(n3)

16.

Let P be a Quick Sort Program to sort numbers in ascending order using the first element as a pivot. Let t1 and t2 be the number of comparisons made by P for the inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which one of the following holds?

a)

t1=5

b)

t1>t2

c)

t1<t2

d)

t1=t2

17.

public void func (Tree root)


{


func (root.left ());


func (root.right ());


System.out.println (root.data ());


}

a)

preorder traversal

b)

postorder traversal

c)

inorder traversal

d)

level order traversal

18.

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

a)

a) public void min (Tree root)


{


while (root.left () != null)


{


root = root.left ();


}


System.out.println (root.data ());


}

b)

b) public void min (Tree root)


{


while (root != null)


{


root = root.left ();


}


System.out.println (root.data ());


}

c)

c) public void min (Tree root)


{


while (root.right () != null)


{


root = root.right ();


}


System.out.println (root.data ());


}

d)

d) public void min (Tree root)


{


while (root != null)


{


root = root.right ();


}


System.out.println (root.data ());


}

19.

What will be the output of the following pseudocode?


Integer i

Set i = 3

do

print i + 3

i = i - 1

while(i not equals 0)

end while


[Note: A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the given Boolean condition at the end of the block]

a)

A) 6 6 6

b)

B) 6 5 6

c)

C) 5 5 5

d)

D) 6 5 4

20.

What would be the output of the following pseudocode?


Integer a

String str1

Set str1 = “goose”

a = stringLength(str1)

Print (a ^ 1)


[Note- string-length(): string-length() function counts the number of characters in a given string and return the integer value.

^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of its equal operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0]

a)

A) 0

b)

B) 4

c)

C) 5


d)

D) 3

21.

What will be the output of the following pseudocode?


Integer a, b

Set a = 15, b = 7

a = a mod (a - 3)

b = b mod (b – 3)

a = a mod 1

b = b mod 1

Print a + b

a)

A) 15

b)

B) 7

c)

C) 2

d)

D) 0

22.

What will be the output of the following pseudocode?


Integer a, b, c

Set b = 5, a = 2, c = 2

if(b>a && a>c && c>b)

b = a + 1

Else

a = b + 1

End if

Print a + b + c


[Note-&&: Logical AND - The logical AND operator (&&) returns the Boolean value true(or 1) if both operands--. If (x) gets executed if the value if(), i.e., x is not zero]

a)

A) 2

b)

B) 13

c)

C) 26

d)

D) 5

23.

For which of the following applications can you use hashing?

1. To construct a message authentication code.

2. For Timestamping

3. For detecting a cycle in a graph

Choose the correct answer from the options given below.

a)

A. Only 1 and 3

b)

B. Only 2 and 3

c)

C. Only 1

d)

D. Only 1 and 2

24.

Consider an array of float. Calculate the difference between the address of the 1st and 4th element, assuming float occupies 4 bytes of memory.

a)

A. 16

b)

B. 4

c)

C. 12

d)

D. 8

25.

What is the second part of a node in a linked list that contains the address of the next node called?

a)

A. data

b)

B. pointer

c)

C. element

d)

D. Link