Professional Documents
Culture Documents
Question Bank-PLA1001
Question Bank-PLA1001
Question Bank-PLA1001
class Main {
public static void main(String args[])
{
int a = 3;
int b = 6;
int c = a | b;
int d = a & b;
System.out.println(c + "" + d);
}
}
a) 7 2
b) 7 7
c) 7 5
d) 5 2
Which of the following is a Divide and Conquer application for fast multiplication?
A. Karatsuba Algorithm
B. Booth’s algorithm
C. Euclid Algorithm
D. Irvine’s multiplcation algorithm
If you want to search from a 1D array traversing through the positions sequentially, the time
complexity would be _________
a) O(n)
b) O(log n)
c) O(n2)
d) O(n log n)
How can we simplify the following time complexity to the simplest version?
O(5*2^n + 1000*N^100)
a)O(2^n)
b)O(1000N)
c)O(1000*N^100)
d)O(5*2^n)
Which of these classes are used by Byte streams for input and output operation?
a) InputStream
b) InputOutputStream
c) Reader
d) All of the mentioned
In which memory a String is stored, when we create a string using new operator?
A. Stack
B. String memory
C. Heap memory
D. Random storage space
What is the time complexity of the basic Euclid algorithm which involves two numbers a and
b? Note that len indicates bit length.
A. O(Log (a, b))
B. O(Log min(a, b))
C. O(Log min(len(a), len(b)))
D. None of the above
Which of these is used to perform all input and output operations in Java?
a) streams
b) Variables
c) classes
d) Methods
Which of the following tool is used to generate API documentation in HTML format from doc
comments in source code?
a) javap tool
b) javaw command
c) Javadoc tool
d) javah command
How can we identify whether a compilation unit is class or interface from a .class file?
a) Java source file header
b) Extension of compilation unit
c) We cannot differentiate between class and interface
d) The class or interface name should be postfixed with unit type
An expression involving byte, int, and literal numbers is promoted to which of these?
a. long
b. int
c. Float
d. Byte
class A {
public static void main(String args[])
{
int a = 17;
System.out.print(++a * 7 + (a++));
}
}
What is the output of the snippet given above?
a. 64
b. 128
c. 144
d. 90
Which is the inbuilt tool used to generate Java API documentation in HTML format from the
Java source files?
a. JVM
b. javac
c. javadoc
d. jdoc
What is a Java Runtime Environment (JRE) ?
a. It is a implementation of JVM and physically exists with bundles of libraries.
b. It is a specification of JVM and physically exists with bundles of libraries.
c. It is a implementation of JRE and physically exists with bundles of libraries.
d. It is a implementation of JVM and virtually exists with bundles of libraries.
On what data types can modulus operator be applied?
a.Integers
b.Floating point numbers
c.Both Integers and Floating point numbers
d.None of the above
class A
{
public static void main(String args[])
{
double a = 25.64;
int b = 25;
a = a % 10;
b = b % 10;
System.out.println(a + "" + b);
}
}
a. 5.640000000000001 5.0
b.5.640000000000001 5
c.5 5.640000000000001
d.5 5
class X
{
public static void main(String [] args)
{
int x=20;
String y = (x < 15) ? "x" : (x < 22)? "s" : "l";
System.out.println(y);
}
}
a. x
b. s
c. l
d. error
class R
{
public static void main(String s[])
{
boolean a, b, c;
a = b = c = true;
if( !a || ( b && c ) )
{
System.out.println("If executed");
}
else
{
System.out.println("else executed");
}
}
}
a. If executed
b.Else Executed
c.Compilation Error
d.Runtime Error
There are four algorithms whose worst-case time complexities are given in the four options.
Which algorithm here is the worst performing for a large input size? Note that ‘N’ is the size of
the input.
Note that ‘N’ is the size of the input
a. O(N!)
b. O(NLogN)
c. O(2^N)
O(N*N)
For measuring the average-case time complexity of an algorithm, which asymptotic notation
is used?
a. Alpha
b. Theta
c. Gamma
d. Epsilon
What is the time complexity of the following piece of psuedocode?
Function f()
ans = 0
for i = 1 to n:
for j = 1 to log(i):
ans += 1
print(ans)
a.O(n)
b.O(nlogn)
c.O(n*n)
d.O(n*n*n)
int a = 0, i = N;
while (i > 0)
{
a += i;
i /= 2;
}
a. O(logN)
b. O(N)
c. O(sqrt(N))
d. O(N/2)
What is the time complexity of an algorithm where you are given an array arr of size N and
you have to search for an element starting from arr[0] till arr[N-1] linearly?
a. Linear
b. Logarithmic
c. Quadratic
d. Constant
There are four algorithms whose worst-case time complexities are given in the four options.
Which algorithm here is the worst performing for a large input size? Note that ‘c’ is a constant
here and ‘N’ is the size of the input.
a.O(Log(logN))
b.O(NLogN)
c.O(N^c)
d.O(c^N)
Which of the following case does not exist in complexity theory?
a. Null Case
b. Best Case
c. Average Case
d. Worst Case
int a[n][n]
sum = 0
// Finding sum of elements of a matrix that are strictly above the diagonal.
for i = 1 to n:
for j = i to n:
sum += a[i][j]
print(sum)
for i = 1 to n:
sum -= a[i][i]
Time Complexity of this snippet of code is?
a. Linear (O(N))
b. Exponential (O(2^N))
c. Linearthemic (O(nlogn))
d. Quadratic (O(N*2))
There are three algorithms whose worst-case time complexities are given in the four options.
Which algorithm here is the best performing for a large input size? Note that ‘c’ is a constant
here and ‘N’ is the size of the input.
a.O(N/2)
b.O(N)
c.O(NLogN)
d. Both a and b
What is the worst-case time complexity of the algorithm used in simple sieve if the input is a
number ‘n’?
a. O(nlogn)
b. O(n*n*logn)
c. O(n*log(logn))
d. O(logn*logn)
What is the auxiliary space of the Java implementation of simple sieve problem?
a. Constant
b. Linear
c. Logarithmic
d. Quadratic
Which of the following is an issue with the implementation of simple sieve that segmented
sieve aims to solve?
a. Segmented sieve is more cache friendly
b. Segmented sieve does not crash often
c. Segmented sieve does not make use of locality of reference
d. None of the above
The algorithm of segmented sieve has many steps. In the first step, the simple sieve is used to
find all primes upto ______
a. n
b. n/2
c. sqrt(n)
d. sqrt(n/2)
What is the output of the incremental sieve when integer 20 is passed to the input variable?
a. 2 3 5 7 11 13 17
b. 2 3 5 7 11 13 17 19 20
c. 2 3 5 7 11 13 17 19
d. 2 3 5 7 12 13 17 19
Strobogrammatic number is a number which appears the same when rotated _____ degrees
a. 360
b. 90
c. 75
d. 180
Which of the following sets is does NOT contain all Strobogrammatic numbers?
Set 1: 8008 1001 9006 6009 8888 1881
Set 2: 8888 1881 9886 6889 1691
Set 3: 8888 1881 9886 6889 1961
a. Set 1
b. Set 1 and 2
c. Set 2 and 3
d.All sets contain only Strobogrammatic numbers
We have been given an array A of ‘N’ numbers which are _______. We also have been given
with another array B of size N which denote the __________ when divided by a number ‘p’.
According to the remainder theorem, how do we find the minimum possible value of the
number ‘p’ which produces the given array B?
What is the output of the remainder theorem if the number array contains the elements 5 and
7 and the remainder array consist of the elements 1 and 3
A. 31
B. 32
C. 33
d. 35
Which of the following tool is used to generate API documentation in HTML format from doc
comments in source code?
a) javap tool
b) javaw command
c) Javadoc tool
d) javah command
How can we identify whether a compilation unit is class or interface from a .class file?
a) Java source file header
b) Extension of compilation unit
c) We cannot differentiate between class and interface
d) The class or interface name should be postfixed with unit type
Right Shift Circular and Right Shift Arithmetic are methods of which algorithm?
a. Booth’s Algorithm
b. Karatsuba Algorithm
c. Block Swap Algorithm
D. Euclidean multiplication algorithm
What is the space complexity of the iterative Java implementation of Block Swap algorithm
a. Linear
b. Constant
c. Logarithmic
D. Quadratic
The iterative and recursive solutions of block swap algorithms have a ______ time complexity
a. Constant
b. Logarithmic
c. Quadratic
d. Linear
What is the result of the maximum product subarray, if the elements of the array are {1, -3, 0,
7, -2}
a. 21
b. 28
c. 7
d. 6
What is the result of the function blockSwap(arr, k), if arr is {4, 6, 1, 8, 9, 2} and k is 6
a. 6, 1, 8, 9, 2, 4
b. 1, 8, 9, 2, 4, 6
c. 4, 6, 1, 8, 9, 2
d. 8, 9, 2, 4, 6, 1
Given an array {-1, -3, -10, 0, 60}, what would be the minimum product subarray?
a. {60}
b. {-10, 0}
c. {-1,-3,-10, 0}
d. {-1, -3, -10}
Given an array that contains both positive and negative integers, Maximum product subarray
involves finding the product of the maximum product subarray. Given an array {-2, -40, 0, -2,
-3}, find the subarray which makes up the maximum product subarray
a. {-2, -40}
b. {-2, -40, -3}
c. {-3, -40}
d. None of the above
One of the efficient solutions to the maximum product subarray derives its solution from
_______ algorithm
a. Block Swap
b. Euclid
c. Euler
d. Kadane
For fast multiplication, from how many subproblems does Karatsuba Algorithm reduce the
problem to?
a. From 2 to 1
b. From 4 to 2
c. From 4 to 3
d. From 3 to 2
In the problem of finding the longest sequence after flipping a bit, what is the value when the
input to the program is 12?
a. 2
b. 3
c. 0
d. 1
The time complexity of the implementation of Karatsuba algorithm is O(n^x). What is ‘x’ here?
a. log(3) with log-base 2
b. log(3) with log-base 10
c. log(2) with log-base 3
d. log(2) with base ‘e’
In a naive (slow) multiplication of two binary strings that you studied in school, what is the
time-complexity to perform the multiplication?
a. Linear
b. Logarithmic
c. Linearthmic
d. Quadratic
What is the result of the nibble-swap operation for the input of 35?
a.32
b.51
c.52
d.50
If ‘x’ is a binary number of 8 bits, what is the code to swap the two nibbles of the integer ‘x’?
a. &, <<, >>, &
b. &&, <<,>>, &&
c. &, >>, <<, &
d. None of the above
Give an integer n=27. We can flip exactly one bit. Find the length of the longest sequence of 1s
you could create.
a. 3
b. 5
c. 2
d. 1
Given a byte value 17, what would be the result of the swapping the two nibbles in it? (You
need to convert the given number into binary)
a. 17
b. 11
c. 63
d. 56
For a string S of length n, what is the worst case time complexity of the two-pointer solution
of finding whether the string is palindrome or not?
a. O(n)
b. O(1)
c. O(n^2)
d. O(logn)
According to the conventional Booth’s algorithm, what is the term for ‘A’ in a multiplication
involving B*A
a. Accumulator
b. Multiplicand
c. Multiplier
d. Quotient
You are given an integer n for which you have to find the binary palindrome. What is the
worst-case time complexity for the solution?
a.O(n)
b.O(1)
c.O(logn)
d. None of the above
In the problem of binary palindrome, which of the following expression gives a non-zero
value if a bit in the kth position (from right) is set and zero value otherwise?
a. x & (1 << (k))
b. x & (1 << (k-1))
c. x & (1 >> (k-1))
d. x & (1 >> (k))
In Booth’s algorithm, in which registers will the results of the multiplication operation be
stored respectively?
A. AC and Q
B. Q and M
C. M and Q
D. M and AC
You are given an integer n for which you have to find the binary palindrome. What is the
worst-case time complexity for the solution?
a. Logarithmic
b. Linear
c. Constant
d. None of the above
According to _______ algorithm, We keep on subtracting the smaller number from the larger
number repeatedly to obtain the _______
a. Euclid, LCM
b. Euler, Greatest Common Divisor
c. Euclid, Highest Common Factor
d. Manacher, Greatest Common Divisor
What is the time complexity of the basic euclidean multiplication of two numbers ‘a’ and ‘b’
a. O(log(max(a, b)))
b. O(log(a*b))
c. O(a*b)
d. O(log((loga)*log(b)))
If GCD of two numbers is 1, then the two numbers are said to be ________
a. Multi Prime numbers
b. Mutual Prime Numbers
c. Composite numbers
d. Co-prime numbers
In Booth’s algorithm, if ‘n’ is the number of bits of the two numbers X and Y that are to be
multiplied, what are the initial values of the registers AC and Q(n+1) respectively?
a. 0 and n
b. 0 and 0
c. n and 0
d. 0 and 0
Select the correct formula which represents the idea behind Euclid’s multiplication algorithm.
a. GCD (m,n) = GCD (n, m mod n)
b. LCM(m,n)=LCM(n, m mod n)
c. GCD(m,n,o,p) = GCD (m, m mod n, o, p mod o)
d. LCM (m,n,o,p) = LCM (m, m mod n, o, p mod o)
Which of the following is a Divide and Conquer application for fast multiplication?
E. Karatsuba Algorithm
F. Booth’s algorithm
G. Euclid Algorithm
H. Irvine’s multiplcation algorithm
If you want to search from a 1D array traversing through the positions sequentially, the time
complexity would be _________
a) O(n)
b) O(log n)
c) O(n2)
d) O(n log n)
How can we simplify the following time complexity to the simplest version?
O(5*2^n + 1000*N^100)
a)O(2^n)
b)O(1000N)
c)O(1000*N^100)
d)O(5*2^n)
For measuring the average-case time complexity of an algorithm, which asymptotic notation
is used?
e. Alpha
f. Theta
g. Gamma
h. Epsilon
int a = 0, i = N;
while (i > 0)
{
a += i;
i /= 2;
}
e. O(logN)
f. O(N)
g. O(sqrt(N))
h. O(N/2)
What is the time complexity of an algorithm where you are given an array arr of size N and
you have to search for an element starting from arr[0] till arr[N-1] linearly?
e. Linear
f. Logarithmic
g. Quadratic
h. Constant
There are four algorithms whose worst-case time complexities are given in the four options.
Which algorithm here is the worst performing for a large input size? Note that ‘c’ is a constant
here and ‘N’ is the size of the input.
a.O(Log(logN))
b.O(NLogN)
c.O(N^c)
d.O(c^N)
int a[n][n]
sum = 0
// Finding sum of elements of a matrix that are strictly above the diagonal.
for i = 1 to n:
for j = i to n:
sum += a[i][j]
print(sum)
for i = 1 to n:
sum -= a[i][i]
a.O(N/2)
b.O(N)
c.O(NLogN)
d. Both a and b
What is the worst-case time complexity of the algorithm used in simple sieve if the input is a
number ‘n’?
e. O(nlogn)
f. O(n*n*logn)
g. O(n*log(logn))
h. O(logn*logn)
What is the auxiliary space of the Java implementation of simple sieve problem?
e. Constant
f. Linear
g. Logarithmic
h. Quadratic
Which of the following is an issue with the implementation of simple sieve that segmented
sieve aims to solve?
e. Segmented sieve is more cache friendly
f. Segmented sieve does not crash often
g. Segmented sieve does not make use of locality of reference
h. None of the above
The algorithm of segmented sieve has many steps. In the first step, the simple sieve is used to
find all primes upto ______
e. n
f. n/2
g. sqrt(n)
h. sqrt(n/2)
What is the output of the incremental sieve when integer 20 is passed to the input variable?
e. 2 3 5 7 11 13 17
f. 2 3 5 7 11 13 17 19 20
g. 2 3 5 7 11 13 17 19
h. 2 3 5 7 12 13 17 19
Another name for Phi algorithm is
e. Eratosthenes function
f. Totient Function
g. Incremental Sieve
h. None of the above
Incremental sieve is used to alleviate the following problem of simple sieve
e. Implementation requirements
f. Memory requirements
g. Both a and b
h. Neither a nor b
How many integers are coprime with n in Φ(n), where n = 5
e. 1
f. 2
g. 3
h. 4
Which of the following sets is does NOT contain all Strobogrammatic numbers?
We have been given an array A of ‘N’ numbers which are _______. We also have been given
with another array B of size N which denote the __________ when divided by a number ‘p’.
According to the remainder theorem, how do we find the minimum possible value of the
number ‘p’ which produces the given array B?
What is the output of the remainder theorem if the number array contains the elements 5 and
7 and the remainder array consist of the elements 1 and 3
D. 31
E. 32
F. 33
h. 35
Which of the following tool is used to generate API documentation in HTML format from doc
comments in source code?
a) javap tool
b) javaw command
c) Javadoc tool
d) javah command
How can we identify whether a compilation unit is class or interface from a .class file?
a) Java source file header
b) Extension of compilation unit
c) We cannot differentiate between class and interface
d) The class or interface name should be postfixed with unit type
f():
int a[N + 1][M + 1][K + 1]
sum = 0
for i = 1 to N:
for j = i to M:
for k = j to K:
sum += a[i][j]
print(sum)
Time complexity of the algorithm is?
a)O(N+M+K)
b)O(N*M*K)
c)O(N*M+K)
d)O(N+M*K)
The two numbers given below are multiplied using the Booth’s algorithm.
Multiplicand : 0101 1010 1110 1110
Multiplier: 0111 0111 1011 1101
How many additions/Subtractions are required for the multiplication of the above two
numbers?
(A) 6
(B) 8
(C) 10
(D) 12
What is the valid data type for variable “a” to print “Hello World”?
switch(a)
{
System.out.println("Hello World");
}
a) int and float
b) byte and short
c) char and long
d) byte and char
Imagine we have two integers a and b. If we keep subtracting repeatedly the larger of two,
we end up with ____
a. LCM
b. HCF
c. Zero
d. Both A and B
evaluation of a logical expThe ression exit in between before complete evaluation in Java is
known as
A. Preevaluation
B. PostEvaluation
C. Short Circuiting
D. Cache Evaluation
A break statement inside a Loop like while, for, do…while and Enhanced-for causes the
program
execution ___ Loop.
A) Exit
B) Continuation with next iteration
C) Never exit
D) None
Using Booth’s Algorithm for multiplication, the multiplier -57 will be recoded as
(A) 0 -1 0 0 1 0 0 -1
(B) 1 1 0 0 0 1 1 1
(C) 0 -1 0 0 1 0 0 0
(D) 0 1 0 0 -1 0 0 1
A. A Only
B. B Only
C. A and C
D. A and B
What is the main difference between a while and a do...while loop in Java?
A) while loop executes the statements inside of it at least once even if the condition is false.
B) do...while loop executes the statements inside of it at least once even if the condition is
false.
C) while loop is fast.
D) do...while loop is fast
How many variants of the sieve algorithms are there?
A. 1
B. 2
C. 3
D. 4