0% found this document useful (0 votes)
98 views66 pages

Pesudocode 1

Here are the steps to perform binary search on a sorted array: 1. Initialize low and high pointers to the beginning and end of the array respectively. 2. Calculate the mid index as (low + high) / 2 3. Compare the element at mid with the target element - If they are equal, return mid - Else if target is less than mid, update high = mid - 1 - Else update low = mid + 1 4. Repeat steps 2-3 until low exceeds high or the target is found. 5. Return -1 if target was not found after complete search. So the missing step in the given pseudo code is to initialize the low and high pointers.
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)
98 views66 pages

Pesudocode 1

Here are the steps to perform binary search on a sorted array: 1. Initialize low and high pointers to the beginning and end of the array respectively. 2. Calculate the mid index as (low + high) / 2 3. Compare the element at mid with the target element - If they are equal, return mid - Else if target is less than mid, update high = mid - 1 - Else update low = mid + 1 4. Repeat steps 2-3 until low exceeds high or the target is found. 5. Return -1 if target was not found after complete search. So the missing step in the given pseudo code is to initialize the low and high pointers.
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/ 66

1.

Find the output for the following pseudocode

Integer N=1
Integer M=10
Integer I Ans:
Sum=0 i) 10
ii) Error
For I in range of N to M iii)11
Sum=sum+I iv) 55
Print sum.
2. Find the output for the following pseudocode

Integer N=5
Ans:
Integer M=10 1. 10 5
N=N XOR M 2. 5 10
3. 5 5
M=N XOR M 4. 10 10
N=N XOR M
Print N , M
3. Find the output for the following pseudocode

Integer i
Ans:
Set i = 3
1. 5 4 6
do
2. 6 5 4
print i + 3
3. 6 4 5
i=i–1
4. 4 6 5
while(i not equals 0)
end while
4. How many times the print statement will be executed

Integer a, b, c
Set a = 8, b = 10, c = 6
If(a > c AND (b + c) > a)
Print a
Ans:
end if
1. 1
if(c > b OR (a + c) > b)
2. 3
Print b
3. 0
end if
4. 4
if((b+c) MOD a EQUALS 0)
Print c
end if
Integer a, b, c
Ans:
Set a = 8, b = 51, c = 2
1. 15
c = (a ^ c)^ (a)
2. 17
b = b mod 4
3. 14
Print a + b + c
4. 13
Integer i, j, k Ans:
Set k = 8for(each i from 1 to 1) 1. 9
for(each j from the value of i to 1) 2. 4
print k+1 3. 2
end for 4. 7
end for
Integer a, b
Set a = 15, b = 7 Ans:
a = a mod (a - 3) 1. 4
b = b mod (b – 3) 2. 0
a = a mod 1 3. 6
b = b mod 1 4. 9
Print a + b
Integer a, b, c
Ans:
Set b = 5, a = 2, c = 2
1. 2
if(b>a && a>c && c>b)
2. 13
b=a+1
3. 5
Else
4. 7
a=b+1
End if
Print a + b + c
Consider an array of float. Calculate the Ans:
difference between the address of the 1st and 1. 16
4th element, assuming float occupies 4 bytes 2. 4
of memory. 3. 12
4. 5
What is the second part of a node in a linked Ans:
list that contains the address of the next node 1. Pointer
called? 2. Data
3. Link
4. Element
With the given information provided find out
the address of Arr[17] in a 1-D array Arr[30]. Ans:
1. 1070
- lower bound = 1 2. 1132
3. 1128
- starting base address = 1100 4. 1068

- size of each element is 2.


Integer value, n
Set value = 1, n = 45 Ans:
1. 32
while(value less than equal to n) 2. 64
value = value << 1 3. 45
end loop 4. 90
Print value
Integer c, d
Set c = 15, d = 12 Ans:
d=c–1 1. 27 39
Print c //line 2. 15 27 39
c = d + (c – 2) 3. 14 26 38
if(c < 40) 4. None of the above
Goto line
end if
How many time the output would be printed?

Integer a, b, c Set a = 8, b = 10, c = 6


If(a > c AND (b + c) > a)
Print a
end if Ans:
if(c > b OR (a + c) > b) 1. 1
Print b 2. 2
end if 3. 3
if((b+c) MOD a EQUALS 1) 4. 0
Print c
end if
Predict the output of the function when a = 4
and b = 6 ?

Integer func (Integer a, Integer b)


Integer temp
while(b) Ans:
temp = a MOD b 1. 3
a=b 2. 1
b = temp 3. 4
end while 4. 2
return a
End function func()
Integer x, y, z Ans:
Set x=24, y=8 1. 0
x = x/y 2. 64
z = y<<x 3. 1
Print z 4. 4
Ans:
Integer x, y, z, a
1. 5
Set x = 2, y = 1, z = 5
2. 2
a = (x AND y) OR (z + 1)
3. 3
Print a
4. 1
Integer a, b, c, d
Set b = 18, c = 12
a=b–c Ans:
for (each c from 1 to a – 1) 1. 6 4 14
b = b + c + 12 2. 6 4 16
b = b/5 3. 5 3 9
d=b+a 4. 6 14 17
end for
c=a+b+c
Print a b c
Integer a Ans:
String str1 1. 4
Set str1 = “Terv” 2. 5
a = stringLength(str1) 3. 6
Print (a ^ 1) 4. 3
For input a = 5 & b = 5.
function (input a, input b) Ans:
If (a < b) 1. 3125
return function (b, a) 2. 15625
elseif (b != 0) 3. 525
return (a * function (a, b - 1)) 4. 625
else
return 1
Ans:
initialize char c
1. 64
set c= a
2. 65
print "%d",a
3. 97
4. Error
Integer i, j, k,c; Ans:
Set value i=0,j=1,k=0; 1. 1 2 0 1
C= i++ || ++j || k++; 2. 1 2 1 1
Print i ,j ,k ,c; 3. 1 2 0 1
4. 1 1 2 1
What will be the output of the following pseudo code for arr[]= 1,2,3,4,5

initialize i,n Ans:


intialize an array of size n 1. 3 5 9 15 20
accept the values for the array 2. 3 5 7 9 5
for i= 0 to n 3. 3 5 7 9 11
arr[i] = arr[i]+arr[i+1] 4. error
end for
print the array elements
Integer x,z Ans:
set x value as 10 1. 7 6 9
for loop starts from 10 and reduced 2. 7 6 3
till x value is 0 3. 6 7 8
z=x&(x>>1) 4. 6 7 9
if(z)
print(%d ,x)
Ans:
1. %a
Integer a; 2. 100
set a value as 100 3. %x
print("%0 %x",a) 4. error
Ans:
Float x 1. 4
long y 2. 8
set x value as 0.0 and y value as 10 3. 0
print(%d , sizeof(y)==sizeof(x+y)) 4. 1
Ans:
Integer any 1. 340
set value of any is ‘ ‘ * 10 2. 320
print any 3. 380
4. 360
Integer go,num
set value of go is 5 and num is 1*10 Ans:
do 1. 2 0 0 0 0 0
num/=go 2. Floating point exception
end do 3. 2 0 0 0 0
while go-- 4. Compilation error
print num
Predict the output of the given pseudo code if the value of n is 35

Read n
i=0 Ans:
While n%10!=0 1. 50
n=n+3 2. 55
i++ 3. 45
end while 4. 53
n=n+i
write n
What will be the output of the given pseudo code if n = 10

Read n
Initialize i to 5 Ans:
Initialize sum to 0 1. 25
while i < n 2. 35
increase sum by i 3. 45
increment i 4. 55
end while
Write sum
Predict the output of the given pseudo code if the value of number is 6

Read number
k=2 Ans:
i=2 1. 1700
while i<=number 2. 1440
k=k*i 3. 1560
i = i +1 4. 1340
end while
write k
What will be the number of " * " printed by the given pseudo code when input is 25

Write "Please enter a number"


Read input
Repeat while input > 0 Ans:
if( input > 0 and input <=10 ) 1. 55
Write * 2. 45
else if ( input >10 and input <=20 ) 3. 25
Write ** 4. 35
else if ( input >20 and input< = 30 )
Write ***
input --
end if
end while
You have written the pseudo code given alongside for performing binary search in an array of elements sorted in
ascending order. Which step to be followed in A to execute binary search successfully?

Ans:
1. Else if x is greater than the
mid element, then x can only
lie in left half subarray after
the mid element. So we recur
1.Compare x with the middle element. for left
2.If x matches with the middle element, we 2. Else if x is less than the mid
element, then x can only lie in
return the mid index. right half subarray after the
3.A mid element. So we recur for
right
4.Else ( x is smaller ) recur for the left half 3. Else if x is greater than the
mid element, then x can only
lie in right half subarray after
the mid element. So we recur
for right
4. None of the given options
Set Integer Emp_no=101 Ans:
Set Integer salary=0 1. Code executes successfully and
while (Emp_no=501) value of salary is displayed once.
salary=salary+100 2. Code executes successfully and
display salary nothing is displayed.
end while 3. Code executes successfully and
value of salary is displayed
infinite number of times.
4. Compile time error.
Ans:
Set Integer res=0 1. The program will not enter
do the loop.
--res 2. Code will run infinite number
display res of times.
res++ 3. Code will execute and value
while(res>=0) of res will be displayed twice.
end do-while 4. Code will execute and value
of res will be displayed once.
How many times will ‘#’ be displayed

for m = 0 to 4 step 1
Do Ans:
for n=0 to 4 step 1 1. 1
Do 2. 15
display '#'end-for 3. 8
if(m==2) then break 4. 2
end-if
end-for
for i=0 to 4 step 1 do
If i==i++ + --i then do Ans:
display i 1. 3 2 1 0
end-if 2. 1 2 3 4
end-for 3. 0
4. 2 0
Set Character c='7'
Ans:
switch(c)
1. Onehello
case '1': display "One"
2. Seventwohello
case '7': display "Seven"
3. Seventwo
case '2': display "Two"
4. seven
default: display "Hello"
break
end-switch
Integer a, p = 0 Ans:
Set a = 5 1. 0
a=a+1 2. 7
a=a*2 3. 1
a=a/2 4. 2
p=a/5+6
print p
Integer a, b, с Ans:
Set b = 8, a = 2 1. 3
c=a^b 2. 0
if (( c ^ b)) 3. 5
b=0 4. 7
End if
Print b
Integer a, b, c
Ans:
Set b = 40, a = 20, c = 20
1. 40
a=a+c
2. 100
c=c+a
3. 300
a=a+c
4. None of these
c=c+a
Print a + b + c
Integer a, b Ans:
Set a = 1, b = 1 1. 1
a = (a ^ 1) & (1) + (b ^ 1) & (1) 2. 2
Print a + b 3. 0
4. None of the above
int x=222
Ans:
while(x<225)
1. 0
{
2. 221 222
print x
3. 222 223
x=x++
4. None of the above
}
for i=0 to n-1
j=1
while j>0 and A[j]< A[j-1]
swap(A[j],A[j-1])
j=j+1

Ans:
1. Bubble sort is being implemented to sort an array
2. Merge sort is being implemented to sort an array
3. Insertion sort is being implemented to sort an array
4. The code doesn’t sort an array
int x Ans:
set x = 888 1. 1
if(x == 0) 2. 3
print "1" 3. 9
else if(x mod 9==0) 4. 6
print "9"
else print (x mod 9)
end if
Ans:
Integer x, y, z, a 1. 5
Set x=2, y=1, z=5 2. 2
a=(x AND y) OR (z+1) 3. 5
Print z 4. 0
int i Ans:
set i=6 do 1. 4 3 2 1 5 0
print i-1 2. 5 4 3 2 1 0
i=i-1 3. 0 1 2 3 4 5
while(i not equals 0) 4. 6 5 4 3 2 1
while loop ended
Set a=6, b=3, c=2 Ans:
if(b>a && a>c && c>b) 1. 11
b = a+1 2. 9
else 3. 5
a = b+1 4. Run time error
print a+b+c
main() Ans:
{ 1. Hai
while(!!7) 2. Haihai
printf("Hai"); 3. Infinite loop
return 0; 4. None of these
}
integer x =4, y = 0 Ans:
integer z 1. 1
z = (y++, y) 2. 0
print(z) 3. Undefined Behavior due to order of evaluation can be different.
4. Compilation error
Set j=1, k=1 Ans:
for each i from 1 to 5 : 1. 1 2 3 4 5
print(k) 2. 4 6 8 10
j+=1 3. 1 1 2 3 5
k+=j 4. 1 3 6 10 15
end-for
integer a = 40, b = 35, c = 20, d = 10 Ans:
Comment about the output of the following 1. Differ by 80
two statements: 2. Same
3. Differ by 50
print a * b / c – d 4. Differ by 160
print a * b / (c – d)
integer num = 8; Ans:
print( num << 1, num >> 1) 1. 8 0
2. 0 0
3. 16 4
4. error
integer a = 4, b = 2; Ans:
print(a^b) 1. 4
2. 1
3. 0
4. 6
int j=41, k= 37
Ans:
j=j+1
1. 42 36
k=k-1
2. 36 1
j=j/k
3. 1 1
k=k/j
4. 1 36
print(k,j)
integer a = 60, b = 35, c = -30 Ans:
What will be the output of the following two 1. 0 and 1
statements: 2. 0 and 0
3. 1 and 1
print ( a > 45 OR b > 50 AND c > 10 ) 4. 1 and 0
print ( ( a > 45 OR b > 50 ) AND c > 10 )
integer a = 984, b=10
float c Ans:
c=a/b 1. 984
print c 2. 98.4
3. 98.0
4. error
Ans:
Create integer Array ; 1. 82
Array elements ={ 2, 4, 5,78,9}; 2. 13
Sum Array even index elements ; 3. 14
4. 16
Print sum;
Create char c =’A’, b=’s’; Ans:
Integer n; 1. 180
Add c and b store n; 2. 148
Print n; 3. 150
4. 212
Create integer a, b, c ; Ans:
a=13; 1. 3
b=3; 2. 2
a Right shift of b store c; 3. 1
print c; 4. 0
Integer a=5;
Ans:
Print a pre increment , a post increment ;
1. 6 6 12
Integer b=5; 2. 7 6 13
Print b pre increment + b post increment; 3. 7 7 14
4. 7 5 13
Integer a , b , c;
Set the value of a=5 , b=11 , c=0; Ans:
1. 1 3 6
a= ++a + a++ - b++;
2. 0 3 5
b= ++b - --b + --a;
3. 1 4 6
c= ++b + ++b - a--; 4. 7 12 8
print a,b and c;
Integer n, k; Ans:
1. -44
Set n value 43;
2. -43
k = ~ n;
3. 44
print n 4. 45
Ans:
Integer n, k; 1. -14
Set n value -13; 2. -13
k = ~ n; 3. 12
print n; 4. 11
Integer n; Ans:
Set value of n =5; 1. 6
If(n=0) 2. 0
3. 2
Its true print n value ; 4. 1
Else
Print ++n;
Integer n; Ans:
Set value of n=10; 1. 10
Check the if Condition n equal to 10; 2. 11
Its true print n++; 3. 12
4. Compile time error
else
print n=n+2;

You might also like