Software Engineering Trivia 3 — Questions and Answers
Question 1: What is the time complexity of looking up an element in a balanced binary search tree (BST)?
- O(1)
- O(log n) (Correct answer)
- O(n)
- O(n log n)
Correct answer: O(log n)
A balanced BST halves the search space at each node, yielding O(log n) lookup time for n elements.
Question 2: Which design pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable?
- Observer
- Factory
- Strategy (Correct answer)
- Decorator
Correct answer: Strategy
The Strategy pattern lets the algorithm vary independently from clients that use it, enabling runtime behavior swapping.
Question 3: In software engineering, what does the acronym DRY stand for?
- Design Reuse Yield
- Don't Repeat Yourself (Correct answer)
- Dynamic Resource Yielding
- Dependency Reduction Yardstick
Correct answer: Don't Repeat Yourself
DRY (Don't Repeat Yourself) is a principle that every piece of knowledge should have a single, authoritative representation in the codebase.
Question 4: Which HTTP status code indicates that a client request was successfully received, understood, and accepted?
- 201 Created
- 204 No Content
- 200 OK (Correct answer)
- 202 Accepted
Correct answer: 200 OK
HTTP 200 OK is the standard success response indicating the request was fulfilled without error.
Question 5: What type of testing validates that individual components of software work correctly in isolation?
- Integration testing
- System testing
- Unit testing (Correct answer)
- Acceptance testing
Correct answer: Unit testing
Unit testing targets the smallest testable parts of an application independently, without external dependencies.
Question 6: In Big O notation, what is the space complexity of a recursive Fibonacci function without memoization?
- O(1)
- O(log n)
- O(n) (Correct answer)
- O(2^n)
Correct answer: O(n)
The call stack depth reaches O(n) at most since each recursive chain goes n levels deep before returning.
Question 7: Which concurrency primitive is used to ensure only one thread accesses a critical section at a time?
- Semaphore
- Thread pool
- Mutex (Correct answer)
- Coroutine
Correct answer: Mutex
A mutex (mutual exclusion lock) grants exclusive access to one thread at a time, preventing race conditions in critical sections.
What is the time complexity of looking up an element in a balanced binary search tree (BST)?