NEW
Font size
WorksheetsPseudo code Practice 1
Total questions: 10
Worksheet time: 20mins
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
5 5 5
Infinite loop
6 6 5
6 5 4
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
5
3
4
0
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?
5
3
1
2
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
8
7
9
2
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
0
2
7
15
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
5
26
13
2
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.
Only 1 and 3
Only 2 and 3
Only 1
Only 1 and 2
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.
Both 1 and 2 are true
Both 1 and 2 are false
Only 2 is true
Only 1 is true
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 ]
6
4
0
2
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
1 3 6 10 15
1 2 3 4 5
2 4 6 8 10
1 1 2 3 5
