Download “onlinestudy4U” app from play store for all free material.
Pseudo code for Capgemini :
Pseudo code for Capgemini----------------------------------------- 1 -25
Pseudo code can be broken down into five components.
• Variables:
• Assignment:
• Input/output:
• Selection:
• Repetition:
A variable has a name, a data type, and a value. There is a location in memory
associated with each variable. A variable can be called anything or be given any
name. It is considered good practice to use variable names that are relevant to
the task at hand.
Assignment is the physical act of placing a value into a variable. Assignment
can be shown using
set = 5;
set = num + set;
The left side is the variable a value is being stored in and the right side is where
the variable is being accessed. When a variable is assigned a value, the old
value is written over with the new value so the old value is gone. x = 5 does not
mean that x is equal to 5; it means set the variable x to have the value 5. Give x
the value 5, make x equal to 5.
Input / Output both deal with an outside source (can be a user or another
program) receiving or giving information. An example would be assuming a fast
food restaurant is a program. A driver (user) would submit their order for a
burger and fries (input), they would then drive to the side window and pick up
their ordered meal (output.)
• Output – Write / display / print
• Input – Read / get / input
Selection construct allows for a choice between performing an action and
skipping it. It is our conditional statements. Selection statements are written as
such:
if ( conditional statement)
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
statement list
else
statement list
Repetition is a construct that allows instructions to be executed multiple times
(IE repeated).
In a repetition problem
– Count is initialized
– Tested
– incremented
Repetition problems are shown as:
while (condition statement)
statement list
Here are some of the problems that will help you to prepare for exams.
[ 1 ]. Write pseudo code that reads two numbers and multiplies them
together and print out their product.
[ 2 ]. Write pseudo code that tells a user that the number they entered
is not a 5 or a 6.
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
[ 3 ]. Write pseudo code that performs the following: Ask a user to
enter a number. If the number is between 0 and 10, write the word blue.
If the number is between 10 and 20, write the word red. if the number is
between 20 and 30, write the word green. If it is any other number, write
that it is not a correct colour option.
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
[ 4 ]. Write pseudo code to print all multiples of 5 between 1 and 100
(including both 1 and 100).
[ 5 ]. Write pseudo code that will count all the even numbers up to a
user defined stopping point.
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
[ 6 ]. Write pseudo code that will perform the following:
a. Read in 5 separate numbers
b. Calculate the average of 5 numbers
c. Find the smallest (minimum) and largest (maximum) of the five
entered numbers.
d. Write out the results found from steps b and c with a message
describing what they are
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
[ 7 ]. Write pseudo code that reads in three numbers and writes them
all in sorted order.
[ 8 ]. Write pseudo code that will calculate a running sum. A user will
enter numbers that will be added to the sum and when a negative
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
number is encountered, stop adding numbers and write out the final
result.
[ 9 ]. Point out the error
#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
[ 10]. Consider the following iterative implementation to find the
factorial of a number. What statement should be added to complete the
code?int main()
{
int n = 6, i;
int fact = 1;
for(i=1;i<=n;i++)
;
printf("%d",fact);
return 0;
}
a. fact = fact + i
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
b. fact = fact * i
c. i = i * fact
d. i = i + fact
[ 10 ]. 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
[ 11 ]. Convert the following 211 decimal number to 8-bit binary
a. 11011011
b. 11001011
c. 11010011
d. 11010011
[ 12 ]. 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
[ 13 ]. Comment on the output of this code.
#include <stdio.h>
int main()
{
int a = 1;
switch (a)
case 1:
printf("%d", a);
case 2:
printf("%d", a);
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
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
[ 14 ]. How will you find the maximum
public void max(Tree root) public void max(Tree root)
while(root.left() != null) while(root != null)
root = root.left(); root = root.left();
System.out.println(root.data()); System.out.println(root.data());
public void max(Tree root) element in a binary search tree?
while(root.right() != null)
root = root.right();
System.out.println(root.data());
[ 15 ]. What is the output of the following
code? public void max(Tree root)
void my_recursive_function(int n) while(root != null)
{ root = root.right();
if(n == 0) System.out.println(root.data())
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
my_recursive_function(10);
return 0;
}
a. 10
b. 1
c. 10 9 8 … 1 0
d. 10 9 8 … 1
[ 16 ]. Choose the output
#include <stdio.h>
int main()
{
int i = 0;
int x = i++, y = ++i;
printf("%d % d\n", x, y);
return 0;
}
a) 0, 2
b) 0, 1
c) 1, 2
d) Undefined
[ 17 ]. Choose the output
#include <stdio.h>
int main()
{
int i = 10;
int *p = &i;
printf("%d\n", *p++);
}
a) 11
b) 10
c) Garbage value
d) Address of i
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
[ 18 ]. Choose the output
#include <stdio.h>
void main()
{
int x = 97;
int y = sizeof(x++);
printf("X is %d", x);
}
a) X is 99
b) X is 98
c) X is 97
d) Run time error
[ 19 ]. Choose the output
#include <stdio.h>
void main()
{
int x = 4, y, z;
y = --x;
z = x--;
printf("%d%d%d", x, y, z);
}
a) 3 2 3
b) 2 3 3
c) 3 2 2
d) 2 3 4
[ 20 ]. Choose the output
#include <stdio.h>
void main()
{
int x = 4;
int *p = &x;
int *k = p++;
int r = p - k;
printf("%d", r);
}
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
a) 4
b) 8
c) 1
d) Run time error
[ 21 ]. Choose the output of the code
#include <stdio.h>
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("\n%d%d%d%d", a, b, c, d);
}
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
[ 22 ]. Choose the output of the code
#include <stdio.h>
void main()
{
int a = -5;
int k = (a++, ++a);
printf("%d\n", k);
}
a) -4
b) -5
c) 4
d) -3
[ 23 ]. Write a Pseudo Code for Bubble Sort
Set n to number of records to be sorted
repeat
flag = false;
for counter = 1 to n-1 do
if key[counter] > key[counter+1] then
swap the records;
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
set flag = true;
end if
end do
n = n-1;
until flag = false or n=1
[ 24 ]. Compute Fibonacci numbers till 50
Declare an integer variable called n
Declare an integer variable sum
Declare an integer variable f1
Declare an integer variable f2
set sum to 0
set f1 and f2 to 1
set n to 50
repeat n times
sum = f1 + f2
f2 = f1
f1 = sum
print sum
end loop
[ 25 ]. What will be the value of S if N=127
Read n
i=0,s=0
Function Sample(int n)
while(n>0)
r=n%l0
p=8^i
s=s+p*r
i++
n=n/10
End While
Return s;
End Function
a) 27
b) 187
c) 87
d) 120
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
[ 26 ]. What will be the output of the following pseudo code?
Integer n
for (n = 3; n != 0; n-)
Print n
n = n-1
end for
a) 3 1
b) 3 2 1
c) 3
d) Infinite Loop
[ 27 ]. What will be the value of even_counter if number = 2630?
Read number
Function divisible(number)
even_counter = 0, num_remainder = number;
while (num_remainder)
digit = num_remainder % 10;
if digit != 0 AND number % digit == 0
even_counter= even_counter+1
End If
num_remainder= num_remainder / 10;
End While
return even_counter;
a) 3
b) 4
c) 2
d) 1
[ 28 ]. Where is the error in the given pseudo code to sort numbers in
ascending order?
Read size
Read a[1],a[2],…a[size]
i=0
While(i<size)
j=i+1
While(j<size)
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
If a[i] < a[j] then
t= a[i];
a[i] = a[j];
a[j] = t;
End If
j=j+1
End While
i=i+1
End While
i=0
While (i<size)
print a[i]
i=i+1
End While
a) Line 4
b) Line 6
c) Line 7
d) No Error
[ 29 ]. What will be the value of t if a = 56 , b = 876?
Read a,b
Function mul(a, b)
t=0
while (b != 0)
t=t+a
b=b-1
End While
return t;
End Function
a) 490563
b) 49056
c) 490561
d) None of the mentioned
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
[ 30 ]. What will be the output?
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) 72
d) 68
[ 31 ]. In the worst case, the number of comparisons needed to search a
singly linked list of length n for a given element is….?
a) log 2 n
b) n⁄2
c) log 2 n – 1
d) n
[ 32 ]. Which of the following will give the best performance?
a) O(n)
b) O(n!)
c) O(n log n)
d) O(n^C)
[ 33 ]. What is the time complexity of searching for an element in a
circular linked list?
a) O(n)
b) O(nlogn)
c) O(1)
d) None of the mentioned
[ 34 ]. How many times the following loop is executed?
{
…
ch = ‘b’;
while(ch >= ‘a’ && ch <= ‘z’)
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
ch++;
}
a) 0
b) 25
c) 26
d) 1
[ 35 ]. What will be the output the following pseudo code?
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) 88
c) 72
d) 65
[ 36 ]. What is the space complexity of the following code considering
that the size of int is 2 bytes ?
int sum(int A[], int n)
{
int sum = 0, i;
for(i = 0; i < n; i++)
sum = sum + A[i];
return sum;
}
a) 2n + 8
b) 2n + 4
c) 2n + 2
d) 2n + 6
[ 37 ]. What does the following code do ?
public void func(Tree root)
{
func(root.left());
func(root.right());
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
System.out.println(root.data());
}
a) Preorder traversal
b) Inorder traversal
c) Postorder traversal
d) Level order traversal
[ 38 ]. 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
[ 39 ]. 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(n)
b) O(m+n)
c) O(n2)
d) O(mn)
[ 40 ]. 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) Θ(nLogn)
d) O(n3)
[ 41 ]. 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, and 1
b) 3, 3, and 3
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
c) 4, 0, and 1
d) 3, 0, and 2
[ 42 ]. What will be the output of the following pseudo code ?
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) 9
b) 15
c) 21
d) 6
[ 43 ]. What will be the output of the following pseudo code?
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
[ 44 ]. Keep the statement language while writing a
pseudo code.
a) Dependent
b) Independent
c) Case sensitive
d) Capitalized
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
Explanation: The statement’s language should be independent. Other rules
are to write only one statement per line and end multiline structures.
[ 45 ]. Capitalize initial keyword – This is a rule while writing a pseudo
code.
a) True
b) False
Explanation: The statement is true. It is an important rule to capitalize the
initial keyword while writing a pseudo code
[ 46 ]. Which one of the following is not a keyword?
a) Read
b) Write
c) start
d) endif
Explanation: Start is not a Keyword. Other words like read, write, if, else, etc
are keywords and convey a special meaning.
[ 47 ]. _ is used to show hierarchy in a pseudo code.
a) Indentation
b) Curly Braces
c) Round Brackets
d) Semicolon
Explanation: Each design structure uses a particular indentation pattern.
Indentation should be considered in the following cases:
Sequence
Selection
Loop
[ 48 ]. The statement that tells the computer to get a value from an input
device and store it in a memory location
a) read
b) write
c) READ
d) WRITE
Explanation: The READ statement is used to take the input. READ being a
keyword should be in capital letters.
[ 49 ]. are identified by their addresses, we give them
names (field names / variable names) using words.
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
a) Memory variables
b) Memory Locations
c) Memory Addresses
d) Data variables
Explanation: Memory locations are identified by their addresses, we give
them names (field names/variable names) using words descriptive to us
such as ctr as opposed to a location addresses such as 19087.
[ 50 ]. begins with lower case letters.
a) Keywords
b) Variables
c) Tokens
d) Functions
Explanation: Variables begin with a lowercase. They contain no spaces. They
also involve the consistent use of names.
[ 51 ]. Another notation for exponentiation ?
a) *
b) **
c) ***
d) *^
Explanation: Double asterisk sign is also used for exponentiation. The
general notation is ^ sign.
[ 52 ]. A symbol used for grouping?
a) ()
b) {}
c) [].
d) ” ”
Explanation: Parenthesis is used for grouping while working with fields.
There are other symbols like *, +, -, **, etc.
[ 53 ]. A statement used to close the IF block.
a) ELSE
b) ELSEIF
c) END
d) ENDIF
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
Explanation: The answer is ENDIF. It is used to close the IF block. ENDIF
statement should be in line with the IF statement.
[ 54 ]. Which one of the following is not a type of Linked List?
a. Circular Linked List
b. Doubly Linked List
c. Null Linked List
d. Singly Linked List
[ 55 ]. Which of the languages is often translated to the pseudo code?
a) PASCAL
b) FORTRAN
c) PL/I
d) BASIC
[ 56 ]. Merge sort uses:
a. Divide and conquer strategy
b. Backtracking approach
c. Heuristic search
d. Greedy approach
[ 57 ]. The complexity of Bubble Sort algorithm is:
a. O(n)
b. O(log n)
c. O(n2)
d. O(n log n)
[ 58 ]. Deletion from one end and insertion from other end is
a. stack
b. branch
c. tree
d. queue
[ 59 ]. Preorder is:
a. depth first order
b. breadth first order
c. topological order
d. linear order
[ 60 ]. Information about an array used in a program will be stored in
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
a. symbol table
b. activation record
c. dope vector
d. system table
[ 61 ]. ++i is equivalent to:
a. i=i+2
b. i=i+1
c. i=i+i
d. i=i-1
[ 62 ]. Repeated execution of simple computation may cause
compounding of
a. round off errors
b. syntax errors
c. run time errors
d. logic errors
[ 63 ]. Which statement we should ignore in structure programming
a. WHILE-DO
b. GO-TO
c. IT-ELSE
d. SWITCH
[ 64 ]. Pseudo code is very focused on language syntax.
a. True
b. Fasle
[ 65 ]. Which one of the following shapes is NOT used in basic
flowcharts?
a. Rectangle
b. Elipse
c. Diamond
d. Octagon
[ 66 ]. Is there a "correct" representation of algorithm to use?
a. Yes you must use pseudo code to impress programmers.
b. Yes, flowcharts must be used so everyone can understand.
c. No, it depends on the situation. Either is appropriate.
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
[ 67 ]. Pseudo code requires a structure
a. True
b. False
Explanation: True. Pseudo code must be have a beginning and ending
statement.
[ 68 ]. What construct should you use to make your pseudocode more
readable?
a. Bold letters
b. Tab spaces
c. A combination of upper and lower case.
d. All of the above.
[ 69 ]. Flowcharts require a begin symbol:
a. True
b. False
[ 70 ]. Pseudo code and flow charts are best suited to which phase in the
development life cycle?
a. Design
b. Testing
c. Maintenance
[ 71 ]. is used to show the hierarchy of a pseudocode.
a. Indentation
b. Curly brackets
c. Round brackets
d. Semicolon
[ 72 ]. The statement that tells the computer to get a value from the
keyboard and store it in memory is:
a) Read
b) Write
c) READ
d) WRITE
Explanation: In Pseudo code, such statements must be always
capitalized. Otherwise they will have no meaning!
[ 73 ]. The statement used to close the IF block:
a. ELSE
b. ELSEIF
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/
Download “onlinestudy4U” app from play store for all free material.
c. END
d. ENDIF
[ 74 ]. begins with lowercase letters:
a. Keywords
b. Variables
c. Tokens
d. Functions
[ 75 ]. What will be the value of s if n=127?
Read n
i=0,s=0
Function Sample(int n)
while(n>0)
r=n%l0
p=8^i
s=s+p*r
i++
n=n/10
End While
Return s;
End Function
a.27 b.187 c.87 d.120
OnlineStudy4U .. A Complete Placement Solution website: https://onlinestudy4u.in/