Question Bank-PLA1001

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Predict the output

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 method does not store string value after space?


a) next()
b) nextString()
c) nextLine()
d) Both A and C
What is the range of byte data type in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned

Incremental sieve is used to alleviate the following problem of simple sieve


a)Implementation requirements
b)Space requirements
c)Both A and B
d)None of the above

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

Which of these selection statements test only for equality?


a) if
b) switch
c) if & switch
d) none of the mentioned

What is the size of int data type in Java


a)4 bytes
b)6 bytes
c)8 bytes
d)12 bytes

What is the data type of the number 12.3445?


a) Int
b) Float
c) Double
d) None of the above

Which one is a valid declaration of a boolean?


a) boolean b1 = 1;
b) boolean b2 = ‘false’;
c) boolean b3 = false;
d) boolean b4 = ‘true’
What is the runtime of Karatsuba Algorithm?
A. O(n^log3)
B. O(n^log2)
C. O(nlogn)
D. C.O(n*n)
1. &
2. ^
3. ?:

What is the order of precedence (highest to lowest) of following operators?


a) 1 -> 2 -> 3
b) 2 -> 1 -> 3
c) 3 -> 2 -> 1
d) 2 -> 3 -> 1

The purpose of hasNextInt is of the scanner class is


a)to check that the input is a Whole number
b)to check that the input is text
c)to check that the input is a number with a decimal point
d)to check that the input is a True / False value

Which is a approach of Euclidean division of polynomials out of those given below?


A. Euler's phi Algorithm
B. Euclid's Algorithm
C. Remainder Theorem
D. Euler Totient Algorithm

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

Predict the output


class Main
{
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + “”; + d);
}
}
a) 38 43
b) 39 44
c) 295 300
d) 295.04 300

Predict the output


class Main {
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
sum += i;
System.out.println(sum);
}
}
a) 5
b) 6
c) 14
d) compilation error

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

What is the range of int data type in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned

Time complexity of Simple Sieve of Eratosthenesis


A. O(n*log(log(n)))
B. O(n*log(n-1))
C. Quadratic
D. Linearithmic

Which of these selection statements test only for equality?


a) if
b) switch
c) if and switch
d) none of the mentioned

Evaluate the following Java expression, if x=3, y=5, and z=10:


++z + y - y + z + x++
A. 24
B. 23
C. 20
D. 25

A number whose numeral is rotationally symmetric is ______


A. Phi Number
B. Euclid’s numbers
C. Palindrome Number
D. Strobogrammatic Number

Which of the following algorithms is used to find GCD of two numbers


1. Euler's phi Algorithm
2. Remainder Theorem
3. Euclid's Algorithm
A. 1 Only
B. 1 and 2
C. 2 and 3
D. 1 and 3
What will be the output of the following Java program?
Class Main {
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y)
{
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y +””);
}
}
}
a) 1 3 5 7
b) 2 4 6 8
c) 1 3 5 7 9
d) 1 2 3 4 5 6 7 8 9

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

What is byte code in Java?


a) Code generated by a Java compiler
b) Code generated by a Java Virtual Machine
c) Name of Java source code file
d) Block of code written inside a class

Which of the below is invalid identifier with the main method?


a) public
b) static
c) private
d) final

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

What will be the output of the snippet given below?


double myVal = 7.4557;
Int notMyVal = (int)Math.ceil(myVal);
System.out.println(notMyVal);
a. 7
b. 8
c. 9
d. 0
What will be the output of the following Java program?

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

What is the output of the following Java code

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

What is the output of the following expressions in Java


int x = 0, y = 0 , z = 0 ;
x = (++x + y-- ) * z++;
a. 0
b.1
c.2
d.3

What is the output of the following piece of code

int[] A = {0, 2, 4, 1, 3};


for(int i = 0; i < a.length; i++){
a[i] = a[(a[i] + 3) % a.length];
}
System.out.println(A[1]);
a. 0
b. 1
c. 2
d. 3
With regards to ‘break’ keyword in Java, which of the following statement is correct?
a.It stops the execution of entire program
b. It halts the execution and forces the control out of the loop
c.It forces the control out of the loop and starts the execution of next iteration
d.It halts the execution of the loop for certain time frame

Select the invalid control statement from the given options.


a. break
b. continue
c. return
d. exit
Select the escape sequence which is invalid in the Java programming language.
a. \a
b. \b
c. \t
d. \f
With which datatypes does switch statement work?
a. short
b. int
c. char
d. All of the above
Which of the options correlates well with the definition of a computer algorithm?
a. Infinite steps of sequences
b. Pictorial representation of a problem
c. Step by step method to solve a problem
d. Indication of possible IO values for a problem

Which of the following is a graphical representation of an algorithm?


a. Data graph
b. Data Flow diagram
c. Flow chart
d. Control structure

What is the assumption of an apriori analysis of an algorithm?


a. The algorithm has been tried and tested with test cases
b. Other factors like CPI speed are not considered to have affect on the implementation of the
algorithm
c. The algorithm has been tested for efficiency and is the best available solution
d. None of the above

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)

The measure of amount of memory used for an algorithm to be executed is called?


a. Function efficiency
b. Memory efficiency
c. Amortized efficiency
d. Space efficiency

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)

Given the following definition of a function


X(g) = {f(n): there exist positive constants c and n0 such that 0 ≤ c*g(n) ≤ f(n) for all n ≥ n0}

Which asymptotic notation does ‘X’ represent?


a. Big-Theta
b. Small-theta
c. Big-O
d. Big-Omega

What is the time complexity of following code:

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 does problem of Sieve of Eratosthanes do?


a. find all primes within an upper bound
b. Find all primes within two numbers
c. Find all composites within two numbers
d. None of the above

In Segmented Sieve, regular sieve is used in finding the primes of


a. 1st segment
b. 2nd Segment
c. All segments
d. None of the above
What is the value of Φ(3)?
a. 1
b. 2
c. 3
d. 4

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

Another name for Phi algorithm is


a. Eratosthenes function
b. Totient Function
c. Incremental Sieve
d. None of the above

Incremental sieve is used to alleviate the following problem of simple sieve


a. Implementation requirements
b. Memory requirements
c. Both a and b
d. Neither a nor b

How many integers are coprime with n in Φ(n), where n = 5


a. 1
b. 2
c. 3
d. 4

Euler’s theorem Φ(n)


Involves checking GCD of n with the integers which are _______
a. Less than n and excluding 1
b. Less than or equal to n
c. Less than n and including 1
d. Less than n/2

Which of the following is NOT a Strobogrammatic number?


a. 8008
b. 8969
c. 8968
d. 1961

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?

Fill in the blanks with the options given below


A. Pairwise coprime, remainders of the numbers in array A
B. Divisible by ‘x’, pairwise coprime
C. Divisible by ‘x’, remainders of the numbers in array A
d. remainders of the numbers in array A, pairwise coprime with array A

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

What is byte code in Java?


a) Code generated by a Java compiler
b) Code generated by a Java Virtual Machine
c) Name of Java source code file
d) Block of code written inside a class

Which of the below is invalid identifier with the main method?


a) public
b) static
c) private
d) final

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

Which approach does Karatsuba algorithm use to multiply two numbers?


a. Linear Approach
b. Divide and Conquer
c. Backtracking
d.Greedy Technique

Which of the following algorithms is NOT a multiplication algorithm/theorem?


1. Booth’s algorithm
2. Chinese Remainder theorem
3. Karatsuba algorithm
4. Euclid Algorithm
a. 1 and 2
b. 2,3 and 4
c. 2 and 4
d. 1 and 3

Which of the following is NOT a nibble in the context of Java?


a. Four-bit aggregation
b. Half a byte
c. Half an octet
d. Half size of an integer

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 Karatsuba multiplication of 47 * 78, which of the following is NOT a subproblem?


a. 4*7
b. (11*15) - 28 - 56
c. 7*8
d. All of the above are the subproblems of the multiplication of the numbers

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)

Which of the following is used for binary multiplication?


a. Booth's Algorithm
b. Karatsuba’a Algorithm
c. Euler’s Multiplication Algorithm
d.None of the above

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

What is the value of n in multiplication of 110* 1000?


a. 0
b. 1
c. 2
d. 3

Which bit(s) will be checked on each cycle of the booth’s algorithm?


a. Qn-1 Only
b. Qn Only
c. Qn and Qn+1
d. Qn-1, Qn, and Qn+1

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)

Predict the output


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?
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)

Which method does not store string value after space?


a) next()
b) nextString()
c) nextLine()
d) Both A and C

What is the range of byte data type in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned

Incremental sieve is used to alleviate the following problem of simple sieve


a)Implementation requirements
b)Space requirements
c)Both A and B
d)None of the above
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

Which of these selection statements test only for equality?


a) if
b) switch
c) if & switch
d) none of the mentioned

What is the size of int data type in Java


a)4 bytes
b)6 bytes
c)8 bytes
d)12 bytes

For measuring the average-case time complexity of an algorithm, which asymptotic notation
is used?
e. Alpha
f. Theta
g. Gamma
h. 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)

Given the following definition of a function


X(g) = {f(n): there exist positive constants c and n0 such that 0 ≤ c*g(n) ≤ f(n) for all n ≥ n0}

Which asymptotic notation does ‘X’ represent?


c. Big-Theta
d. Small-theta
c. Big-O
d. Big-Omega

What is the time complexity of following code:

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)

Which of the following case does not exist in complexity theory?


e. Null Case
f. Best Case
g. Average Case
h. 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?


e. Linear (O(N))
f. Exponential (O(2^N))
g. Linearthemic (O(nlogn))
h. 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 does problem of Sieve of Eratosthanes do?


e. find all primes within an upper bound
f. Find all primes within two numbers
g. Find all composites within two numbers
h. None of the above
In Segmented Sieve, regular sieve is used in finding the primes of
e. 1st segment
f. 2nd Segment
g. All segments
h. None of the above
What is the value of Φ(3)?
b. 1
b. 2
c. 3
d. 4

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

Euler’s theorem Φ(n)


Involves checking GCD of n with the integers which are _______
d. Less than n and excluding 1
e. Less than or equal to n
f. Less than n and including 1
d. Less than n/2

Which of the following is NOT a Strobogrammatic number?


e. 8008
f. 8969
g. 8968
h. 1961
Strobogrammatic number is a number which appears the same when rotated _____ degrees
e. 360
f. 90
g. 75
h. 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
e. Set 1
f. Set 1 and 2
g. 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?

Fill in the blanks with the options given below


D. Pairwise coprime, remainders of the numbers in array A
E. Divisible by ‘x’, pairwise coprime
F. Divisible by ‘x’, remainders of the numbers in array A
d. remainders of the numbers in array A, pairwise coprime with array A

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

What is byte code in Java?


a) Code generated by a Java compiler
b) Code generated by a Java Virtual Machine
c) Name of Java source code file
d) Block of code written inside a class

Which of the below is invalid identifier with the main method?


a) public
b) static
c) private
d) final

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

Which multiplication algorithm involves the understanding of low level computing


components such as registers?
A. Karatsuba algorithm
B. Euclid’s algorithm
C. Remainder theorem
D. Booth’s algorithm

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)

Which of the following for loop declaration is not valid?


for ( int i = 99; i >= 0; i / 9 )
for ( int i = 7; i <= 77; i += 7 )
for ( int i = 20; i >= 2; - -i )
for ( int i = 2; i <= 20; i = 2* i )

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

What is the output of the Java program given below?


class Output
{
public static void main(String args[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
b++;
++a;
System.out.println(a + "" + b + "" + c);
}
}
a) 3 2 4
b) 3 2 3
c) 2 3 4
d) 3 4 4

What will be the output of the following Java code?


enum Season
{
A, B, X, Z
};
System.out.println(Season.A.ordinal());
a) 0
b) 1
c) 2
d) 3

Find the output of the program


public class Main{
public static void main(String[] args) {
char x = &#39;X&#39;;
int i = 0;
System.out.print(true ? x : 0);
System.out.print(false ? i : x);
}
}
a) X98
b) Compile time error
c) X88
d) Runtime error

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

Which of the below is invalid identifier with the main method?


a) public
b) static
c) private
d) final

What is the output of the below Java program?


int a=1;
while(a<4)
{
System.out.print(a + "; ");
a++;
}
A) 1 2 3 4
B) 1 2 3
C) 6
D) Compiler error

What is the output of the below Java program?


class static_out
{
static int x;
static int y;
void add(int a , int b)
{
x = a + b;
y = x + b;
}
}
class static_use
{
public static void main(String args[])
{
static_out obj1 = new static_out();
static_out obj2 = new static_out();
int a = 2;
obj1.add(a, a + 1);
obj2.add(5, a);
System.out.println(obj1.x + "" + obj2.y);
}
}
a) 7 7
b) 6 6
c) 7 9
d) 9 7

What is another word for half an octet?


A. four-bit aggregation
B. Nibble
C. Short Bit

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

You might also like