Question: (Python) A sparse array (a list) is a sequence of numbers in which most entries are zero. An efficient way of storing a sparse array
(Python)
A sparse array (a list) is a sequence of numbers in which most entries are zero. An efficient way of storing a sparse array (a list) is a dictionary in which the keys are positions with nonzero values, and the values are the corresponding values in the sequence. For example, the sequence [0, 0, 0, 0, 0, 4, 0, 0, 0, 2, 9] would be represented with the dictionary { 5:4, 9:2, 10:9 }. Write a program that will a generate dictionary given any list (as demonstrated above) and will generate a list from a dictionary (for example the dictionary { 5:4, 9:2, 10:9 } would produce the list [0, 0, 0, 0, 0, 4, 0, 0, 0, 2, 9]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
