Back to the 2023 paper

Module 1: Introduction

20232m

In algorithm analysis, what does "space complexity" refer to?
(i) The number of input elements
(ii) The amount of physical memory used
(iii) The number of recursive calls
(iv) The number of lines of code in the algorithm

Worked SolutionAI Assisted

Answer: (ii) The amount of physical memory used

Explanation:

  • Space complexity is the total amount of memory (in terms of asymptotic function of input size nn) required by an algorithm to run to completion, including:

    • Input space / auxiliary space for variables, data structures, recursion stack, dynamically allocated memory.
    • Often reported as auxiliary space (extra space excluding input itself).
  • (i) number of input elements is nn itself, not space complexity.

  • (iii) number of recursive calls contributes to stack space but is only one component.

  • (iv) lines of code is program size / software metric, unrelated to asymptotic memory usage.

Hence space complexity = memory consumed as function of nn, e.g., iterative linear search O(1)O(1), merge sort O(n)O(n), recursive DFS O(h)O(h) stack.

Correct choice: (ii)

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.