Write A Pseudocode To Find The Largest of Two Numbers
Write A Pseudocode To Find The Largest of Two Numbers
2. WRITE
A PSEUDOCODE TO FIND THE SUM OF TWO
NUMBERS.
begin
numeric nNum1,nNum2,nSum
accept nNum1
accept nNum2
compute nSum=nNum1+nNum2
end
numeric nLen,nBrd,nAre
accept nLen
accept nBrd
nAre=nLen*nBrd
end
4. WRITE A PSEUDOCODE TO FIND THE AREA OF SQUARE.
begin
accept nSide
nArea=nSide*nSide
end
accept nRad
nArea = nRad*nRad*22/7
end
accept nBase
accept nPerp
nArea=nBase*nPerp
end
accept nHigh
nArea=nBase*nHigh
end
accept nDgn1
accept nDgn2
nArea=nDgn1*nDgn2/2
end
accept nNum1
accept nNum2
if(nNum1>nNum2)
begin
end
else
begin
end
end
accept nNum1
accept nNum2
nGone=(nNum1>nNum2)?nNum1:nNum2
end
numeric nNum1,nNum2,nNum3
accept nNum1
accept nNum2
accept nNum3
if(nNum1>nNum2)
begin
if(nNum1>nNum3)
begin
end
else
begin
end
end
else
if(nNum2>nNum3)
begin
end
else
begin
end
Capgemini Questions with Answers
Pseudocode Questions and Answers
ALGORITHMS
1. What will be the output of the following pseudo code?
Note- &: bitwise AND - The bitwise AND operator (&) compares each bit of the first operand to the
corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. 6
B. 24
C. 7
D. 11
Answer: C
A. 22
B. 18
C. 31
D. 13
Answer: B
P a g e 5 | 17
3. What will be the output of the following pseudocode?
Answer: A
A. 96
B. 15
C. 33
D. 26
Answer: B
5. What will be the output of the following pseudocode for a=2, b=7, c=7?
A. 26
B. 14
C. 16
D. 18
Answer: C
6. What will be the output of the following pseudocode for p=7, q=2?
P a g e 6 | 17
A. 20
B. 2
C. 12
D. 3
Answer: D
Note- &: bitwise AND - The bitwise AND operator (&) compares each bit of the first operand to the
corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. 88
B. 59
C. 69
D. 74
Answer: C
8. What will be the output of the following pseudocode for a=8, b=1?
P a g e 7 | 17
Note- &&: Logical AND - The logical AND operator (&&) returns the Boolean value true(or 1) if both
operands are true and return false (or 0) otherwise.
A. 11
B. 25
C. 16
D. 18
Answer: C
A. 18
B. 13
C. 22
D. 31
Answer: A
Note- ^ is the bitwise exclusive OR operator that compares each bit of its first operand to the
corresponding bit of the 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. 55
B. 40
P a g e 8 | 17
C. 46
D. 43
Answer: D
11. What will be the output of the following pseudocode for a=8, b=1?
Note- &: bitwise AND - The bitwise AND operator (&) compares each bit of the first operand to the
corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. -1
B. 8
C. 2
D. 1
Answer: B
Note- ^ is the bitwise exclusive OR operator that compares each bit of the first operand to the
corresponding bit of its second operand. If one bit is 0, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. 59
B. 56
C. 65
D. 53
Answer: A
P a g e 9 | 17
13. What will be the output of the following pseudocode?
Note: countVowel(string) returns the number of vowels in the string, e.g. countVowel(“okay”)
returns 2. lower(string) converts all the letters of the string to lower case, e.g. lower(“OkaY”) returns
“okay”.
A. 12
B. 7
C. 0
D. 4
Answer: D
DATA STRUCTURES
1. Which of the following statements is incorrect for Linked list data structure?
A. Memory allocation from Heap
B. Memory allocation from stack
C. Size is not fixed.
D. It occupies more memory than array.
Answer: B
2. If you are using Bubble sort for sorting the given numbers in ascending order, then find out the
number of swapping needed.
12, 16, 10, 7, 13, 3, 9
A. 14
B. 16
C. 12
D. 15
Answer: D
3. Find out the array representation of the given max heap, if the value 25 is inserted in it.
28,17,16,15,14
A. 28,25,17,16,15,14
B. 25,28,17,15,16,14
C. 14,15,16,17,25,28
D. 28,17,25,15,14,16
Answer: D
5. If you are using Bubble sort for sorting the given numbers in ascending order, then find out the
number of swapping needed.
3,10,4,7,9,2,6
A. 12
B. 14
C. 11
D. 8
Answer: C
8. If you are using bubble sort for sorting the given numbers in ascending order, then find out the
number of swapping needed.
9,23,8,10,32,6,14
A. 9
B. 12
C. 10
D. 11
Answer: C
9. Find out the array representation of the given max heap, if the value 20 is deleted from it.
22,21,20,19
A. 21,22,19
B. 22,21,19
C. 19,21,22
P a g e 11 | 17
D. 21,19,22
Answer: B
10. If we draw a binary search tree by inserting the given numbers from left to right. then what would
be the height of the BST?
1,4,3,5,7,9
A. 5
B. 4
C. 3
D. 2
Answer: A
13. Find out the array representation of the given min-heap, if the value 110 is inserted in it.
1,2,3,17,19,36,7,25,100
A. 1,3,2,17,19,36,7,110,100,25
B. 1,2,3,17,1,36,9,7,110,100,25
C. 1,2,3,17,19,36,7,25,100,110
D. 1,2,3,17,19,36,7,110,100,25
Answer: C
14. Find out the array representation of the given min heap, if the value 2 is deleted from it.
1,2,3,4
A. 1,4,3
B. 1,3,4
C. 4,3,1
D. 3,4,1
Answer: A
P a g e 12 | 17
3. Trees
A. 1 and 2
B. All 1, 2, and 3
C. 1 and 3
D. 2 and 3
Answer: B
16. Which of the following statements is/are correct for Double Linked List?
1. All the nodes have two links
2. Provides bidirectional traversing
3. Provides only unidirectional traversing
A. 1 and 3
B. 1 and 2
C. Only 3
D. Only 1
Answer: B
17. If you are using Bubble sort for sorting the given numbers in ascending order, the find out the
number of swapping needed.
2,9,3,6,8,1,5
A. 10
B. 12
C. 11
D. 13
Answer: C
P a g e 13 | 17
20. If there is a binary tree of height 8, then what should be the maximum number of nodes in that
tree?
A. 511
B. 255
C. 256
D. 512
Answer: B
21. If the base address of two dimensional array A[80] [20] is 700, then find out the address of an
element a[1][8] in the array.
** Assume 4 words per memory cell and elements are arranged in column major order.
A. 3245
B. 3264
C. 6543
D. 3456
Answer: B
22. If the base address of two dimensional array A[70] [10] is 600, then find out the address of an
element A[2][7] in the array.
** Assume 4 words per memory cell and elements are arranged in column major order.
A. 2658
B. 2543
C. 2568
D. 2345
Answer: C
24. How many nodes are present in a strictly binary tree with 8 leaves?
A. 7
B. 15
C. 16
D. 17
Answer: B
25. Find out the maximum number of nodes present in a binary tree of height 5.
A. 16
P a g e 14 | 17
B. 32
C. 15
D. 31
Answer: D
26. If the base address of two dimensional array A[30] [50] is 500, then find out the address of an
element A[5][10] in the array.
** Assume 4 words per memory cell and elements are arranged in row major order.
A. 1189
B. 1124
C. 1160
D. 1540
Answer: D
27. If we draw a binary search tree by inserting the given numbers from left to right, then what would
be the height of the BST?
11, 13, 12, 14, 10, 9
A. 2
B. 5
C. 4
D. 3
Answer: C
28. If we draw a binary search tree by inserting the given numbers from left to right, then what would
be the height of the BST?
12, 13, 16, 10, 9, 7
A. 4
B. 2
C. 5
D. 3
Answer: A
29. Find out the maximum number of nodes present in a tree of height 6.
A. 31
B. 63
C. 64
D. 32
Answer: B
30. Find out the array representation of the given min-heap, if the value 10 is inserted in it.
5, 6, 9, 17, 18
A. 5, 6, 9, 10, 17, 18
B. 5, 6, 9, 17, 18, 10
C. 6, 9, 5, 17, 18, 10
P a g e 15 | 17
D. 9, 5, 6, 17, 18, 10
Answer: B
31. Which of the following is the correct order of the nodes visited during an in-order traversal of the
given noded tree?
A. B-D-A-G-E-C-H-I-G
B. B-D-A-G-E-C-H-F-I
C. D-B-A-G-E-C-H-F-I
D. D-B-A-G-E-C-H-I-F
Answer: B
32. Which of the following statements is/are TRUE for array data structure?
A. Memory allocation from stack.
B. Memory allocation from Heap
C. All of the mentioned options
D. Size is not fixed.
Answer: A
33. Which of the following is the correct post-order traversal of the given tree?
A. 1 2 4 5 3
B. 4 5 2 3 1
C. 1 2 3 4 5
P a g e 16 | 17
D. 4 2 5 1 3
Answer: B
34. Find out the sum of the degree of vertices in the pseudograph as shown in the image.
A. 12
B. 6
C. 11
D. 8
Answer: C
35. If the base address of two dimensional array A[10] [20] is 100, then find out the address of an
element A[2][6] in the array.
** Assume 4 words per memory cell and elements are arranged in row major order.
A. 286
B. 284
C. 245
D. 278
Answer: B
P a g e 17 | 17
Pseudocode questions
2. WRITE
A PSEUDOCODE TO FIND THE SUM OF TWO
NUMBERS.
begin
numeric nNum1,nNum2,nSum
accept nNum1
accept nNum2
compute nSum=nNum1+nNum2
end
numeric nLen,nBrd,nAre
accept nLen
accept nBrd
nAre=nLen*nBrd
end
4. WRITE A PSEUDOCODE TO FIND THE AREA OF SQUARE.
begin
accept nSide
nArea=nSide*nSide
end
accept nRad
nArea = nRad*nRad*22/7
end
accept nBase
accept nPerp
nArea=nBase*nPerp
end
accept nHigh
nArea=nBase*nHigh
end
accept nDgn1
accept nDgn2
nArea=nDgn1*nDgn2/2
end
accept nNum1
accept nNum2
if(nNum1>nNum2)
begin
end
else
begin
end
end
accept nNum1
accept nNum2
nGone=(nNum1>nNum2)?nNum1:nNum2
end
numeric nNum1,nNum2,nNum3
accept nNum1
accept nNum2
accept nNum3
if(nNum1>nNum2)
begin
if(nNum1>nNum3)
begin
end
else
begin
end
end
else
if(nNum2>nNum3)
begin
end
else
begin
end
Capgemini Questions with Answers
Pseudocode Questions and Answers
ALGORITHMS
1. What will be the output of the following pseudo code?
Note- &: bitwise AND - The bitwise AND operator (&) compares each bit of the first operand to the
corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. 6
B. 24
C. 7
D. 11
Answer: C
A. 22
B. 18
C. 31
D. 13
Answer: B
P a g e 5 | 17
3. What will be the output of the following pseudocode?
Answer: A
A. 96
B. 15
C. 33
D. 26
Answer: B
5. What will be the output of the following pseudocode for a=2, b=7, c=7?
A. 26
B. 14
C. 16
D. 18
Answer: C
6. What will be the output of the following pseudocode for p=7, q=2?
P a g e 6 | 17
A. 20
B. 2
C. 12
D. 3
Answer: D
Note- &: bitwise AND - The bitwise AND operator (&) compares each bit of the first operand to the
corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. 88
B. 59
C. 69
D. 74
Answer: C
8. What will be the output of the following pseudocode for a=8, b=1?
P a g e 7 | 17
Note- &&: Logical AND - The logical AND operator (&&) returns the Boolean value true(or 1) if both
operands are true and return false (or 0) otherwise.
A. 11
B. 25
C. 16
D. 18
Answer: C
A. 18
B. 13
C. 22
D. 31
Answer: A
Note- ^ is the bitwise exclusive OR operator that compares each bit of its first operand to the
corresponding bit of the 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. 55
B. 40
P a g e 8 | 17
C. 46
D. 43
Answer: D
11. What will be the output of the following pseudocode for a=8, b=1?
Note- &: bitwise AND - The bitwise AND operator (&) compares each bit of the first operand to the
corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. -1
B. 8
C. 2
D. 1
Answer: B
Note- ^ is the bitwise exclusive OR operator that compares each bit of the first operand to the
corresponding bit of its second operand. If one bit is 0, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. 59
B. 56
C. 65
D. 53
Answer: A
P a g e 9 | 17
13. What will be the output of the following pseudocode?
Note: countVowel(string) returns the number of vowels in the string, e.g. countVowel(“okay”)
returns 2. lower(string) converts all the letters of the string to lower case, e.g. lower(“OkaY”) returns
“okay”.
A. 12
B. 7
C. 0
D. 4
Answer: D
DATA STRUCTURES
1. Which of the following statements is incorrect for Linked list data structure?
A. Memory allocation from Heap
B. Memory allocation from stack
C. Size is not fixed.
D. It occupies more memory than array.
Answer: B
2. If you are using Bubble sort for sorting the given numbers in ascending order, then find out the
number of swapping needed.
12, 16, 10, 7, 13, 3, 9
A. 14
B. 16
C. 12
D. 15
Answer: D
3. Find out the array representation of the given max heap, if the value 25 is inserted in it.
28,17,16,15,14
A. 28,25,17,16,15,14
B. 25,28,17,15,16,14
C. 14,15,16,17,25,28
D. 28,17,25,15,14,16
Answer: D
5. If you are using Bubble sort for sorting the given numbers in ascending order, then find out the
number of swapping needed.
3,10,4,7,9,2,6
A. 12
B. 14
C. 11
D. 8
Answer: C
8. If you are using bubble sort for sorting the given numbers in ascending order, then find out the
number of swapping needed.
9,23,8,10,32,6,14
A. 9
B. 12
C. 10
D. 11
Answer: C
9. Find out the array representation of the given max heap, if the value 20 is deleted from it.
22,21,20,19
A. 21,22,19
B. 22,21,19
C. 19,21,22
P a g e 11 | 17
D. 21,19,22
Answer: B
10. If we draw a binary search tree by inserting the given numbers from left to right. then what would
be the height of the BST?
1,4,3,5,7,9
A. 5
B. 4
C. 3
D. 2
Answer: A
13. Find out the array representation of the given min-heap, if the value 110 is inserted in it.
1,2,3,17,19,36,7,25,100
A. 1,3,2,17,19,36,7,110,100,25
B. 1,2,3,17,1,36,9,7,110,100,25
C. 1,2,3,17,19,36,7,25,100,110
D. 1,2,3,17,19,36,7,110,100,25
Answer: C
14. Find out the array representation of the given min heap, if the value 2 is deleted from it.
1,2,3,4
A. 1,4,3
B. 1,3,4
C. 4,3,1
D. 3,4,1
Answer: A
P a g e 12 | 17
3. Trees
A. 1 and 2
B. All 1, 2, and 3
C. 1 and 3
D. 2 and 3
Answer: B
16. Which of the following statements is/are correct for Double Linked List?
1. All the nodes have two links
2. Provides bidirectional traversing
3. Provides only unidirectional traversing
A. 1 and 3
B. 1 and 2
C. Only 3
D. Only 1
Answer: B
17. If you are using Bubble sort for sorting the given numbers in ascending order, the find out the
number of swapping needed.
2,9,3,6,8,1,5
A. 10
B. 12
C. 11
D. 13
Answer: C
P a g e 13 | 17
20. If there is a binary tree of height 8, then what should be the maximum number of nodes in that
tree?
A. 511
B. 255
C. 256
D. 512
Answer: B
21. If the base address of two dimensional array A[80] [20] is 700, then find out the address of an
element a[1][8] in the array.
** Assume 4 words per memory cell and elements are arranged in column major order.
A. 3245
B. 3264
C. 6543
D. 3456
Answer: B
22. If the base address of two dimensional array A[70] [10] is 600, then find out the address of an
element A[2][7] in the array.
** Assume 4 words per memory cell and elements are arranged in column major order.
A. 2658
B. 2543
C. 2568
D. 2345
Answer: C
24. How many nodes are present in a strictly binary tree with 8 leaves?
A. 7
B. 15
C. 16
D. 17
Answer: B
25. Find out the maximum number of nodes present in a binary tree of height 5.
A. 16
P a g e 14 | 17
B. 32
C. 15
D. 31
Answer: D
26. If the base address of two dimensional array A[30] [50] is 500, then find out the address of an
element A[5][10] in the array.
** Assume 4 words per memory cell and elements are arranged in row major order.
A. 1189
B. 1124
C. 1160
D. 1540
Answer: D
27. If we draw a binary search tree by inserting the given numbers from left to right, then what would
be the height of the BST?
11, 13, 12, 14, 10, 9
A. 2
B. 5
C. 4
D. 3
Answer: C
28. If we draw a binary search tree by inserting the given numbers from left to right, then what would
be the height of the BST?
12, 13, 16, 10, 9, 7
A. 4
B. 2
C. 5
D. 3
Answer: A
29. Find out the maximum number of nodes present in a tree of height 6.
A. 31
B. 63
C. 64
D. 32
Answer: B
30. Find out the array representation of the given min-heap, if the value 10 is inserted in it.
5, 6, 9, 17, 18
A. 5, 6, 9, 10, 17, 18
B. 5, 6, 9, 17, 18, 10
C. 6, 9, 5, 17, 18, 10
P a g e 15 | 17
D. 9, 5, 6, 17, 18, 10
Answer: B
31. Which of the following is the correct order of the nodes visited during an in-order traversal of the
given noded tree?
A. B-D-A-G-E-C-H-I-G
B. B-D-A-G-E-C-H-F-I
C. D-B-A-G-E-C-H-F-I
D. D-B-A-G-E-C-H-I-F
Answer: B
32. Which of the following statements is/are TRUE for array data structure?
A. Memory allocation from stack.
B. Memory allocation from Heap
C. All of the mentioned options
D. Size is not fixed.
Answer: A
33. Which of the following is the correct post-order traversal of the given tree?
A. 1 2 4 5 3
B. 4 5 2 3 1
C. 1 2 3 4 5
P a g e 16 | 17
D. 4 2 5 1 3
Answer: B
34. Find out the sum of the degree of vertices in the pseudograph as shown in the image.
A. 12
B. 6
C. 11
D. 8
Answer: C
35. If the base address of two dimensional array A[10] [20] is 100, then find out the address of an
element A[2][6] in the array.
** Assume 4 words per memory cell and elements are arranged in row major order.
A. 286
B. 284
C. 245
D. 278
Answer: B
P a g e 17 | 17