Question: Writing this program in C. How do I do this exercise? A sparse vector is a vector whose most components are zero. To store a

 Writing this program in C. How do I do this exercise?

Writing this program in C. How do I do this exercise?

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 7 0 0 48 then k-3 and val contains 23 -7 48 pos contains 2 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[l, int val, int pos[I, 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 source[, int m, const int val[l, const int pos[l, int n) which reconstructs vector source from the efficient representation stored in arrays val and pos. Parameter n represents the size of arrays val and pos. Parameter m represents the size of array source, which equals the dimension of the vector Write a program to test the two functions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!