You are on page 1of 23

What is the output of the following code ?

What
8. Whatis the
is theint a =of10,
output
output thebthe
of = 20;
following code
following ? ?
code
BASIC I/O,OPERATORS System.out.println((a
int a = 5; int >a =
5)10,
? (bb <=
30
20; ? "Yes" : "No") : "No");
a += a++ + ++a; Yes No Compile error
System.out.println(a);
System.out.println(~a);
What is the result of the following expression? 15 16 17
+ 2 * System.out.println(~;
5What 3 result of the following expression? -10, -20 -11, -21 -9, -19
What is is the
the output of the following code ? 21 11 13
5int>a3=|| 10,
2 <b1= 20;
System.out.println(a >> 1); true false error
1.What is isthethe
result
System.out.println(b
What
What is the
of >>
output
output
thethe
expression
the1);
of of following
following
5 code
code
^ 3? ?
?
2 3 6
int x = 5, y = 10; int a = 10, b = ?20, c = 30; 5, 10 5, 5 10, 20
What is the output of the following code
System.out.println(x++ * y++); int x = 10, y = 20; 50 55 60
System.out.println(a += b -= c *= 2); -50 -40 -30
System.out.println(x ^ y); 10 20 30
Decision making and Control structures
What is a control structure in Java? A block of codeA way to manaA group of vari
Which of the following statements is true about the if-else sta It can only hanIt can handle mIt can handle
System.out.println("Universe");
} Hello World Goodbye UnivHello
12345 1234 2345
Which of the following statements is true about the do-while l It is a pre-test It is a post-tesIt can only exe
What
x--; is the purpose of the break statement in Java? To exit a loop To skip to the To execute a bl
} 54321 12345 55555
Which of the following is not aMania");
System.out.println("Interview valid jump statement? return continue break
} byte and short char and long byte and char
With regards to ‘break’ keyword in Java, which of the followinit stops the ex It halts the ex It forces the co
Time & Space complexity
What
for is
j inthe time complexity of an algorithm that performs n/2 O(n)
range(n): O(log n) O(n log n)
print(i * j) O(1) O(n) O(n^2)
What is the space complexity of an algorithm that uses an arrayO(1) O(n) O(m)
What is space complexity? The amount ofThe amount ofThe number of
Which of the following is an example of an O(1) space comple Quicksort Merge sort Bubble sort
The space complexity of a recursive function is proportional to The number ofThe number ofThe number of
Which of the following statements is true about space complex Space complexSpace complexSpace complex
Which of the following options represents the space complexit O(1)
print(i*j*k) O(n) O(n^2)
O(n) O(n^2) O(n^3)
Which of the following is the most efficient algorithm in term O(n) O(n^2) O(n log n)
SIMPLE SIEVE
What is the sum of all prime numbers less than 50? 321 328 490
Which of the following is an optimization used in the Sieve o Using a linked Marking only Using a heap i
Which of the following is a step in the Sieve of Eratosthenes a Finding the g Multiplying al Dividing all n
Which of the following is not a step in the Sieve of Eratosthen Create a boole Mark all multi Mark all multi
What is the space complexity of the Sieve of Eratosthenes algo O(n) O(log n) O(sqrt(n))
How many prime numbers less than or equal to 100 can be found 24 25 26
Which of the following is a drawback of the Simple Sieve alg Requires less Requires mor Takes less tim
Which of the following is a drawback of the Simple Sieve alg Requires less Requires mor Takes less tim
In the Sieve of Eratosthenes algorithm, what is the maximum n n-1 sqrt(n)
How many prime numbers are there between 100 and 200? 23 21 10
Segmented and incremental sieve
What is the main advantage of the segmented sieve algorithm ov It uses less meIt is faster fo It is easier to
How does the Incremental Sieve algorithm work? It generates a It generates It generates a
In a step of segmented sieve, it finds primes smaller than or eq Sqrt(n) Sqrt(logn) N
What is the output of
ans += 1the incremental sieve when n=20 is given 2 3 5 7 11 13 2 3 5 7 11 13 2 3 5 7 11 13
print(ans) O(logn) O(n) O(nlogn)
What is the time complexity of the Incremental Sieve algorith O(n log log n) O(n log n) O(n)
What is the space
formulacomplexity of thethe
for calculating Incremental
nth primeSieve
numberalgorit
usingO(1)
the Incremental O(log
Sieven)algorithm?
O(n)
n * (n - 1) + 2 n * n - n + 1 n * n + n + 1
What is the purpose of the "cross-off" step in the Segmented STo remove nonTo find all pri To generate all
What is the advantage of using the Segmented Sieve algorithmThe SegmentedThe SegmentedThe Segmented
Euler's phi Algorithm
Which of the following statements is true about Euler's phi funIt is a multipli It is an additi It is a linear
What is the relationship between the values of ϕ(n) and ϕ(p^k) ϕ(n) = p^k - 1ϕ(n) = p^(k-1) ϕ(n) = p^k
What is the relationship between the values of ϕ(n) and ϕ(m) f ϕ(nm) = ϕ(n) +ϕ(nm) = ϕ(n)ϕ ϕ(nm) = ϕ(n) -
If ϕ is the Euler’s Totient function, then ϕ(92) is: 42 44 56
Which of the following algorithms uses Euler's Totient Functi Sieve of EratosPollard's Rho RSA algorithm
What is the output of phi(324)? 98 90 108
Which of the following is an efficient algorithm for computingTrial division Wheel factorizSieve of Erato
What is the value of phi(n) for n = 12 using Euler's phi functio 1 2 6
Which of the following real-life scenarios can be modeled usinEstimating the Calculating th Determining th
What is the value of Euler's Totient Function for the number 789 880 800
Strobogrammatic Numbers
What is a Strobogrammatic Number? A number thatA number that A number that i
What are the two possible Strobogrammatic digits? 0 and 1 0 and 8 2 and 7
How many Strobogrammatic Numbers are there between 1 and10 20 30
What is the strobogrammatic number that is the largest prime 11 101 181
Which of the following is not a Strobogrammatic Number? 818 1881 969
What is a Strobogrammatic Number? A number that A number that A number that
How many Strobogrammatic Numbers are there with n digits? 2^(n-1) 2^n 3^(n/2)
Which of the following statements is true about Strobogram They are only They are alwa They can be u
Which of the following is a Strobogrammatic Number? 10301 282 68086
Which of the following is a property of strobogrammatic numbThey are alwa They are alwa They are alwa
Remainder theorem
Consider a number that leaves a remainder of 2 when divided 76 158 156
17 11 10
The Chinese Remainder Theorem is often used in which field?Number theoryGeometry Algebra
Which of the following is the correct notation for congruence?a = b (mod n) a = b % n a%n=b
Which of the following congruences
System.out.println(quotient + " " + is true?
remainder); 5 ≡ 1 (mod 3) 7 ≡ 2 (mod 5) 10 ≡ 3 (mod 6)
33 22 12
Which of the following is equivalent to the congruence 3x ≡ 2 a) x ≡ 3 (mod b) x ≡ 2 (mod c) x ≡ 3 (mod
What is the smallest non-negative integer solution to the cong 1 2 4
What is the inverse of 3 (mod 7)? a) 1 (mod 7) b) 2 (mod 7) c) 3 (mod 7)
23 47 119
In cryptography, the Chinese Remainder Theorem is used for: Generating r Encrypting meDecrypting me
Answer
Runtime error Yes
18 18
9, 19 -9, -19
30 13
none of the a true
8 6
20, 40 5, 10
65 55
-20 -30
0 30

A mechanism fo A way to manage the flow of execution in a program


It cannot hand It can handle multiple conditions using logical operators
World Hello World
None of the a 1 2 3 4 5
It can execut It is a post-test loop
To declare a vaTo exit a loop completely
11111 54321
goto goto
int and float byte and char
It halts the ex It halts the execution and forces the control out of the loop

O(n^2) O(n)
O(log n) O(n^2)
O(n + m) O(n + m)
The efficiency The amount of memory required to execute a program
Counting sort Counting sort
The number ofThe number of function calls
Space complexiSpace complexity is a measure of how much memory a program uses.
O(2^n) O(n)
O(n^4) O(n^3)
O(2^n) O(n)

345 328
None of the a Marking only odd numbers as non-prime
None of the a None of the above
Find the grea Find the greatest common divisor of each number
O(1) O(n)
13 25
Takes more ti Requires more memory
Takes more ti Requires more memory
n/2 sqrt(n)
12 10

It can handle l It can handle larger ranges of numbers.


None of the a It generates prime numbers by adding a constant increment to a previous prime number
N/2 Sqrt(n)
2 3 5 7 12 13 2 3 5 7 11 13 17 19
O(n*n) O(nlogn)
O(sqrt(n)) O(n)
O(sqrt(n)) O(1)
n*n+2 n*n-n+1
To generate twTo remove non-prime numbers from the segment
The SegmentedThe Segmented Sieve algorithm can generate prime numbers up to a larger limit

None of the abIt is a multiplicative function


ϕ(n) = (p-1)*p ϕ(n) = (p-1)*p^(k-1)
None of the abϕ(nm) = ϕ(n)ϕ(m)
71 44
Primality testi RSA algorithm
120 108
Euler's produc Euler's product formula
4 4
Predicting the D. Predicting the number of different chemical
670 800

A number that A number that reads the same when rotated 180 degrees
5 and 6 0 and 8
40 30
There is no s There is no strobogrammatic number that is prime
666 666
A number that A number that can be read the same way upside down
n! 3^(n/2)
They are alwa They can be used in cryptography to encode messages
73627 282
They are alwa They are always palindromic

67 158
13 17
Calculus Number theory
a ≡ b (mod n) a ≡ b (mod n)
4 ≡ 6 (mod 8) 7 ≡ 2 (mod 5)
34 22
d) x ≡ 4 (mod d) x ≡ 4 (mod 5)
5 4
d) 4 (mod 7) b) 2 (mod 7)
167 23
Hashing algor Decrypting messages.
me number
What will be the output of the following Java program?
1. What
What is A is the
the output
output of of
thethe following
following code
code ? ?
class
BASIC I/O,OPERATORS
int x = 5, y = 10;
{ is the output of theintfollowing
What a = 10, bcode
= 20,?c = 30;
System.out.println(x++ * y++); int x = 10,System.out.println(a 50 55
Whatpublic
is the static
outputvoid main(String
of the code ? y = 20;
following args[])
+= b {-= c *= 2); int a = 10, b = 20; -50 -40
System.out.println(x ^ y);
double a = 25.64; 10 20
What is int b = 25;of the
System.out.println((a
the output > 5)following
&& (b < code
30)); ? true false
Which a =
int aof=thea % 10;
10,following
b = 20; operators has the highest precedence in J Logical NOT (!) Addition (+)
b = b % 10;
System.out.println(a
What & ; following expression?
is System.out.println(a
the result of the 100 20
+ "" + b);
} 2+3*4%5-6 21 -11
What
} is the result of the expression 10 - 4 * 2 + 3 % 2+(45+6-7) 47 43
5.64000000000005.6400000000000
What is the result of the expression 10 > 5 || 3 < 2? true false
Decision making and Control structures
Which of these statements is incorrect? switch statement two case constant
Which of the following statements is true about the if-else statem It can only handl It can handle mult
Which of these are selection
System.out.println("x statements
is greater than orinequal
Java?to y or x is equal toif()
y"); for()
} x is less than y x is greater than
What is a control structure in Java? A block of code t A way to manage
Which of these selection statements test only for equality?
System.out.println("Universe"); switch if & switch
} Hello World Goodbye Univers
} x is greater than x is less than y
01234 0134
Which of the following is not a looping statement in Java? for while
Time
Which&ofSpace complexity
the following algorithms has the highest time complexity?
O(n log n) O(n^2)
Which of the following data structures has the highest space compArrays Linked lists
Which of the following asymptotic notations is used to provide l × Ω
Which case indicate the minimum time required for program exec best case average case
_________ is the formal way to express the upper bound of an algOmega Notation Theta Notation
Asymptotic analysis is _______ bound output input
f(n) = 3n2+4n+2 which will be the exact value for f(n)? O(n^2) Ө(n^2)
The time complexity of the non-deterministic algorithm is alwaysless than determigreater than deter
What
for is
j inthe time complexity of an algorithm that performs n^2/4 oO(n)
range(n): O(log n)
print(i * j) O(1) O(n)
SIMPLE SIEVE
What is the 100th prime number according to the Sieve of Eratost345 546
What is the time complexity of the Sieve of Eratosthenes to checkO(nlog(logn)) Pr O(n) Precomputati
The Simple Sieve algorithm is used to find: Prime numbers upComposite numbers
Which of the following is a drawback of the Simple Sieve algori Requires less m Requires more m
In the Sieve of Eratosthenes algorithm, how many times is each prime Oncenumber usedTwice
to mark its multiples?
Which data structure is used in the Simple Sieve algorithm? Stack Queue
What is the first prime number found by the Sieve of Eratosthene1 2
In the Sieve of Eratosthenes algorithm, what is the maximum pri n n-1
Which of the following is not an optimization of the Sieve of Era Starting the iter Skipping even n
In the Sieve of Eratosthenes algorithm, which numbers are initia All even number All odd numbers
Segmented andans incremental
+= 1 sieve
print(ans) O(logn) O(n)
What is the space complexity of the Incremental Sieve algorithm? O(1) O(log n)
How do
What youformula
is the generatefor
thecalculating
next primethenumber usingnumber
nth prime the Incrementa
using theBy adding theSieve
Incremental in By algorithm?
adding the in
n * (n - 1) + 2 n * n - n + 1
What is the time complexity of the Incremental Sieve algorithm? O(n log log n) O(n log n)
What is the purpose of the "cross-off" step in the Segmented SievTo remove non-pTo find all prime
What is the advantage of using the Segmented Sieve algorithm ove The Segmented Sie The Segmented Sie
What is the main advantage of using a bitset instead of an array It uses less memoIt is faster
What is the main difference between the Incremental Sieve and thThe Incremental The Sieve of Erato
What is the time complexity of the segmented sieve algorithm? O(n) O(n log n)
Euler's phi Algorithm
What is the value of phi(1) using Euler's phi function? 0 1
What is the value of phi(p) using Euler's phi function, where p i 1 p-1
What is the value of phi(pq) using Euler's phi function, where p p+q pq
What is the time complexity of Euler's phi algorithm? 0(n) O(logn)
What is the Euler's phi function? It calculates the It counts the num
What is the output of phi(800)? 400 320
What is the value of phi(n) for n = 1,000 using Euler's phi functi 100 400
Which of the following is an application of Euler's phi function? Cryptography Generating prime
What is the output of phi(10)? 2 4
Which of the following is a disadvantage of using Euler's phi fun It requires prec It is computationa
Strobogrammatic Numbers
How many Strobogrammatic Numbers are there in base 5 that are0a 1
Which of the following is not a Strobogrammatic Number in base69 101
How many Strobogrammatic Numbers are there in base 10 that ar0 1
Which of the following is a Strobogrammatic Number in base 8? 355 209
Which of the following is a property of Strobogrammatic Number They are alwaysThey can be repre
What are the possible digits in a strobogrammatic number? 0, 1, 2, 3, 4, 5, 6,0, 1, 2, 5, 8
In binary, which of the following types of numbers are strobogra Palindromic numb Mersenne number
Which of the following is NOT a strobogrammatic number? 808 6119
Which of the following statements about strobogrammatic numbers The concept of Strobogrammatic n
How many Strobogrammatic Numbers are there with n digits? 2^(n-1) 2^n
Remainders Therorem
Find x such that 3x ≡ 7 (mod 10) x ≡19 (mod 10). x ≡ 9 (mod 11).
Which of the following statements
System.out.println(quotient + " " is true regarding the Chines It can only be a It can be applied
+ remainder);
33 22
Consider a number that leaves a remainder of 2 when divided by 114 119
What is the remainder theorem? It is a theorem i It is a theorem in
The Chinese Remainder Theorem is often used in which field? Number theory Geometry
Which of the following is a disadvantage of the Chinese Remain It requires adv It can only be app
Consider a number that leaves a remainder of 2 when divided by 76 158
17 11
In cryptography, the Chinese Remainder Theorem is used for: Generating rand Encrypting messa
60 65 55
-30 -20 -30
30 0 30
compile error runtime error 1
Division (/) Equality (==) Equality (==)
30 0 0
-2 30 -2
194 none of the above 47
5 5.64000000000 5 5 5.640000000000001 5.0
error none of the above true

switch statement it is possible to cre two case constants in the same switch can have identical values
It can handle mulIt cannot handle mor It can handle multiple conditions using logical operators
continue break if()
5 10 x is less than y and x is not equal to y
A group of variablA mechanism for decA way to manage the flow of execution in a program
if loop switch
Hello World Hello World
5 10 x is less than y
2 None of the above 0 1 3 4
do-while if-else statement if-else statement

O(2^n) O(n!) O(n!)


Stacks Queues Arrays
Ɵ O Ω
worst case None of the above best case
Big Oh Notation All of the above Big Oh Notation
outer inner input
Ω(n^2) None of these O(n^2)
equal to determiniNone of these less than deterministic algorithm
O(n^2) O(n^3) O(n^2)
O(n^2) O(log n) O(n^2)

541 678 541


O(n * logn) PrecoO(n) Precomputation,O(nlog(logn)) Precomputation, O(1) for check.
Perfect numbers upRational numbers upPrime numbers up to a given limit
Takes less time t Takes more time to Requires more memory
Three times Four times ONCE
Array Linked List Array
3 4 2
sqrt(n) n/2 sqrt(n)
Skipping multipleSkipping multiples Skipping multiples of 5
All numbers No numbers No numbers

O(nlogn) O(n*n) O(nlogn)


O(n) O(sqrt(n)) O(1)
By adding the in By adding the incre By adding the increment to the previous prime number and checking for prima
n*n+n+1 n*n+2 n*n-n+1
O(n) O(sqrt(n)) O(n)
To generate all fa To generate twin priTo remove non-prime numbers from the segment
The Segmented Sie The Segmented Sieve The Segmented Sieve algorithm can generate prime numbers up to a larger lim
It is simpler to It is more accurate It uses less memory
The Incremental SThe Sieve of EratostThe Incremental Sieve can find prime numbers beyond a certain limit
O(n sqrt(n)) O(n log log n) O(n log n)

Undefined None of the above 1


p None of the above p-1
(p-1)*(q-1) None of the above (p-1)*(q-1)
O(sqrt(n)) O(nlogn) O(sqrt(n))
It counts the numbe None of the above It counts the number of positive integers less than or equal to n that are relative
321 342 320
600 800 400
Sorting algorithmNone of the above Cryptography
5 6 4
It is not useful f None of the above It is computationally expensive for very large values of n

2 many 0
80678 10210 101
2 many 1
707 606 707
They can be genera They are always oddThey can be generated recursively by adding one digit at a time
1, 2, 3, 4, 5, 6, 7, 2000, 1, 8 0,1,8
Dihedral primes thAll of the above Palindromic numbers
6869 5005 6869
The strobogrammatic properties of a giEvery natural number larger than one is strobogrammatic in every base.
3^(n/2) n! 3^(n/2)

x ≡ 7 (mod 10). x ≡ 9 (mod 10). x ≡ 9 (mod 10).


It can be applied It can only be appli It can be applied to solve systems of congruences with coprime moduli.
12 34 22
123 456 114
It is a theorem in It is a theorem in staIt is a theorem in algebra that states that if a polynomial f(x) is divided by x-a, t
Algebra Calculus Number theory
It has limited app It is computational It has limited applicability to certain types of problems.
156 67 158
10 13 17
Decrypting messaHashing algorithms. Decrypting messages.
have identical values
ical operators
ime number and checking for primality

te prime numbers up to a larger limit

bers beyond a certain limit

s than or equal to n that are relatively prime to n

ge values of n

g one digit at a time

obogrammatic in every base.

uences with coprime moduli.

polynomial f(x) is divided by x-a, then the remainder is equal to f(a).

of problems.

You might also like