wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Pseudo code Practice 1

Total questions: 10

Worksheet time: 20mins

Name
Class
Date
1.

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

a)

5 5 5

b)

Infinite loop

c)

6 6 5

d)

6 5 4

2.

What would be the output of the following pseudocode?


Integer a

String str1

Set str1 = “goose”

a = stringLength(str1)

Print (a ^ 1)


Note: ^ is XOR operator

a)

5

b)

3

c)

4

d)

0

3.

Consider an array A = {1, 2, 4, 5, 6, 11, 12} and a key which is equal to 10. How many comparisons would be done to find the key element in the array using the binary search?

a)

5

b)

3

c)

1

d)

2

4.

What would be the output of the following pseudocode?


Integer i, j, k

Set k = 8

for(each i from 1 to 1)

for(each j from the value of i to 1)

print k+1

end for

end for

a)

8

b)

7

c)

9

d)

2

5.

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)

0

b)

2

c)

7

d)

15

6.

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

a)

5

b)

26

c)

13

d)

2

7.

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)

Only 1 and 3

b)

Only 2 and 3

c)

Only 1

d)

Only 1 and 2

8.

If you are using a Depth-first search (DFS) for traversing an unweighted graph, then which of the following will happen?


1. It produces the minimum spanning tree

2. It produces all pair shortest path tree


Choose the correct answer from the options given below.

a)

Both 1 and 2 are true

b)

Both 1 and 2 are false

c)

Only 2 is true

d)

Only 1 is true

9.

What will be the output of the following pseudocode?


Integer a, b, c

Set b = 2, a = 2

c = a ^ b

Print c

[Note- ^ is the bitwise exclusive OR operator ]

a)

6

b)

4

c)

0

d)

2

10.

Which of the following series will be printed by the given pseudocode?


Integer i, j, k, n

Set j=1, k=1

for(each i from 1 to 5)

print k

j=j+1

k=k+j

end for

a)

1 3 6 10 15

b)

1 2 3 4 5

c)

2 4 6 8 10

d)

1 1 2 3 5