#include<stdio.h>
int main()
{
int a[20],min,max;
int n;
printf("\nEnter the num of elements: ");
scanf("%d",&n);
printf("Enter the elements\n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0)
{
min=max=a[i];
}
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
printf("The largest element is %d. The smallest element is %d.", max, min);
}
what is the disadvantage of sparse matrix?
using multidimensional array
Yes but why.
The root of the tree is stored in array element [0]; for any node of the tree that is stored in array element [i], its left child is stored in array element [2*i], its right child at [2*i+2]
A fast-transpose is a computer algorithm that quickly transposes a sparse matrix using a relatively small amount of memory. Using arrays normally to record a sparse matrix uses up a lot of memory since many of the matrix's values are zero. In addition, using the normal transpose algorithm to transpose this matrix will take O(cols*elements) amount of time. The fast-transpose algorithm only uses a little memory to record the matrix and takes only O(cols+elements) amount of time, which is efficient considering the number of elements equals cols*rows.
A sparse matrix contains many (often mostly) zero entries. The basic idea when storing sparse matrices is to only store the non-zero entries as opposed to storing all entries. Depending on the number and distribution of the non-zero entries, different data structures can be used and yield huge savings in memory when compared to a naïve approach. One example of such a sparse matrix format is the (old) Yale Sparse Matrix Format [1]. It stores an initial sparse N×N matrix M in row form using three arrays, A, IA, JA. NZ denotes the number of nonzero entries in matrix M. The array Athen is of length NZ and holds all nonzero entries of M. The array IA stores at IA(i) the position of the first element of row i in the sparse array A. The length of row i is determined by IA(i+1) - IA(i). Therefore IA needs to be of length N + 1. In array JA, the column index of the element A(j) is stored. JA is of length NZ. Another possibility is to use quadtrees
what is the disadvantage of sparse matrix?
using multidimensional array
Yes but why.
Please use the discussion area to state your question in English.
The root of the tree is stored in array element [0]; for any node of the tree that is stored in array element [i], its left child is stored in array element [2*i], its right child at [2*i+2]
A fast-transpose is a computer algorithm that quickly transposes a sparse matrix using a relatively small amount of memory. Using arrays normally to record a sparse matrix uses up a lot of memory since many of the matrix's values are zero. In addition, using the normal transpose algorithm to transpose this matrix will take O(cols*elements) amount of time. The fast-transpose algorithm only uses a little memory to record the matrix and takes only O(cols+elements) amount of time, which is efficient considering the number of elements equals cols*rows.
In a complete binary tree (CBT) stored using an array, the parent of an element at index i can be found at index (i-1)/2, assuming the array is 0-indexed. So for an element stored at index 11, the parent node would be stored at index (11-1)/2 = 5.
The advantages of using an array are that lists of the same data types can be stored easily without the need for a connection to a database. For example, a list of names can be stored in an array and only one variable need be declared. - Mike Hoerger
write ashell script to add awo matrix using array.
sorry
You've pretty much answered your own question because a two-dimensional array is a matrix. Indeed, all multi-dimensional arrays are matrices. When we create a matrix, we generally know what type of data will be stored in the matrix, how many dimensions it will have and how many elements each dimension will have, thus an array is the ideal container to represent a matrix. It provides the most compact method of storing homogeneous data, provides efficient constant-time random access to the data and introduces the least amount of abstraction into the representation. Most languages do not provide a built-in matrix type, however this is simply because there is no one matrix type that would suit every possible application. However, all languages do provide a built-in array mechanism which can be used as the basis for any matrix type which is both simple to create and easy to maintain.