0% found this document useful (0 votes)
363 views

Capgemini - Pseudocoding & Algorithms - Hot Set-1

This document provides 20 questions about pseudocode algorithms and data structures. The questions test concepts like loops, conditionals, operators, functions, strings, arrays, and heaps. Sample outputs and answers are provided for each question.

Uploaded by

Et Cetera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
363 views

Capgemini - Pseudocoding & Algorithms - Hot Set-1

This document provides 20 questions about pseudocode algorithms and data structures. The questions test concepts like loops, conditionals, operators, functions, strings, arrays, and heaps. Sample outputs and answers are provided for each question.

Uploaded by

Et Cetera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Capgemini Pseudo coding and Algorithms_Hot Set

Q1.What will be the output of the following pseudocode?

1. Integer a,b,c

2. set a=0,b=2,c=5

3. for(each c from 4 to 7)

4. If ( (b-c-a)>(a+b) )

5. Jump out of the loop


6. End if

7. a=a+c

8. a=(2&4)+c

9. End for

10. print a+b

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.

Ops :A.15

B.5

C.9

D.13

Ans: Option B) 9
Q2. What will be the output of the following pseudocode? 1

.Integer a,b,c

2. Set a=7,b=6,c=7

3. for(each C from 4 to 5)

4. if( (b+a)<(C_b) )

5. Jump out of the loop

6. end if

7.a=b^b

8.b=(b+8)+c

9. End for

10. print a=b


Note: ^ is the bitwise exclusive OR operator that computer each bit of its first operand to the
corresponding bit of its second operand. If one bit is 0 and the other bit is 1,the corresponding result bit
is set to 1.Otherwise result bit is set to 0.

Ops : A.33

B.46

C.31

D.24

Ans: Option D) 24
Q3: What will be the output of the following pseudocode?

1. Integer pp,qq,rr

2. set pp=4,qq=8,rr=9

3. if ( (pp+qq)<(qq-pp) )

4. rr=(pp&pp)^rr

5. qq=(6+6)+pp

6. qq=(3+10)+rr

7. End if

8. print pp+qq+rr

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.

^ is the bitwise exclusive OR operator that computer each bit of its first operand to the corresponding
bit of its second operand. If one bit is 0 and the other bit is 1,the corresponding result bit is set to
1.Otherwise result bit is set to 0.

Ops: A.17

B.21

C.31

D.22

Ans: Option B) 21
Q4: What will be the output of the following pseudo code?

1.

2. Integer j

3. Integer arr[2] [2]={ {3,4},{2,2} }


4. if (( arr[0]-arr[1][0]+arr[0][1]>(arr[0][1]-arr[0][1]))

5. Arr[1][1]=arr[0][1]+arr[0][1]

6. Else

7. arr[0][1]=(5&3)+arr[0][1]

8. End if

9. if (( arr[0][1] &arr[1][1])<(arr[0][1]^arr[0][1]) )

10. arr[1][1]=arr[0][1]^arr[0][1]

11. End if

12. print arr[1][1]+arr[0][1]+arr[1][1]

Ans: 20

Q5: : What will be the output of the following pseudocode?

1. Integer p,q,r

2. Set p=4,q=6,r=4

3. if ((r+5)<(9+r))

4. r=3+r
5. End if

6. if (2>r && (p^q)<(r+p))

7. r=10+q

8. Else

9. r=q^r

10. End if

11.r=(p+r)+p

12.print p+q+r

Note: ^ is the bitwise exclusive OR operator that computer each bit of its first operand to the
corresponding bit of its second operand. If one bit is 0 and the other bit is 1,the corresponding result bit
is set to 1.Otherwise result bit is set to 0.
Ops: A.17

B.19

C.26

D.24

Ans: Option

B) 19

Q6: What will be the output of the following pseudocode?

1. Integer a,b,c

2. Set a=4,b=3,c=9

3. for (each c from 4 to 7)

4. a=5+b

5. a=(c+12)+b

6. End for

7. print a+b

Ops: A.34

B.39

C.18

D.25

Ans: Option

D) 25

Q7:What will be output of the following pseudo code for a=1,b=8,c=9?

1. Integer funn (Integer a, integer, integer)


2. For (each from 2 to 3)
3. a=10+b
4. A=(b=+b)^c
5. End for
6. For (each c from 2 to 5)
7. a=c+a
8. End for
9. Return a+b
10. End function funn ()

NOTE: ^ is the bitwise exclusive OR operator that computer each bit of its first operand to the
corresponding bit of its second operand. If one bit is 0 and the other bit is 1,the corresponding result
bit is set to 1.Otherwise result bit is set to 0.

Ops: A.48

B.51
C.40

D.41

Ans: Option A) 48
Q8:What will be the output of the following pseudo code ?

1. Integer p,q,r

2. Set p=0 ,q=4,r=11

3. if (r>p)

4. r=q+r

5. End if

6. print p+q+r

Ops:A.26

B.19

C.17

D.31

Ans:

Option B)

19

Q9: What will be the output of the following pseudo code ?

1. Integer pp,qq,rr

2. set pp=7,qq=7,rr=8

3.qq=(rr+qq)+qq

4.rr=rr+pp

5.qq=(pp+qq)&pp

6.pp=rr+qq

Print pp+qq+rr

Note: : ^ is the bitwise exclusive OR operator that computer each bit of its first operand to the
corresponding bit of its second operand. If one bit is 0 and the other bit is 1,the corresponding result bit
is set to 1.Otherwise result bit is set 0.
Ans: 40

Q10. What will be the output of the following pseudo code ?

1. Integer a,b,c

2. Set a=4,b=4,c=4
3. for(each c from 2 to 4)
4. b=6+c

5. If ((8-a+b)>(b+c))

6. b=(3+7)&b

7. a=(c+5)+b

8. Else

9. jump out of the loop

10. End if

11. b=7+a

12. End for

13. print a+b

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.

Ops :A.27

B.24

C.31

D.20

Ans:

Option b)

24

Q11. What will be the output of the following pseudo code ?

1. Integer a,b,c
2. Set a=5,b=8,c=6
3. If((b-c-a)>(a+b))
4. c=(8+6)+c
5. B=(12+4)+a
6. End if
7. Print a+b+c

Ops: A.17

B.19

C.30

D.26

Ans: Option

B) 19
Q12. What will be the output of the following pseudo code for a=6,b=5 ?

1.

2. Integer funn (integer a,integer b)


3. if (a&1 && a>0 && b>0)

4. return funn (a-1,b) +funn(a+1,b)

5. End if

6. return a

Ops: A.11

B.15

C.6

D.1
Ans: Option c) 6

Q13. What will be the output of the following pseudo code ?

1. Integer j,m

2. Set m=1

3. Integer a[4]={7,1,2,2}

4. if (a[3]<a[2] || a[1]<4)

5. m=m+1

6. End if

7. print m

Ops:A.2

B.-2

C. 3

D.12

Ans: Option

A) 2

Q14. What will be the output of the following pseudo code ?

1. Integer a,b,c

2. Set a=0,b=3,c=14

3. b=b+a

4.b=(a+1)^c

5. b=(7+8)+b

6. c=(a+7)&c
7. print a+b+c
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.

^ is the bitwise exclusive OR operator that computer each bit of its first operand to the corresponding
bit of its second operand. If one bit is 0 and the other bit is 1,the corresponding result bit is set to
1.Otherwise result bit is set to 0.

Ops A.31

B.36

C.39

D.42

Ans: Option B) 36
Q15. What will be the output of the following pseudo code ?

1. Integer a,b,c

2. Set a=6,b=9,c=12

3. c=(c+8)+a

4. b=(a+10)&b

5. c=(2&11)+c

6. print a+b+c

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.

Ops:A.43

B.41

C.34

D.31

Ans: option c) 34
Q16. What will be the output of the following pseudo code for a=3,b=5? 1.

2. Integer funn(Integer a,Integer b)

3. if (a>6)

4. return a+b
5. Else
6. return funn(a+1,b)

7. End if

Ops: A.13

B.19

C.12

D.11

Ans: Option c) 12
Q17.What will be the output of the following pseudocode?

1. Integer a,b,c

2. Set a=4,b=3, c=8

3.b=6+a

4. if(a>b)

5. b=(1+12)+c

6. End if

7. print a+b+c

Ops: A.25

B.30

C.21

D.22

Ans: option

d)22

Q18. .What will be the output of the following pseudocode?

1. String str1=”ooolooo”,str2=”locol”

2. print ispalin(str1)

Note: ispalin (string) returns 1 if the string is a palindrome ,otherwise returns 0.EX-ispalin(“yyy”) returns
1.

Ops:A.4

B.1

C.8

D.-1

Ans:

optionb)1
Q19. .What will be the output of the following pseudocode?

1. Integer pp,qq,rr
2. Set pp=5,qq=5,rr=13

3.rr=qq&pp

4.qq=(4&4)+qq

5.pp=(pp+1)+rr

6.qq=12+qq

7.print pp+qq+rr

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.

Ops: A.39

B.37

C.33

D.47

Ans: b) 37
Q20.What will be the output of the following pseudo code?

1. Integer p,q,r

2. Set p=9,q=6,r=8

3. for (each r from 3 to 6)

4. p=(p^r)+q

5. if ( (3+p+r)<(r-q) )

6. p=1+q

7. q=2+q

8. End if

9. End for

10. print p+q

Note: ^ is the bitwise exclusive OR operator that computer each bit of its first operand to the
corresponding bit of its second operand. If one bit is 0 and the other bit is 1,the corresponding result bit
is set to 1.Otherwise result bit is set to 0.

Ops: A.47

B.49

C.44

D.55

A) 47
Q21: What will be the output of the following pseudo code ?

1. Integer j,m

2. Set m=2

3. Integer a[4]={1,0,0,0}

4. if (a[1]>1)

5. m=m+1

6. End if

7. print m

Ops:A.2

B.-5

C.21

D.6

Ans: A) 2
Q22.What will be the output of the following pseudo code?

1. String str1=”aba”,str2=”aba”
2. Print ispalin(str1+str2)

Note: : ispalin (string) returns 1 if the string is a palindrome ,otherwise returns 0.

A.-4

B.17 C.1

D.4

Ans: c)1
DATA STRUCTURES

Q 01.Find out the array representation of the given max heap, if the value 97 is deleted from it.

105,102,97,99,96,93

Ops: A.105,102,93,99,96

B.105,102,93,96,99

C.105,93,102,99,96
D.102,105,93,99,96

Ans: C.105,93,102,99,96

Q 02:Determine which of the given sequence of degree of vertices is graphic.

1.(2,4,5,5)

2.(3,3,3)

Note:A sequence is graphic if there is a simple graph with the degree sequence.

A.Only 1

B. Both 1 & 2

C.Only 2

D.Neither 1 nor 2

Ans: b) Both 1 & 2

You might also like