Mixed practice

12 questions across all topics

WDTPD - Arrays
Q1
What is the output?
A = [1, 2, 3, 4, 5]
FOR i = 0 TO 1
    temp = A[i]
    A[i] = A[4-i]
    A[4-i] = temp
NEXT i
OUTPUT A[0], A[1], A[2]
Data Structures
Q2
Build a BST by inserting: 40, 20, 60, 10, 30, 50, 70. What is the preorder traversal?
Computer Number Systems
Q3
Convert the octal number 3478347_8 to decimal.
WDTPD - Looping
Q4
What is the output?
n = 100
count = 0
WHILE n > 1
    n = INT(n / 3)
    count = count + 1
END WHILE
OUTPUT count
Prefix/Infix/Postfix Notation
Q5
Evaluate the postfix expression: 3 4  2 5  +3\ 4\ *\ 2\ 5\ *\ +
Digital Electronics
Q6
How many rows does a truth table have for a circuit with 3 inputs?
Bit-String Flicking
Q7
Evaluate: LSHIFT-2 (10100 AND 11110)
Boolean Algebra
Q8
Simplify: (AB)(AB)' using DeMorgan's Law.
Recursive Functions
Q9
If f(a,b)f(a, b) returns aa when b=0b = 0, and returns f(a+1,b1)f(a + 1, b - 1) otherwise, find f(3,4)f(3, 4).
Graph Theory
Q10
A directed graph has vertices A, B, C, D and edges AB, BC, CA, BD. Is this graph a DAG (directed acyclic graph)?
WDTPD - Branching
Q11
What is the output?
p = 17
IF p MOD 2 == 0 THEN
    OUTPUT "even"
ELSE
    is_prime = 1
    FOR d = 2 TO INT(p/2)
        IF p MOD d == 0 THEN
            is_prime = 0
        END IF
    NEXT d
    IF is_prime == 1 THEN
        OUTPUT "prime"
    ELSE
        OUTPUT "odd"
    END IF
END IF
WDTPD - Strings
Q12
What is the output?
S = "ABCDEFGH"
OUTPUT S[2:5]