Time and Space Complexity Analysis Questions

Reasoning about algorithmic efficiency: Big-O/Theta/Omega notation, amortized analysis, recurrence solving, and the time-versus-space trade-off. Covers deriving bounds from code, comparing candidate approaches, and communicating complexity clearly under interview pressure. The analytical layer applied across every algorithm topic.

EasyTechnical
67 practiced

You are handed this loop: for i in range(n): x = arr[i] * 2. Explain its time and space complexity when arr is (a) a plain Python list and (b) a NumPy ndarray processed with vectorized operations instead of the explicit loop. Discuss why the asymptotic complexity class is the same in both cases but the practical constant factor differs by orders of magnitude.

HardTechnical
53 practiced

Explain the roofline model and how you would use it to determine whether a computation (for example, a batched matrix multiply) is compute-bound or memory-bound. Given the FLOP count and the number of bytes moved for an operation, walk through computing its arithmetic intensity and comparing it against a system's roofline.

MediumTechnical
46 practiced

Explain how to design an LRU (least-recently-used) cache that supports get and put in O(1) time. Which two data structures do you combine, and why does neither one alone (just a hash map, or just a doubly linked list) achieve O(1) for both operations?

MediumTechnical
41 practiced

A hash table doubles its bucket count when the load factor exceeds a threshold (e.g. 0.75), and some implementations also halve it when the table becomes too sparse. Derive the amortized cost of insert and delete under this policy, and explain why a naive shrink-on-every-delete-below-threshold policy can break the amortized bound (the classic 'thrashing' failure mode).

EasyTechnical
55 practiced

Compare recursive and iterative implementations of the same algorithm on stack depth, memory usage, tail-call optimization, and stack-overflow risk on deep inputs. Give an example (deep tree traversal, or computing a large factorial) where you would deliberately convert a recursive solution to an iterative one using an explicit stack, and explain when tail-call elimination does (and does not) rescue the recursive version.

Unlock Full Question Bank

Get access to all Time and Space Complexity Analysis interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.