Bird
Raised Fist0

After a Singleton instance is initialized using double-checked locking in a multithreaded environment, what is the expected time complexity of subsequent calls to retrieve the instance?

medium🧠 Conceptual Q5 of Q15
OOP & Design Patterns - Singleton Pattern - Thread Safety, Double-Checked Locking & Lazy Init
After a Singleton instance is initialized using double-checked locking in a multithreaded environment, what is the expected time complexity of subsequent calls to retrieve the instance?
AO(log n) -- logarithmic time
BO(1) -- constant time
CO(n) -- linear time
DO(n log n) -- linearithmic time
Step-by-Step Solution
Solution:
  1. Step 1: Understand double-checked locking

    Double-checked locking uses synchronization only during the first initialization.
  2. Step 2: After initialization

    Once the instance is created, the synchronized block is bypassed, so access is direct.
  3. Step 3: Time complexity

    Accessing the instance after initialization is a simple pointer/reference return, which is O(1).
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Post-init access is direct, no locking overhead [OK]
Quick Trick: Double-checked locking avoids locking after init, so O(1) [OK]
Common Mistakes:
MISTAKES
  • Assuming synchronization every time causes O(n)
  • Confusing initialization cost with access cost
  • Ignoring that locking is skipped after first init
Trap Explanation:
PITFALL
  • Locking only occurs once; subsequent calls are direct access, so complexity is constant.
Interviewer Note:
CONTEXT
  • Tests knowledge of performance implications of double-checked locking.
Master "Singleton Pattern - Thread Safety, Double-Checked Locking & Lazy Init" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes