Aptitude
Programming Logic
NQT Section 4
~20 min

Programming Logic

Pseudocode, output prediction, flowcharts & algorithm analysis

Topic
Difficulty

60 questions · first 10 free

Q1Output Prediction
easy

What is the output of this code?

code
x = 5
y = 3
print(x ** y)
Q2Output Prediction
easy

What is printed?

code
for i in range(1, 6):
    if i % 2 == 0:
        print(i)
Q3Output Prediction
medium

What is the output?

code
def mystery(n):
    if n <= 1:
        return n
    return mystery(n-1) + mystery(n-2)

print(mystery(6))
Q4Output Prediction
medium

What is the output?

code
x = [1, 2, 3, 4, 5]
print(x[1:4])
Q5Output Prediction
medium

What does this print?

code
a = 10
b = 20
a, b = b, a
print(a, b)
Q6Output Prediction
hard

What is the output?

code
def f(x, lst=[]):
    lst.append(x)
    return lst

print(f(1))
print(f(2))
print(f(3))
Q7Output Prediction
medium

What is the output?

code
x = "Hello"
print(x[::-1])
Q8Output Prediction
hard

What is printed?

code
for i in range(3):
    for j in range(3):
        if i == j:
            print(i * j, end=" ")
Q9Output Prediction
easy

What is the output?

code
print(type(5/2))
Q10Output Prediction
medium

What does this code print?

code
lst = [1, 2, 3, 4, 5]
lst.remove(3)
print(lst.pop(1))
Q11Pseudocode
easy

Trace this pseudocode:

Pseudocode
SET result = 0
FOR i FROM 1 TO 5
    result = result + i
ENDFOR
PRINT result

Unlock all 60 questions with Pro

Q12Pseudocode
medium

What is the output?

Pseudocode
SET x = 10
WHILE x > 0
    PRINT x
    x = x - 3
ENDWHILE

Unlock all 60 questions with Pro

Q13Pseudocode
medium

What does this pseudocode compute?

Pseudocode
FUNCTION mystery(n)
    IF n == 0 RETURN 1
    RETURN n * mystery(n - 1)
END FUNCTION
PRINT mystery(5)

Unlock all 60 questions with Pro

Q14Pseudocode
hard

Trace this pseudocode:

Pseudocode
SET a = 1, b = 1
FOR i FROM 3 TO 7
    c = a + b
    a = b
    b = c
ENDFOR
PRINT b

Unlock all 60 questions with Pro

Q15Pseudocode
medium

What is printed?

Pseudocode
SET count = 0
FOR i FROM 1 TO 20
    IF i MOD 3 == 0 OR i MOD 5 == 0
        count = count + 1
ENDFOR
PRINT count

Unlock all 60 questions with Pro

Q16Pseudocode
hard

What is the value of result after this pseudocode runs?

Pseudocode
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 result

Unlock all 60 questions with Pro

Q17Pseudocode
medium

What is the output of this pseudocode?

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

Q18Pseudocode
easy

What does this find?

Pseudocode
SET a = 12, b = 8
WHILE b != 0
    temp = b
    b = a MOD b
    a = temp
ENDWHILE
PRINT a

Unlock all 60 questions with Pro

Q19Flowchart
medium

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

Q20Flowchart
medium

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

Q21Flowchart
hard

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

Q22Algorithm Analysis
medium

What is the time complexity of Binary Search?

Unlock all 60 questions with Pro

Q23Algorithm Analysis
easy

Which sorting algorithm has the best average-case time complexity?

Unlock all 60 questions with Pro

Q24Algorithm Analysis
medium

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

Q25Algorithm Analysis
hard

A function runs nested loops:

code
for i in range(n):
    for j in range(i, n):
        # O(1) operation

What is the time complexity?

Unlock all 60 questions with Pro

Q26Algorithm Analysis
medium

Which data structure is most efficient for implementing a LIFO (Last In, First Out) operation?

Unlock all 60 questions with Pro

Q27Algorithm Analysis
hard

What is the recurrence relation for Merge Sort, and what does the Master Theorem give as its complexity?

Unlock all 60 questions with Pro

Q28Programming Concepts
easy

What is the difference between == and === in JavaScript?

Unlock all 60 questions with Pro

Q29Programming Concepts
medium

What is the output?

code
int x = 5;
System.out.println(x++);
System.out.println(x);

Unlock all 60 questions with Pro

Q30Programming Concepts
medium

What does the `static` keyword mean for a class method in Java?

Unlock all 60 questions with Pro

Q31Programming Concepts
hard

What is the difference between a shallow copy and a deep copy of an object?

Unlock all 60 questions with Pro

Q32Programming Concepts
medium

What is a NULL pointer exception and when does it occur?

Unlock all 60 questions with Pro

Q33Programming Concepts
easy

What does DRY stand for in software development?

Unlock all 60 questions with Pro

Q34Control Flow
easy

What is the output?

code
x = 10
if x > 5:
    print("A")
elif x > 8:
    print("B")
else:
    print("C")

Unlock all 60 questions with Pro

Q35Control Flow
medium

What is the output?

code
for i in range(5):
    if i == 3:
        break
    print(i)

Unlock all 60 questions with Pro

Q36Control Flow
medium

What is the output?

code
for i in range(5):
    if i == 3:
        continue
    print(i)

Unlock all 60 questions with Pro

Q37Control Flow
hard

What is printed by this switch-like code (Java)?

code
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

Q38String Operations
easy

What is the length of the string "Hello World"?

Unlock all 60 questions with Pro

Q39String Operations
medium

What is the output?

code
s = "TCS NQT 2024"
words = s.split()
print(words[1])

Unlock all 60 questions with Pro

Q40String Operations
medium

What is the result of:

code
"Python"[2:5]

Unlock all 60 questions with Pro

Q41Data Structures
easy

Which data structure works on FIFO (First In, First Out) principle?

Unlock all 60 questions with Pro

Q42Data Structures
medium

What is the time complexity of searching an element in an unsorted array?

Unlock all 60 questions with Pro

Q43Data Structures
hard

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

Q44Data Structures
medium

What is the minimum number of nodes in a complete binary tree with height 3?

Unlock all 60 questions with Pro

Q45Logic
medium

What is the output?

code
x = True
y = False
print(x and y)
print(x or y)
print(not x)

Unlock all 60 questions with Pro

Q46Logic
medium

What is wrong with this code intended to find if a number is prime?

code
def is_prime(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True

Unlock all 60 questions with Pro

Q47Logic
hard

What does this code do?

code
def f(lst):
    return [x for x in lst if x > 0]

Unlock all 60 questions with Pro

Q48Logic
medium

What is the output of this code?

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

Q49Bit Manipulation
medium

What is the result of 5 AND 3 (bitwise)?

Unlock all 60 questions with Pro

Q50Bit Manipulation
medium

What does x << 2 do for x = 3?

Unlock all 60 questions with Pro

Q51OOP Concepts
easy

What is polymorphism in OOP?

Unlock all 60 questions with Pro

Q52OOP Concepts
medium

What is the difference between an abstract class and an interface in Java?

Unlock all 60 questions with Pro

Q53OOP Concepts
easy

What is encapsulation in OOP?

Unlock all 60 questions with Pro

Q54Debugging
medium

Find the bug:

code
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

Q55Debugging
hard

Find the bug in this binary search:

code
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 -1

Unlock all 60 questions with Pro

Q56Algorithm Analysis
medium

What pattern does this code implement?

code
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

Q57Algorithm Analysis
hard

What is the time complexity of this code?

code
n = 100
i = 1
while i < n:
    i *= 2

Unlock all 60 questions with Pro

Q58Pseudocode
medium

What does this pseudocode return for input [5, 2, 8, 1, 9]?

Pseudocode
FUNCTION process(arr)
    SET result = arr[0]
    FOR each x in arr
        IF x < result THEN result = x
    RETURN result
END

Unlock all 60 questions with Pro

Q59Output Prediction
hard

What is the output?

code
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

Q60Programming Concepts
medium

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.