Q1. Time/space of common structures?
A: Array access O(1), insert/delete middle O(n). LinkedList access O(n), insert/delete at head O(1). HashMap average O(1) for get/put (possible O(n) worst). Stack/Queue ops O(1).
F/U: “What’s amortized?” → Average over a sequence; e.g., ArrayList push amortized O(1).
Q2. BFS vs DFS—when to use which?
A: BFS finds shortest path in unweighted graphs; uses queue (O(V+E)). DFS is good for cycle detection/topological sort; uses stack/recursion (O(V+E)).
F/U: “Detect cycle in directed graph?” → DFS + recursion stack (white/gray/black or visited + inStack).
Q3. Sorting choice?
A: Use quicksort average O(n log n), but worst O(n²). Mergesort O(n log n) stable; good for linked lists. Heapsort O(n log n) in-place, not stable.
F/U: “Stable sort?” → Keeps equal keys’ order; needed in multi-key sorts.
Q4. Big-O for common map ops + collisions?
A: HashMap avg O(1), worst O(n) with collisions; Java uses tree bins after threshold → O(log n).
F/U: “How to reduce collisions?” → Good hash, load factor, resizing.
Q5. OOP pillars with quick examples?
A: Encapsulation (private fields + getters), Inheritance (extends), Polymorphism (overriding), Abstraction (interfaces/abstract classes).
F/U: “Interface vs abstract?” → Interfaces define contracts; abstract classes share partial implementation.
Q6. Collections vs Arrays?
A: Arrays fixed size, type-safe primitives; Collections dynamic, rich APIs.