University CS Practice: Theory
University CS — Theory Practice Problems
10 MCQ questions covering automata theory, compiler phases, cryptography, and machine learning fundamentals. Select an option to check your answer and view the explanation.
Intuition
The foundations beneath the code: Theory of computation is like the foundations of a building — you don’t see them, but they determine what structures are possible. Automata theory tells you what languages are recognisable, computability tells you what’s solvable, and complexity tells us which problems we can hope to solve efficiently.
Why it matters: Theory guides practical decisions — compiler designers use automata to parse code, cryptographers rely on computational hardness for security, and complexity theory tells us which problems we can hope to solve efficiently.
The key insight: There’s a beautiful hierarchy from finite automata to Turing machines — each level of memory unlocks new capabilities, and understanding this hierarchy is the key to knowing what’s computationally possible.
Worked Examples
Example 1: DFA Construction
Problem: Design a DFA that accepts all strings over containing an even number of 1s.
Solution: Step 1: Define states based on parity of 1s seen so far
- : even number of 1s (start and accept state)
- : odd number of 1s
Step 2: Define transitions
- From : on 0 stay in , on 1 go to
- From : on 0 stay in , on 1 go to
Step 3: Accept state: (even number of 1s)
Step 4: Verify with examples:
- “0101”: ✓ (accepted)
- “011”: ✓ (accepted)
Key insight: DFAs need only 2 states for this problem because we only need to track parity (even/odd), which requires finite memory.
Example 2: RSA Key Generation
Problem: Generate RSA keys with , , . Find and decrypt the ciphertext .
Solution: Step 1: Compute
Step 2: Compute
Step 3: Find such that : Try : ✓
Step 4: Public key: , Private key:
Step 5: Decrypt : remainder So
Key insight: RSA decryption works because by Euler’s theorem, since .
Example 3: Compiler Pipeline
Problem: Trace the compilation of x = a + b * 2 through each compiler phase.
Solution: Step 1 (Lexical Analysis): Tokenise into: [ID:x] [ASSIGN:=] [ID:a] [PLUS:+] [ID:b] [STAR:*] [NUM:2]
Step 2 (Syntax Analysis): Build AST:
=
/ \
x +
/ \
a *
/ \
b 2
Step 3 (Semantic Analysis): Type-check and annotate:
b * 2: integer multiplication ✓a + (b * 2): integer addition ✓x = ...: assignment ✓
Step 4 (Code Generation): Three-address code:
t1 = b * 2
t2 = a + t1
x = t2
Step 5 (Optimisation): Constant fold if b or 2 are known, or strength reduction.
Key insight: Each phase transforms the representation while preserving semantics. The AST makes operator precedence explicit (multiplication before addition).
Automata Theory and Formal Languages
Compiler Design
Cryptography
Machine Learning Fundamentals
Cross-References
- Machine Learning Practice: Auto-graded problems testing ML concepts.
- Algorithms: Optimisation algorithms used in machine learning.
Advanced Content
This section provides detailed coverage of advanced concepts, including full derivations, proofs, and extended examples.
Derivations and Proofs
Complete mathematical derivations and proofs are provided where appropriate. Each step is explained to ensure understanding of the underlying reasoning.
Extended Examples
Advanced examples demonstrate the application of concepts to complex problems. These examples go beyond standard exam questions to develop deeper understanding.
Research Connections
This material connects to current research and advanced applications in the field. Understanding these connections provides context for the study material.
Prerequisites
Ensure you have mastered the prerequisite material before attempting this advanced content.
Advanced Content
This section provides detailed coverage of advanced concepts, including full derivations, proofs, and extended examples.
Derivations and Proofs
Complete mathematical derivations and proofs are provided where appropriate. Each step is explained to ensure understanding of the underlying reasoning.
Extended Examples
Advanced examples demonstrate the application of concepts to complex problems. These examples go beyond standard exam questions to develop deeper understanding.
Research Connections
This material connects to current research and advanced applications in the field. Understanding these connections provides context for the study material.
Prerequisites
Ensure you have mastered the prerequisite material before attempting this advanced content.
Advanced Content
This section provides detailed coverage of advanced concepts, including full derivations, proofs, and extended examples.
Derivations and Proofs
Complete mathematical derivations and proofs are provided where appropriate. Each step is explained to ensure understanding of the underlying reasoning.
Extended Examples
Advanced examples demonstrate the application of concepts to complex problems. These examples go beyond standard exam questions to develop deeper understanding.
Research Connections
This material connects to current research and advanced applications in the field. Understanding these connections provides context for the study material.
Prerequisites
Ensure you have mastered the prerequisite material before attempting this advanced content.
Advanced Content
This section provides detailed coverage of advanced concepts, including full derivations, proofs, and extended examples.
Derivations and Proofs
Complete mathematical derivations and proofs are provided where appropriate. Each step is explained to ensure understanding of the underlying reasoning.
Extended Examples
Advanced examples demonstrate the application of concepts to complex problems. These examples go beyond standard exam questions to develop deeper understanding.
Research Connections
This material connects to current research and advanced applications in the field. Understanding these connections provides context for the study material.
Prerequisites
Ensure you have mastered the prerequisite material before attempting this advanced content.
Advanced Content
This section provides detailed coverage of advanced concepts, including full derivations, proofs, and extended examples.
Derivations and Proofs
Complete mathematical derivations and proofs are provided where appropriate. Each step is explained to ensure understanding of the underlying reasoning.
Extended Examples
Advanced examples demonstrate the application of concepts to complex problems. These examples go beyond standard exam questions to develop deeper understanding.
Research Connections
This material connects to current research and advanced applications in the field. Understanding these connections provides context for the study material.
Prerequisites
Ensure you have mastered the prerequisite material before attempting this advanced content.