Past exam question: 2066 Bhadra (Regular / Back), Q1(a)
Open in the Padhaiko appQuestion
Why data structures are needed? Write any data structure as ADT
Solution
Need for Data Structures:
- Efficiency: Enables fast searching, sorting, insertion, and deletion on large datasets (e.g., vs. ).
- Memory Organization: Structures data logically (hierarchies, networks, ordered lists) to minimize memory waste and disk I/O.
- Abstraction & Reusability: Separates logical behavior from physical storage so modules remain maintainable.
Stack as an Abstract Data Type (ADT):
- Value Definition: A finite ordered sequence of elements of type
Elementwhere insertions and deletions are restricted to one endpoint (top). - Operator Definition:
createStack()empty stackisEmpty(S)trueiff stack has 0 elementspush(S, x)insertsxattop(precondition: not full)pop(S)removes and returns top item (precondition:!isEmpty(S))peek(S)returns top item without removing (precondition:!isEmpty(S))
Answer:
Data structures are needed for algorithmic speed, optimal memory use, and clean problem modeling. The Stack ADT defines a LIFO collection with createStack, isEmpty, push, pop, and peek independent of array or linked implementation.