Pseudo Code
Pseudo Code
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
120
187
87
27
2
Read N
Function sample(N)
s = 0, f = 1, i=1;
Do Until i <= N
f = f * i;
s = s +(i / f);
i=i+1
End Do
return(s);
End Function
716667
708333
Infinite Loop
666667
3
What will be the output if limit = 6?
Read limit
count=count+1
print n3
n3 = n1 + n2
n1 = n2
n2 = n3
End While
123581321
12358132
12358
112358
4
What will be the value of even_counter if number = 2630?
Read number
Function divisible(number)
while (num_remainder)
even_counter= even_counter+1
End If
End While
return even_counter;
5
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
49056
490563
490561
6
Code to sort given array in ascending order:
Read size
Read a[1],a[2],…a[size]
i=0
While(i<size)
j=i+1
While(j<size)
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
Line 4
No error
Line 7
Line 6
7
What is the time complexity of searching for an element in a circular linked list?
O(1)
O(nlogn)
O(n)
8
In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is
n⁄2
log 2 n – 1
log 2 n
9
Which of the following will give the best performance?
O(n!)
O(n^C)
O(n log n)
O(n)
10
How will you find the minimum element in a binary search tree?
11
How many times the following loop be executed?
ch = ‘b’;
ch++;
}
26
25
12
Consider the following piece of code. What will be the space required for this code?
int sum = 0, i;
return sum;
2n+8
2n+2
2n+4
2n
13
What will be the output of the following pseudo code?
If (a < b)
return function (b, a)
elseif (b != 0)
else
return 0
72
65
88
56
14
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
15
10
6
15
What will be the output of the following pseudo-code?
Integer n if (g > f)
for (n = f; n < g; n = n + 1)
sum = sum + n
else
15
21
16
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
3, 0, and 1
3, 0, and 2
4, 0, and 1
3, 3, and 3
17
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:
O(n3)
Θ(nLog2)
O(nLogn)
O(n2)
18
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
O(n2)
O(mn)
O(m+n)
O(n)
19
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?
t1 = t2
t1 > t2
t1 < t2
t1 = 5
20
What does the following piece of code do?
Inorder traversal
Preorder traversal
21
below is a pseudocode
Set x to 0;
Set n to 1;
x = x + n;
n = n + 1;
end write x
What is the output of the above pseudocode?
5151
100
4950
5050
22
Below is a pseudo-code
Set x to 1;
Set x1 to 0;
Set x2 to 0;
Set x3 to 1;
10)
Set x1 = x1 + x2 + x3;
Set x2 = x2 + x1 + x3;
Set x3 = x3 + x2 + x1;
Write x1;
write x2;
write x3;
x = x + 1;
Arithmetic series
Triangular series
Fibonacci series
Tribonacci series
23
What will be the output of the following pseudocode?
Integer a,b,c
Set a=6,b=84
while(b>0)
b=b/2
a=a+6
c=a+b
while(c>40)
Print a
else
Print b
c=c/10
End while
End while
Print c
12 , 4
12, 1, 48, 4
12,1,4
48, 4
24
What will be the output of the following pseudocode for i=140?
Integer fun(integer i)
Return i
Else
Return fun(fun(i-1))
138
140
139
25
Consider the following the given algorithm and identify the task performed by this
bstree(*tree)
if(tree-> root)
bstree(tree->left);
else
return (1);
bstree(tree->right);
else
return (1);
return (0);
Prim’s algorithm
Bubble sort
26
What will be the output of the following pseudocode?
Integer a,b
while(b>0)
a = b MOD 2 +a
Print (a)
else
Print(b-1)
b=b/5
a=a+1
end while
3,3,3
50,3,2
50,10,2
49,3,1
27
What will be the output of the following pseudocode?
Integer a, b, c, d, e
while(c>0)
d=a mod b
e= e + d + a
c= c - 1
End while
Print e
153
156
100
52
28
What will be the output of the following pseudocode?
Integer k, a, j, n
Set a = 3, n = 4
End for
End for
Print array1[k]
End for
2 3 34 56
34 2 3 56
56 34 3 2
29
What will be the output of the following pseudocode?
Integer j,i,count,num
if((num&1) is EQUAL to 1)
else
count=count+1
num = num>>1
End while
Print count
5
12
95
30
What will be the output of the following pseudocode for a given set of input?
integer a
a=a*2
a=a/5
else
a=a-1
end if
a=35,a=25
a=25,a=15
a=15,a=20
a=5,a=15
31
What will be the output of the pseudocode?
Integer x, y, z
Set x=10,y=12,z=12
z=(x+y)/4
Print successful
Else
Print unsuccessful
Error
unsuccessful
successful
32
What will be the output of following pseudocode?
Integer a,b,count,count1
while(a<=5)
b=1
while(b<=5)
b=b+1
count1 = count1 + 1
end while
a= a + 1
count = count +1
End while
count=50 count1=25
count=50 count1=5
count=45 count1=25
count=5 count1=25
33
what will be the output
#include<stdio.h>
int main()
--expo;
return 0;
Error
100, 10
10,100
34
What will be the output of following pseudo code?
Integer i,j,sum,n
Set sum=0,n=7
sum=sum +(i*i)
End loop
Print sum
160
140
120
100
35
What will be the output of the following:
Integer a,b,c
Set a=10,b=20
for(c=a;c<=b;c=c+2)
a=a+c
b=b-a+c
if(a>10)
Print a
else
Print b
End if
End for
40
30
20
10
36
What will be the output of the following c code?
#include
int main()
int a = 45;
int i=sizeof(a);
printf("%d",i);
37
what will be output of following c code?
#include<stdio.h>
int f(int n)
if(n<=0)
return 1;
if(n>3)
a=n;
return f(n-1) + a;
int main()
printf("Result: %d",f(5));
return 0;
18
19
38
What will be the output of the following pseudo-code for input 7?
Set m=1,T=0
If m >N
Go to line No. 9
Else
T= T+m
m=m+1
Go to line no.3
Stop
56
76
32
28
39
what will be the output of the following algorithm for Num=10?
Start
sap=sap+I
J=sap
End loop
Print J
85
65
75
55
40
Consider the following pseudocode.
a=1;
b=1;
while(a<=500)
Begin
a=2^a;
b=b+1;
End
41
What will be the output of the following pseudocode?
integer a, b, c;
Set a = 3;
b = 5;
c = 1;
a = a + b + c - 8;
b = a + c - 8;
if (a > b)
Print fine
else
None of these
Error
Thank you
Fine
42
What will be the output of the following pseudocode if n=5 and element of the array are 24,20,60,100,200?
#include <stdio.h>
integer
integer x;
if (n is equal to 1)
return a[0];
else
x = fun (a, n - 1);
if (x == a[n - 1])
return x;
else
400
300
200
100
43
What will be the output of the following pseudocode?
integer a = 1, b = 2;
a = a + b + i;
a = a + b;
b = a - b;
Print b End for
13 10 47 70
13 10 27 70
3 10 27 70
30 10 27 70
44
What will be the output of the following code :
Integer a, b, c, v;
Set a = 5;
b = 6;
v = 90;
while (v > 8)
a = a + v;
c = (a + b) % 10;
while (c > 9)
b = b - a;
c = c - 1;
End while
v = v/2
End while
Print b, c
35
17
57
69
45
What will be the output of the following code ?
Print *
End for
Line break
End for
Error
46
What will be the output of the following pseudocode?
integer a, b, c;
Set a = 6;
b = 84;
while (b > 0)
b = b / 2;
a = a + 6;
c = a + b;
if (c mode 2 is equal to 0)
Print a
else
Print b c = c / 10;
12 1 4 48
10 12 4 48
1 12 48 4
12 1 48 4
47
what will be the output of the following pseudocode?
Set orig=n;
rem=n%10;
rev=rev*10+rem;
n=n/10;
End while
if(orig is Equal to rev)
Print rev
else
Print (orig-rev)/6
End if
105
495
110
120
48
What will be the output of the pseudocode?
Integer i,j,sum,n;
sum=sum+j
End loop
End loop
Print sum
75
90
84
80
49
For what value of a b and c the following pseudocode will execute both the print statements?
integer a,b,c;
set a = 5, b = 4, c = 7;
if(a>b OR a>c)
Print a
Print b
59
49
32
54
50
What will be the output of the following pseudocode?
integer a,b;
while(b>0)
a = b%2 + a;
Printf a
else
Print b-1
b = b/5
a=a+1
End while
254
294
458
123
51
What will be the output of the following pseudocode?
Set a1 = 2 b1 = 45 c1 = 36;
Set a2 = 11 b2 = 26 c2 = 30;
c = c1 + c2;
b = c / 60;
c = c % 60;
b = b + b1 + b2;
a = b / 60;
b = b % 60;
a = a + a1 + a2;
Print a:b:c
20 : 22 : 26
14 : 12 : 6
10 : 15 : 60
5 : 10 : 15
52
What will be the output of the following pseudocode if n=40 and LIMIT=100?
if(n <+ 0)
return 1;
return 2;
Print ,n
fun2(2*n);
Print n
80 120 120 80
40 80 80 40
20 40 40 20
10 20 20 10
53
For which of the following sets of input, the following pseudocode will print Q?
integer a=32,b=69,c=68;
if(a+c>b)
if(b<c)
printf("P");
else
printf("Q");
54
What will be the output of the following pseudocode for x=3 and y=4?
if(x>0)
fun(x-1,y+1);
End if
Print y
2034
5214
7654
8542
55
What will the output of the following pseudocode for i=140?
integer fun(int i)
if((i%2)!=0)
return i;
else
return fun(fun(i=1));
56
What will be the output of the following pseudo-code for a given array a[5]=3,4,6,1,2 and pos=2
Declare i,j,n,pos
Repeat for j=pos to n-1
n=n-1;
End
3615
324615
3415
34215
57
What will be the necessary condition to get the desired element from a given array by using the following algorithms?
Do_Something(DATA, N, ITEM,LOC)
MID = (LOW+HI)/2
IF ITEM = DATA[MID] do
LOC+MID
Return LOC
HI = MID-1
ELSE
LOW = MID+1
58
What will be the output of the following C code?
#include<stdio.h>
int main()
int x = 2, y = 0, z = 3;
59
What will be the output of the following C code?
a=a+b+c-8;
b=a+c-8;
if(a>b)
Print fine
else
Error
Thank you
Fine
60
consider the following given code and predict its output.
main()
int *a,*b;
int i;
a=num;
b=num+2;
i=*a++;
4,4,8
2,1,8
4,1,8
1,4,8
61
What will be the output of the following code?
#include <iostream>
int main()
{
int x=1,y=1;
for(;y;cout<<x<<y<<" ")
y=x++ <=5;
return 0;
21 31 41 51 61 70
21 31 51 61
22 23 44 55
31,71,41,60,21
62
What will be the output of the following code?
#include<stdio.h>
int main()
int i=1,j;
for(;;)
if(i)
j=--i;
if(j<5)
printf("Advance ",j++);
else
break;
return 0;
}
Compile-time error.
No, compile error but it will run into an infinite loop printing Advance.
63
What will be the output of the following code?
#include<stdio.h>
int main()
int x=4,y=0;
int z;
z=(y++,y);
printf("%dn",z);
return 0;
compiler error
zero - '0'
64
What will be the output of the following code?
#include <stdio.h>
int f(int n)
if(n<=0)
return 1;
if(n>3)
a=n;
return f(n-2)+2;
return f(n-1)+a;
int main()
printf("Result:%d",f(5));
return 0;
12
18
19
65
What will be the output of the following C code?
#include <stdio.h>
if(n<=0)
return ;
if(n>LIMIT)
return ;
printf(" %d ",n);
fun2(2*n);
printf(" %d ",n);
int main()
fun2(17);
return 0;
66
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x=9,y=2,z=6;
int a=x&y|z;
printf("%d",a);
return 0;
Error
67
What will be the output of the following C code?
#include <stdio.h>
union Sti
int nu;
char m;
};
int main()
union Sti m;
printf("%d",sizeof(m));
return 0;
16
12
68
What will be the output for the pseudocode for x=11, y=57
fun(int x,int y)
if(x==0)
return y;
else
Zero (0)
None of these
69
What will be the output of the following algorithm?
#include<stdio.h>
int main()
temp = no;
digit = no % 10;
sum = sum + digit;
no /= 10;
printf("%dn",sum);
return 0;
17
16
15
70
What will be the output of the following C code
#include<stdio.h>
int main()
int x=2,y=0,z=3;
Error
Zero (0)
2
71
What will be the output of the following C code
#include<stdio.h>
int main()
char a='D';
printf(" %d",a);
return 0;
Error
69
68
67
72
What will be the output of the following C code
#include<stdio.h>
int main()
for(i=0;i<5;i++)
a++;
if(i == 3)
printf("Hello world");
break;
printf("%d",a);
return 0;
hello world
73
What will be the output of the following C code
#include<stdio.h>
void main()
int k=4;
int r = 3;
p = &r;
printf("%d", p);
74
what is the maximum degree of any vertex in a simple graph with n vertices ?
n-1
2n-1
n+1
75
What will be the output for the pseudo-code for p=22, q=127
fun(int p,int q)
if(p==0)
return q;
else
Error
76
find out the number of interchanges needed to convert the given array into a max-heap.
89,19,50,17,12,15,2,5,7,11,6,9,100
3
4
77
Which of the following statements is/are TRUE for undirected graphs ?
Both P and Q
Neither P nor Q
Q Only
P Only
78
what will be the output of the following algorithm?
Start
Declare a, I and b
for I =0 to 4
Increment a by 1
if I = 3 then
print hello
End if
End for
print a
hello
hello4
1
79
what will be the output of the following pseudocode?
Input m =9,n = 6
m = m + 1
n = n + 1
m = m + n
if(m>n)
print m
else
print n
10
17
80
what will be the output of the following pseudocode?
Set x =0 and y =1
print x
x = x + y
y = x / y
End of loop
0138
1024
0123
0124
81
what will be the output of the following pseudo code ?
Integer n
if (g > f)
sum=sum+n
End of loop
else
print sum
21
15
82
what will be the output of the following pseudocode?
Input : 5
Algorithm(integer num)
if num mod i = 0
i= i+1;
if (i==(num/2)+1)
print "successful"
Un- Successful
Successful
83
what will be the output of the following pseudocode?
Input n = 1234
Integer q, r and rn
While (q > 0)
r = q mod 10
rn = rn + r^3
q= q / 10
End of loop
print rn
321
110
100
36
84
what will be the output of the following pseudocode?
function(Input a, Input b)
if(a < b)
Elseif (b !=0)
else
return 0
65
78
82
85
Consider the following operation along with Enqueue and Dequeue Operation on queues, where k is a global parameter
MultiDequeue (Q)
n = k
Dequeue (Q)
n = n - 1
}
What is the worst-case time complexity of a sequence of ‘m’ Multiplexer () operation on an initially empty-queue?
0(m+k)
0(mk)
0(m^2)
0(m)
86
Which one correctly defines Full-Adder?
Option:-
A-An adder circuit having two inputs used to add two binary digits. It produces their sum and carries as Input.
B-An adder circuit having three inputs used to add two binary digits plus a carry. It produces their sum and carry as
outputs.
C-An adder circuit used in the least significant position when adding two binary digits with no carry-in to consider. It
87 Predict the output of the given pseudo code if the value of the number is 6:
Read number
k=2
i=2
while i <= number:
k=k*i
i = i +1
end while
write k
a)1440.0
b)1340.0
c)1700.0
d)1560.0
if(q EQUALS 0)
return 0
B. 7
C. 12
D. 8
90 What will be the output of the following pseudocode?
Integer x, y, Z, a
Set x=2,y=1,z=5
a = (x AND y) OR (z + 1)
Print a
A. 5
B. 3
C. 2
D. 1
91 What will be the output of the following pseudocode for a = 2, b = 3?
doSomething(Integer a, Integer b)
if(b EQUALS 1)
return 0
else
A. 3
B. 4
C. 2
D. 1
92 What will be the output of the following pseudocode?
Integer a, n, sum, q, r
Set q=a
n=n+1
q=q/10
End while
Print n
sum =sum + r
a =a/power(10, n- 1)
End while
Print sum
A. 3 2
B. 6 4
C. 6 5
D. 3 4
93 What will be the output for the following pseudocode?
Integer a=5,b=8,c
if(a>8 OR b < 7)
c=a+b
elseif(a + b > 9)
c=a-b
else
a=a+5
c=c-2
end if
a=a+b
Print a and c
b=b-5
[Note: OR — The logical Or operator returns the Boolean value if either or both operands
are true and returns false otherwise.]
B. 5 -3
C. 5 1
D. 13 -3
C. Code executes successfully and value of salary is displayed infinite number of times.
B. 1
C. 2
D. 8
A. 0
B. 3
C. 1
D. 2
98 What will be the output of the following pseudocode?
A. SevenTwoHello
B. OneHello
C. SevenTwo
D. Seven
99 What will be the output of the following pseudocode?
A. 3
B. 5
C. 8
D. None of these
100 What will be the output of the following pseudocode?
A. 0
B. 1
C. 2
D. 7
101 What will be the output of the following pseudocode?
A. 3
B. 0
C. 10
D. 2
102 What will be the output of the following pseudocode?
A. 40
B. 100
C. 300
D. None of these
A.1
B. 2
C. 0
D. None of these
104
What will be the value of the following pseudocode?
Set value = 1, n = 45
Print num
A.44
B.0
C.1
D.12
Integer x, y
x=x+2
end for
Print x
A.11
B.10
C.12
D.13
106 What will be the value of the following pseudocode?
Integer j, m
Set m = 1, j = 1
if(a[0])
a[j] = 5
End if
m = m + a[j]
Print m
A.3
B.2
C.6
D.4
107 What will be the value of the following pseudocode for k=150?
fun(integer k)
if(k>155)
return
end if
print k
fun(k+2)
print k
C. 150
for(each k from 0 to 4)
end for
for(each 1 from 0 to 4)
Print c[1]
end for
A. 7 13 13 11 11
B. 3 5 1 -5 -9
C. -3 -5 -1 5 9
D. None
109 How many times “A” will be printed in the following pseudocode?
Integer a, b, c
for(a = 0 to 4)
for(b = 0 to 2)
Print “A”
End for
End for
End if
A.8
B.7
C.9
D.10
Integer p, q, r
Set q = 13
for(each p from 1 to 4)
r = q mod p
p=p+5
q=p+r
end for r = q / 5
Print q, r
A.6 4
B.1 3
C.7 2
D.6 1
Integer x
Print “0”
Print “9”
otherwise
Print x MOD 9
end if
A. 8
B. 16
C. 7
D. None
Integer a, b
Set a = 12, b = 25
a = (a + b) MOD 2
b=b=a
a = a + b - 13
Print a, b
A. -11 1
B. -12 00
C. 11 22
D. 37 24
Integer a, b, c
Set a = 4, b = 4, c = 4
if (a & (b ^ b) & c)
a = a >> 1
End if
Print a + b + c
A.16
B.24
C.8
D.12
114 What will be the output of the following pseudocode for a = 10, b =
11?
if(0)
End if
a=a+a+a+a
return a
A.40
B.30
C.44
D.0
a = a+b+b-2
return 3-a
Else
End if
return a-b+1
A.0
B.5
C.16
D.11
Else
End if
return a-b
return a+b
A.-9
B.5
C.6
D.21
if(a > b)
End if
if(b > a)
End if
b=b^a
a=a^b
return a + b
A. 35
B. 20
C. 14
D. 25
Integer x
Set x = 2
if(x is EQUAL TO 1)
if(x IS EQUAL TO 0)
Print “A”
else
Print “B”
end if
else
Print “C”
end if
A.B C
B.C
C.A
D.B
c = c - 1;
if (c == 0) retum 1;
x = x + 1;
return f(x, c) * x;
In above program the first parameter is passed by reference and the second parameter is
passed by value. If the value of p = 5 before the call then what is the value that returned
by f(p, p)?
A. 6561
B. 161051
C. 55440
D. 3024
120 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
121 What will be the output if limit = 6?
Read limit n1 = 0, n2= 1, n3=1, count = 1;
count=count+1
print n3
n3 = n1 + n2
n1 = n2
n2 = n3
End While
A. 1235813
B. 12358
C. 123581321
D. 12358132
Read number
Function divisible(number)
while (num_remainder)
even_counter= even_counter+1
End If
End While
return even_counter;
A. 3
B. 4
C. 2
D. 1
123 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
Read number
Function divisible(number)
while (num_remainder)
even_counter= even_counter+1
End If
return even_counter;
A. 3
B. 4
C. 2
D. 1
125 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
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
127 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
128 What will be the output of the following pseudo code?
Integer n
if(g>f)
for(n=f;n<g;n=n+1)
sum=sum+n
print sum
A. 21
B. 15
C. 9
D. 6
count=count+1
print n3
n3 = n1 + n2
n1 = n2
n2 = n3
End While
A. 1235813
B. 12358
C. 23581321
D. 12358132
130 Count the number of " * " printed by the given pseudo code when the input is 25.
Write "Please enter a number"
Read input
Repeat while input > 0
if( input > 0 and input <=12 )
Write *
else if ( input >12 and input <=24 )
Write **
else if ( input >24 and input< = 30 )
Write ***
input --
end if
End while