Which not a good data structure to represent a sparse matrix
Optym technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Which not a good data structure to represent a sparse matrix
Show answer & explanation
Answer: C. C) Heap
A sparse matrix is best represented by dictionaries/hash maps, compressed sparse row (CSR) arrays, or linked lists. A heap is a priority queue designed for finding min/max and does not support efficient 2D spatial indexing.
Step-by-step Derivation:
Step 1: Sparse matrices store non-zero elements keyed by (row, col) coordinates.
Step 2: Dictionaries (hash maps) and coordinate arrays allow fast lookup or linear algebra operations.
Step 3: Heaps do not preserve 2D matrix structure or support efficient element access by row and column.