LtiMindtree – Technical MCQ questions | Computer Domain Questions

Pseudocode Assessment

Technical Pseudocode Assessment

10 Computer Science Logic & Algorithmic Questions

1. What will be printed when Main() executes?

CLASS Parent:
    FUNCTION Greet():
        PRINT "Hello"

CLASS Child EXTENDS Parent:
    FUNCTION Greet():
        PRINT "Hi"

FUNCTION Main():
    obj = NEW Child()
    obj.Greet()

2. How many total comparisons will the loop make to search for target = 16 in array arr = [4, 8, 15, 16, 23, 42]?

FUNCTION LinearSearch(arr, target):
    FOR i FROM 0 TO LENGTH(arr) - 1 DO:
        IF arr[i] == target THEN:
            RETURN i
        END IF
    END FOR
    RETURN -1

3. What integer value is returned after executing BitwiseTest()?

FUNCTION BitwiseTest():
    A = 29   // Binary: 11101
    B = 14   // Binary: 01110
    result = (A & B) | (A ^ B)
    RETURN result

4. What integer value is returned when calling Calculate(4)?

FUNCTION Calculate(n):
    IF n <= 1 THEN:
        RETURN 2
    ELSE:
        RETURN Calculate(n - 1) + Calculate(n - 2) + 1
    END IF

5. What is the final value of sum returned by the function?

FUNCTION ProcessArray():
    ARRAY arr = [3, 8, 2, 11, 6, 14]
    sum = 0
    FOR i FROM 0 TO LENGTH(arr) - 1 DO:
        IF arr[i] % 2 == 0 THEN:
            sum = sum + (arr[i] * 2)
        ELSE:
            sum = sum - arr[i]
        END IF
    END FOR
    RETURN sum

6. What integer value is printed by CombinedOperations()?

FUNCTION CombinedOperations():
    CREATE STACK s
    CREATE QUEUE q
    ENQUEUE 10, 20, 30 INTO q
    PUSH DEQUEUE(q) ONTO s
    PUSH DEQUEUE(q) ONTO s
    ENQUEUE POP(s) INTO q
    PUSH 40 ONTO s
    PRINT TOP(s) + FRONT(q)

7. How many total times will the statement count = count + 1 execute?

FUNCTION NestedLoop():
    count = 0
    FOR i FROM 1 TO 3 DO:
        FOR j FROM 1 TO 4 DO:
            count = count + 1
        END FOR
    END FOR
    RETURN count

8. In a binary search for target = 16 on sorted array [2, 5, 8, 12, 16, 23, 38], what is the value of arr[mid] on the very first comparison?

FUNCTION BinarySearch(arr, target):
    low = 0
    high = LENGTH(arr) - 1
    WHILE low <= high DO:
        mid = (low + high) / 2
        IF arr[mid] == target THEN RETURN mid
        IF arr[mid] < target THEN low = mid + 1
        ELSE high = mid - 1
    END WHILE

9. What value is returned when calling SumEvens([1, 2, 3, 4, 5, 6])?

FUNCTION SumEvens(numbers):
    total = 0
    FOR EACH num IN numbers DO:
        IF num % 2 == 0 THEN:
            total = total + num
        END IF
    END FOR
    RETURN total

10. What integer value does Fibonacci(5) return?

FUNCTION Fibonacci(n):
    ARRAY dp OF SIZE n + 1
    dp[0] = 0
    dp[1] = 1
    FOR i FROM 2 TO n DO:
        dp[i] = dp[i - 1] + dp[i - 2]
    END FOR
    RETURN dp[n]