GATE Computer ScienceHardGATE CS
An m × n sparse matrix with m = 1000 rows is stored in coordinate form (three arrays row, col, val, each of length nnz) or in compressed sparse row form (arrays col and val of length nnz and a row-pointer array of length m + 1). Each array element takes one word. For what smallest number of non-zeros nnz does CSR use strictly fewer words than coordinate form?
- A. 1002
- B. 3001
- C. 1000
- D. 1001
Correct answer: A. 1002
Coordinate form needs 3·nnz words and CSR needs 2·nnz + 1001. CSR is strictly smaller when 3·nnz > 2·nnz + 1001, i.e. nnz > 1001, so the smallest integer is 1002 (at 1001 they tie).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Bubble sort with early exit (the algorithm stops after a pass in which no swap occurs) sorts the array [6, 9, 3, 8, 0, 5, 2, 7, 1, 4] into…
- An LRU cache of capacity 3 (get and put both make a key the most recently used; put of an existing key updates its value; when a put adds…
- The standard nextpermutation algorithm (find the rightmost i with a[i] < a[i+1], swap a[i] with the rightmost larger a[j] to its right…
- A max-heap is stored in A[1..13] = [100, 60, 90, 50, 40, 85, 80, 20, 10, 30, 35, 70, 75]. The key at position 8 (the value 20) is deleted…
- Binary search (lo = 0, hi = n − 1, mid = ⌊(lo + hi)/2⌋; each loop iteration compares a[mid] once and ends the search on equality) is run…
- Evaluate the postfix expression 8 2 3 ^ / 2 3 + 5 3 - - where ^ is exponentiation (x ^ y = xʸ), / is integer division and the operators…