Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions