MS Master of Computer Science 5 — Questions and Answers
Question 1: Which design pattern ensures a class has only one instance and provides a global access point to it?
- Factory
- Observer
- Singleton (Correct answer)
- Decorator
Correct answer: Singleton
The Singleton pattern restricts instantiation of a class to a single object and provides a static method to access that instance globally.
Question 2: What is the purpose of the 'volatile' keyword in Java or C?
- To prevent garbage collection of an object
- To indicate a variable may be modified by multiple threads and disable caching/reordering optimizations (Correct answer)
- To mark a method as thread-safe
- To allocate a variable on the stack rather than the heap
Correct answer: To indicate a variable may be modified by multiple threads and disable caching/reordering optimizations
Declaring a variable volatile tells the compiler and CPU to always read/write it from main memory, preventing stale cached copies in multi-threaded code.
Question 3: In formal language theory, which class of languages is recognized by a pushdown automaton (PDA)?
- Regular languages
- Context-free languages (Correct answer)
- Context-sensitive languages
- Recursively enumerable languages
Correct answer: Context-free languages
Pushdown automata recognize exactly the context-free languages; the stack gives them enough memory to match nested structures like parentheses.
Question 4: What does 'eventual consistency' mean in distributed databases?
- All nodes are always in sync with zero latency
- If no new updates occur, all replicas will eventually converge to the same value (Correct answer)
- The system guarantees linearizable reads at all times
- Writes are rejected during network partitions
Correct answer: If no new updates occur, all replicas will eventually converge to the same value
Eventual consistency guarantees that, given enough time without new updates, all replicas will return the same value — it does not guarantee immediate consistency.
Question 5: Which asymptotic notation describes a tight bound — both upper and lower — on an algorithm's growth rate?
- O (Big-O)
- Ω (Big-Omega)
- Θ (Big-Theta) (Correct answer)
- o (Little-o)
Correct answer: Θ (Big-Theta)
Θ-notation (Big-Theta) means the algorithm's growth rate is sandwiched between constant multiples of a function from both above and below.
Question 6: In software engineering, what is the main goal of regression testing?
- Testing performance under peak load
- Verifying that new changes have not broken previously working functionality (Correct answer)
- Validating user interface accessibility
- Measuring code coverage for new features
Correct answer: Verifying that new changes have not broken previously working functionality
Regression testing re-runs existing test cases after a change to ensure that previously correct behavior has not been inadvertently broken.
Question 7: What is the key advantage of a B-tree over a binary search tree for database indexing?
- B-trees use less memory per node
- B-trees keep all data sorted and minimize disk I/O by having high branching factors (Correct answer)
- B-trees support only unique keys
- B-trees do not require rebalancing
Correct answer: B-trees keep all data sorted and minimize disk I/O by having high branching factors
B-trees have a high branching factor so the tree stays shallow, meaning far fewer disk page reads are needed to find a record.
Which design pattern ensures a class has only one instance and provides a global access point to it?