Pseudo Code
Pseudo Code
The syllabus for Accenture pseudo code MCQs section is as given below.
Questions will be mostly on these topics only.
Integer i
Set i = 3
do
print i + 3
i = i - 1
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) 6 6 6
B) 6 5 6
C) 5 5 5
D) 6 5 4
Ans: D
Explanation:
Step 1:
Step 2:
It will print i+3, here updated i value is 2. So i+3 is 5. On the next line i will
be decremented by 1. Then checking the conditions in do-while() i!=0. Here updated
i value is 1 (1!=0),so condition gets true. The loop continues
Step 3:
It will print i+3, here updated i value is 1. So i+3 is 4. On the next line i will
be decremented by 1. Then checking the condition in do while() i!=0. Here updated i
value is 0 (0!=0),so condition gets false. Thus the loop gets terminated!
Do while will execute the statement for the first time and then it will check the
condition.
int i=3;
do{
}while(i!=0);
===================================================================================
=========
Q2. What would be the output of the following pseudocode?
Integer a
String str1
a = stringLength(str1)
Print (a ^ 1)
A) 0
B) 4
C) 5
D) 3
Ans: B
Explanation:
There are two variables a and str1. Value initialized for str1 is “goose”.
On the next line, we are finding the length of str1 that is 5. Finally, printing
the output of a bitwise exclusive OR operator with 1. And the answer is 4.
int a;
string str1="goose";
a = str1.length(); => length of String is 5
===================================================================================
=========
Q3. What would be the output of the following pseudocode?
Integer a, b, c
Set a = 8, b = 51, c = 2
c = (a ^ c)^ (a)
b = b mod 4
Print a + b + c
[Note- mod finds the remainder after the division of one number by another. For
example, the expression “5 mod 2” would evaluate to 1 because 5 divided by 2 leaves
a quotient of 2 and a remainder of 1
^ 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. 13
B. 17
C. 26
D. 16
Ans:A
Explanation:
int main()
int a=8,b=51,c=2;
b = b % 4; =>3
===================================================================================
===================================================================================
===================
Q4. 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. 1
C. 2
D. 3
Ans: D
Explanation:
There is an Integer Array A = {1, 2, 4, 5, 6, 11, 12} and the key value is 10.
Binary search applies only sorted, ordered list.
We know that binary search takes log n base 2 time to search for a particular
element.
If there are N elements in the set you have chosen binary search then take log n
base 2 time.
1)First, you check how many elements in your array. if an element in your array is
greater than 1 then you go for the next step.
2)Binary search divides the problem into two parts using the mean of the total
number of an element which is sorted mean=(0+n)/2
3)And compare the searching element which is either greater the mean or lesser or
equal to the mean .then after comparison skip the one part either greater part or
small part depends on the result or searching is done if the mean is equal to the
searching element. So that problem is divide into n/2 and goes until searching is
done.
If you apply the recursive equation for the binary search algorithm then
n/2^k=1
log n= k log 2
k=log n base 2.
N=7
K=log 7 base 2 = 3
K=3
===================================================================================
=========================
Set k = 8
for(each i from 1 to 1)
print k+1
end for
end for
A. 2
B. 9
C. 7
D. 8
Ans: B
Explanation:
Here I value is 1, for loop will check the condition i<=1 condition gets true. Now,
moving with inner for loop j value will be 1 condition gets true j<=1.so, it prints
K+1. Then j value will be incremented by 1(2<+1) inner for loop condition gets
false.
int i, j, k;
k = 8;
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) 15
B) 7
C) 2
D) 0
[Note-mod finds the remainder after the division of one number by another. For
example, the expression “5 mod 2” leaves a quotient of 2 and a remainder of 1]
Answer: 0
Explanation:
There are two variables a and b declared. Value initialized for a is 15 and b is 7.
Taking mod operation for a by 12(a%12) and the answer is 3 will stored in a.
The next mod operation for b is 7 mod (7%4). The answer is 3 will be stored in b.
The next line takes the updated value of a and mods it by 1(3%1). Then the answer
becomes 0 will be stored in a.
Next line takes the updated value of b mod by 1 (3%1) then the answer is 0. Finally
adding all the updated values of a and b (0+0 ) and the output of Pseudocode is 0.
Integer a, b, c
Set b = 5, a = 2, c = 2
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) 2
B) 13
C) 26
D) 5
Ans:B
Explanation:
Checking the condition using if, b >a and a>c and c>b here if conditions get false.
Now else part will execute b value will be incremented by 1 and stored in a,
Finally adding all the updated values of a, b and c (6+5+2 ) and the output of
Pseudocode is 13.
Q8. For which of the following applications can you use hashing?
2. For Timestamping
A. Only 1 and 3
B. Only 2 and 3
C. Only 1
D. Only 1 and 2
Ans:D
Explanation:
Q9. 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. 16
B. 4
C. 12
D. 8
Ans: C
Explanation:
The difference between the address of the 1st and 4th element is 12.
Q10. What is the second part of a node in a linked list that contains the address
of the next node called?
A. data
B. pointer
C. element
D. Link
Ans:D
Explanation:
The field of each node that contains the address of the next node is usually called
the 'link'.
Q11. If you are using Depth-first search (DFS) for traversing an unweighted graph,
then which of the following will happen?
C. Only 2 is true
D. Only 1 is true
Ans:D
Explanation:
Depth-first search (DFS) for traversing an unweighted graph, will produce the
minimum spanning tree.
Only Depth-first search (DFS) for traversing an weighted graph, will produce all
pair shortest-path tree.
Q12. With the given the information provided find out the address of Arr[17] in a
1-D array Arr[30].
- lower bound = 1
A. 1132
B. 1070
C. 1128
D. 1068
Ans: A
Explanation:
Integer a, s
Set s = 0
Print a
A) 25
B) 5
C) 50
D) 40
Ans: C
Explanation:
There is an array of integer arr[]={10,20,30,40,50}. There are two variables a and
b declared. . The value initialized for s is 0. On next line adding the 1st index
value 20 and 2nd index value 30 arr[1] + arr[2]( 20+30) the answer is 50 will be
stored in a. Finally printing the updated values of a is 50.
Integer a, b, c
Set b = 2, a = 2
c = a ^ b
Print c
[Note- ^ is the bitwise exclusive OR operator that compares each bits of its first
operand to the corresponding bit of its-- other bit is 1, the corresponding result
bit is set to 1. Otherwise, the corresponding result bit is set to 0]
A) 6
B) 4
C) 0
D) 2
Ans:C
Explanation:
There are three variables a, b and c declared. Value initialized for a is 2 and b
is 2. When we do a bitwise exclusive OR of c i.e (2^2), the answer is 0. Finally,
print the value of c.
Q15. Which of the following series will be printed by the given pseudocode?
Integer i, j, k, n
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
Ans:A
Explanation:
There are four variables i, j,k and n declared. Value initialized for j is 1 and k
is 1.
For loop, i value starts from 1 loop will run till the i<5, In the first iteration
i value, is 1, printing k value is 1. Next line j value will be incremented by 1
(1+1) =>2. On the next line adding k and j (1+2), then the answer is 3.
2nd iteration i value will be incremented by 1, i=2. Print k, the updated k value
is 3. on the next line j value will be incremented by 1 (2+1) =>3. On the next line
adding k and j (3+3) , then the answer is 6.
3rd iteration i value will be incremented by 1, i=3. Print k, the updated k value
is 6. on the next line j value will be incremented by 1 (3+1) =>4. On the next line
adding k and j (6+4) , then the answer is 10.
4th iteration i value will be incremented by 1, i=4. Print k, the updated k value
is 10. on the next line j value will be incremented by 1 (4+1) =>5. On the next
line adding k and j (10+5) , then the answer is 15.
5th iteration i value will be incremented by 1, i=5. Print k, the updated k value
is 15. Next line j value will be incremented by 1 (5+1) =>6. On the next line
adding k and j (15+6), then the answer is 21.
Here for loop condition gets false, it comes out of the for loop. The output of
Pseudocode is 1 3 6 10 15.
Capgemini Pseudo Code MCQs (previously asked)
Question 1:
Integer x,y,z;
x=0
y=1
x = y = z = 8
Print x
Options:
A) 0
B) 8
C) 1
Question 2:
Integer value, n
Set value = 1, n = 45
end loop
Print value
Options:
A) 64
B) 32
C) 45
Explanation: Here, the left shift operation pushes the values towards the left
once; when 1 is left shifted the value what we will be obtaining will always be 2
to the power something. When one is converted in the beginning and not shifted the
value will be 2^0 which is 1. Next iteration it will be pushed one place towards
the left, therefore the value now will be 2^1 which is 2 ; this will go on
happening until the value stored is greater than 45 . The value which is greater
than 45 in 2 powers is 64. Now the loop terminates and the last value stored in the
variable is 64 and the same will be printed.
Question 3:
Integer c, d
Set c = 15, d = 12
d = c – 1
Print c //line
c = d + (c – 2)
Goto line
end if
Options:
A) 14 26 38
B) 27 39
C) 15 27 39
Question 4:
if(x > 1)
fun(x – 2, y + 2)
end if
print y
Options:
A) 4 5 6
B) 7 6 5
C) 9 7 5
Explanation: the first reverse recursion would print 9 and returns to previous
function call, next it prints 7 and returns to very first function call finally it
prints a 5 and complets the execution.
Question 5:
Integer a, b, c
Set a = 8, b = 10, c = 6
Print a
end if
Print b
end if
Print c
end if
Options:
A) 2
B) 3
C) 1
D) 0
Explanation: All the conditions are true when checked with the condition so the
print statement will be executed 3 times.
Question 6:
What will be the output if the following pseudocode if a=10 and b=6:
Integer temp
while(b)
temp = a MOD b
a = b
b = temp
end while
return a
A) 2
B) 4
C) 3
D) 1
Explanation: The while loop will only terminate when the value of b becomes zero,
this will happen only after the 4th iteration when the last value of the b will be
zero and value of a is 2
Question 7:
Integer x, y, z
x = x/y
z = y<<x
Print z
[Note: << is left shift operator, it takes two numbers, left shifts the bits of the
first operand, the second operand decodes the number of …]
Options:
A) 1
B) 8
C) 0
D) 64
Integer x, y, z, a
Set x = 2, y = 1, z = 5
a = (x AND y) OR (z + 1)
Print a
Options:
A) 5
B) 3
C) 2
D) 1
Explanation: AND gate works when both the conditions are true so the first (x and
y) condition will be taken as true as the both the inputs are true. OR gate works
when any of the conditions are true, where it has already got one of its input as
true so without checking the other input it will directly assign the value as 1.
Question 09:
a = b + c
c = a – b
c = c + a
c = b + c
b = b + c
Print a, b, c
Options:
A) 7 14 7
B) 7 14 10
C) 7 8 14
D) 7 18 14
a = 4 +3 = 7
c = 7 – 4 = 3
c = 3 + 7 = 10
c = 4 + 10 = 14
b = 4 + 14 = 18
Print 7, 18, 14
Question 10:
Integer a, b, c, d
Set b = 18, c = 12
a = b – c
b = b + c + 12
b = b/5
d = b + a
end for
c = a + b + c
Print a b c
Options:
A) 5 3 9
B) 6 14 17
C) 6 4 14
D) 6 4 16
Explanation: The loop runs for 5 times ; after the 5th iteration the value of a=6;
b=4; c=10.
Question 11:
Options:
B) Insertion
C) Searching
D) Sorting
Question 12:
Options:
A) Union
B) Assignment
C) Primitive
Question 13:
Options:
A) End nodes
B) Terminal nodes
C) Last nodes
D) Final nodes
Question 14:
A) Upper bound
B) Lower bound
C) Range
D) Extraction
Explanation: The upper bound is always the highest element of an array index.
Question 15:
Which of the following data types represents many to many relations?
B) Graph
C) Plex
D) Tree
Question 16:
Explanation: We just have 3 types of linked list among the given options b, c and
d. double ended linked list does not exist.
Question 17:
A) Vertex
B) Root
C) Path
D) Edge
Question 18:
Recursion uses more memory space than iteration. Which of the following is/are the
valid reason for the same?
A) Only A
B) Both A and B
C) Neither A nor B
D) Only B
Explanation: Recursive functions use stack as the memory space technique. And also
as rightly pointed out the call has to be present to store the returned values.
Question 19:
To which of the following domain problem does the knapsack problem belong?
A) NP- complete
B) Sorting
C) Optimisation
D) Linear Solution
Explanation : knapsack algorithm is used to find the maximum profit out of the
least weight combination possible, therefore it is definitely belongs to a
optimisation domain.