Question: write in c language 6. [10] A sparse vector is a vector whose most components are zero. To store a sparse vector efficiently it is
write in c language
![write in c language 6. [10] A sparse vector is a vector](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f544ab61e53_93066f544aad8ec6.jpg)

6. [10] A sparse vector is a vector whose most components are zero. To store a sparse vector efficiently it is enough to store only its non-zero components and their index (position in the vector). The components of a vector are indexed starting from 0, like in C arrays. Precisely, to store a sparse vector with n components, only k of which are non-zero, we can use two arrays: val and pos, each of size k For example, if the sparse vector x with 8 components is the following 0 0 23 0 -70 0 48 then k-3 and val contains 23-748 pos contains 24 Notice that the elements of array pos are in increasing order. We will assume that each vector contains at least one non-zero element. Write a function efficient() with prototype void efficient( const int source[], int val[], int pos[], int size) which computes the efficient representation of vector source, by filling the arrays val and pos. Parameter size represents the number of components of vector source (i.e., the size of the array). Assume that the size of arrays pos and val equals the number of non-zero values of vector source. Additionally, write a function reconstruct() with prototype void reconstruct( int sourcell, int m, const int val[], const int posll, int n) which reconstructs vector source from the efficient representation stored in arrays val and pos
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
