A stack is which type of data structure?

2013

A stack is which type of data structure?

Answer: C. Either a static or a dynamic data structure, depending on the implementationConcept: A data structure is called static when its storage/capacity is fixed at creation and cannot change while the program runs, and dynamic when its…

  1. A.

    Static data structure

  2. B.

    Dynamic data structure

  3. C.

    Either a static or a dynamic data structure, depending on the implementation

  4. D.

    None of these

Attempted by 431 students.

Show answer & explanation

Correct answer: C

Concept: A data structure is called static when its storage/capacity is fixed at creation and cannot change while the program runs, and dynamic when its storage is decided and can change during execution. Separately, a stack is defined purely as an Abstract Data Type (ADT): a linear sequence that supports two operations, push (insert at the top) and pop (remove from the top), obeying Last-In-First-Out (LIFO) order. Nothing in that definition fixes how the underlying storage is allocated.

Application: A stack can be implemented in either of two standard ways. Backed by a fixed-size array, its maximum capacity is decided once, at creation, and cannot grow beyond that limit while running – this is a static implementation (and is why an array-based stack can raise a "stack overflow" once its array is full). Backed by a linked list, each push allocates a new node and each pop frees one, so its storage grows and shrinks with every operation as the program runs; backed instead by a dynamically resizable array, its logical size (the number of elements held) changes with every push/pop while its underlying capacity is only reallocated in occasional larger chunks once a threshold is crossed – either way this is a dynamic implementation, since the storage is not fixed once and for all at creation. Since the stack's own definition (LIFO push/pop) says nothing about which of these backings must be used, whether a given stack is static or dynamic is decided by the implementation choice, not by the stack concept itself.

Cross-check: Test both directions. If a stack is built only from a fixed-size array, it exhibits static behaviour (bounded capacity, overflow at the limit) – so "always dynamic" cannot be a universal label. If a stack is built from a linked list, it exhibits dynamic behaviour (no fixed pre-set bound) – so "always static" cannot be a universal label either. Since both backings are valid and standard, neither single label covers every stack.

Contrast with the other listed options:

  • Static data structure – true only for a fixed-size-array-backed stack; a linked-list-backed or resizable-array-backed stack is not bounded in advance, so this term does not hold universally.

  • Dynamic data structure – true only for a linked-list-backed or resizable-array-backed stack; a fixed-size-array-backed stack has a capacity fixed at creation, so this term does not hold universally either.

  • None of these – not justified, since one of the listed options does correctly capture the stack's behaviour once the implementation freedom is accounted for.

Result: Among the options given, a stack is either static or dynamic, depending on the implementation.

Explore the full course: Btsc Lab Assistant

Loading lesson…