Programming Logic
Pseudocode, output prediction, flowcharts & algorithm analysis
60 questions · first 10 free
What is the output of this code?
x = 5
y = 3
print(x ** y)What is printed?
for i in range(1, 6):
if i % 2 == 0:
print(i)What is the output?
def mystery(n):
if n <= 1:
return n
return mystery(n-1) + mystery(n-2)
print(mystery(6))What is the output?
x = [1, 2, 3, 4, 5]
print(x[1:4])What does this print?
a = 10
b = 20
a, b = b, a
print(a, b)What is the output?
def f(x, lst=[]):
lst.append(x)
return lst
print(f(1))
print(f(2))
print(f(3))What is the output?
x = "Hello"
print(x[::-1])What is printed?
for i in range(3):
for j in range(3):
if i == j:
print(i * j, end=" ")What is the output?
print(type(5/2))What does this code print?
lst = [1, 2, 3, 4, 5]
lst.remove(3)
print(lst.pop(1))Trace this pseudocode:
SET result = 0
FOR i FROM 1 TO 5
result = result + i
ENDFOR
PRINT resultUnlock all 60 questions with Pro
What is the output?
SET x = 10
WHILE x > 0
PRINT x
x = x - 3
ENDWHILEUnlock all 60 questions with Pro
What does this pseudocode compute?
FUNCTION mystery(n)
IF n == 0 RETURN 1
RETURN n * mystery(n - 1)
END FUNCTION
PRINT mystery(5)Unlock all 60 questions with Pro
Trace this pseudocode:
SET a = 1, b = 1
FOR i FROM 3 TO 7
c = a + b
a = b
b = c
ENDFOR
PRINT bUnlock all 60 questions with Pro
What is printed?
SET count = 0
FOR i FROM 1 TO 20
IF i MOD 3 == 0 OR i MOD 5 == 0
count = count + 1
ENDFOR
PRINT countUnlock all 60 questions with Pro
What is the value of result after this pseudocode runs?
SET arr = [3, 1, 4, 1, 5, 9, 2, 6]
SET result = arr[0]
FOR i FROM 1 TO 7
IF arr[i] > result
result = arr[i]
ENDFOR
PRINT resultUnlock all 60 questions with Pro
What is the output of this pseudocode?
SET n = 153
SET temp = n, sum = 0
WHILE temp > 0
digit = temp MOD 10
sum = sum + digit^3
temp = temp DIV 10
ENDWHILE
IF sum == n THEN PRINT "Armstrong" ELSE PRINT "Not Armstrong"Unlock all 60 questions with Pro
What does this find?
SET a = 12, b = 8
WHILE b != 0
temp = b
b = a MOD b
a = temp
ENDWHILE
PRINT aUnlock all 60 questions with Pro
A flowchart has these steps: START → Set x=1 → [x ≤ 5?] YES → Print x → x = x+2 → back to [x ≤ 5?] → NO → STOP What values are printed?
Unlock all 60 questions with Pro
A flowchart processes input N: START → Read N → [N > 0?] YES → Print "Positive" → STOP; NO → [N < 0?] YES → Print "Negative" → STOP; NO → Print "Zero" → STOP If N = 0, what is printed?
Unlock all 60 questions with Pro
A flowchart: START → count=0, i=1 → [i ≤ N?] YES → [i%2==0?] YES → count++ → i++ → back to loop; NO → i++ → back to loop; NO → Print count → STOP For N=10, what is count?
Unlock all 60 questions with Pro
What is the time complexity of Binary Search?
Unlock all 60 questions with Pro
Which sorting algorithm has the best average-case time complexity?
Unlock all 60 questions with Pro
What is the space complexity of a recursive function that calls itself n times without any other data structure?
Unlock all 60 questions with Pro
A function runs nested loops:
for i in range(n):
for j in range(i, n):
# O(1) operationWhat is the time complexity?
Unlock all 60 questions with Pro
Which data structure is most efficient for implementing a LIFO (Last In, First Out) operation?
Unlock all 60 questions with Pro
What is the recurrence relation for Merge Sort, and what does the Master Theorem give as its complexity?
Unlock all 60 questions with Pro
What is the difference between == and === in JavaScript?
Unlock all 60 questions with Pro
What is the output?
int x = 5;
System.out.println(x++);
System.out.println(x);Unlock all 60 questions with Pro
What does the `static` keyword mean for a class method in Java?
Unlock all 60 questions with Pro
What is the difference between a shallow copy and a deep copy of an object?
Unlock all 60 questions with Pro
What is a NULL pointer exception and when does it occur?
Unlock all 60 questions with Pro
What does DRY stand for in software development?
Unlock all 60 questions with Pro
What is the output?
x = 10
if x > 5:
print("A")
elif x > 8:
print("B")
else:
print("C")Unlock all 60 questions with Pro
What is the output?
for i in range(5):
if i == 3:
break
print(i)Unlock all 60 questions with Pro
What is the output?
for i in range(5):
if i == 3:
continue
print(i)Unlock all 60 questions with Pro
What is printed by this switch-like code (Java)?
int n = 2;
switch(n) {
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
default: System.out.print("done");
}Unlock all 60 questions with Pro
What is the length of the string "Hello World"?
Unlock all 60 questions with Pro
What is the output?
s = "TCS NQT 2024"
words = s.split()
print(words[1])Unlock all 60 questions with Pro
What is the result of:
"Python"[2:5]Unlock all 60 questions with Pro
Which data structure works on FIFO (First In, First Out) principle?
Unlock all 60 questions with Pro
What is the time complexity of searching an element in an unsorted array?
Unlock all 60 questions with Pro
In a Binary Search Tree (BST), what is the time complexity of search, insert, and delete in the average case?
Unlock all 60 questions with Pro
What is the minimum number of nodes in a complete binary tree with height 3?
Unlock all 60 questions with Pro
What is the output?
x = True
y = False
print(x and y)
print(x or y)
print(not x)Unlock all 60 questions with Pro
What is wrong with this code intended to find if a number is prime?
def is_prime(n):
for i in range(2, n):
if n % i == 0:
return False
return TrueUnlock all 60 questions with Pro
What does this code do?
def f(lst):
return [x for x in lst if x > 0]Unlock all 60 questions with Pro
What is the output of this code?
d = {"a": 1, "b": 2, "c": 3}
for k, v in d.items():
if v % 2 == 0:
print(k)Unlock all 60 questions with Pro
What is the result of 5 AND 3 (bitwise)?
Unlock all 60 questions with Pro
What does x << 2 do for x = 3?
Unlock all 60 questions with Pro
What is polymorphism in OOP?
Unlock all 60 questions with Pro
What is the difference between an abstract class and an interface in Java?
Unlock all 60 questions with Pro
What is encapsulation in OOP?
Unlock all 60 questions with Pro
Find the bug:
def sum_list(lst):
total = 0
for i in range(len(lst)):
total += lst[i]
return total
result = sum_list([1, 2, 3, 4])
print(result)Unlock all 60 questions with Pro
Find the bug in this binary search:
def binary_search(arr, target):
left, right = 0, len(arr)
while left < right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1Unlock all 60 questions with Pro
What pattern does this code implement?
def solve(n):
if n <= 1:
return n
if memo[n] != -1:
return memo[n]
memo[n] = solve(n-1) + solve(n-2)
return memo[n]Unlock all 60 questions with Pro
What is the time complexity of this code?
n = 100
i = 1
while i < n:
i *= 2Unlock all 60 questions with Pro
What does this pseudocode return for input [5, 2, 8, 1, 9]?
FUNCTION process(arr)
SET result = arr[0]
FOR each x in arr
IF x < result THEN result = x
RETURN result
ENDUnlock all 60 questions with Pro
What is the output?
def outer():
x = 10
def inner():
nonlocal x
x += 5
return x
return inner
f = outer()
print(f())
print(f())Unlock all 60 questions with Pro
What is the purpose of a try-except block in Python?
Unlock all 60 questions with Pro
50 more questions with Pro
Upgrade to unlock all 60 questions across all 4 NQT sections — with full explanations.