(i) Sparse array
(ii) Lower and upper triangular matrix
Ans:-
(i) Sparse array:-
A sparse array is a data structure that is used to represent arrays with a large number of
elements that are mostly empty or contain a default value. Rather than storing every single
element, a sparse array only stores the non-default or non-empty values, along with their
indices. This results in a more compact representation of the array that can save memory and
improve performance.
The structure of a sparse array typically includes two arrays: one array contains the indices of
the non-empty or non-default elements, and the other array contains the corresponding
values. These two arrays can be used to reconstruct the original array by filling in the default
or empty values with the default value.
Sparse arrays are used in a variety of applications, such as image processing, natural language
processing, and scientific computing. They are particularly useful for large datasets with a
significant amount of missing or default values, as they can save memory and improve
performance by avoiding the need to store and process empty or default values.
In addition to reducing memory usage, sparse arrays can also improve the performance of
certain algorithms, such as matrix multiplication, by allowing for more efficient storage and
processing of data. As a result, many modern programming languages and libraries provide
support for sparse arrays, including Python's NumPy library and Java's Apache Commons
Math library.
(ii) Lower and upper triangular matrix
A lower triangular matrix is a square matrix in which all the entries above the main diagonal
are zero. Similarly, an upper triangular matrix is a square matrix in which all the entries
below the main diagonal are zero. The main diagonal is defined as the line of entries from the
upper left corner of the matrix to the lower right corner.
The structure of a triangular matrix is typically stored in a one-dimensional array, with the
entries stored in row-major or column-major order. This allows for efficient storage and
processing of the matrix, as the zero entries can be omitted and the remaining entries can be
stored in a contiguous block of memory.
Lower and upper triangular matrices are widely used in linear algebra and numerical analysis,
as they have many important properties that make them useful for solving systems of linear
, equations and performing matrix operations. For example, the determinant of a triangular
matrix is simply the product of its diagonal entries, which can be easily computed using a
simple multiplication. Additionally, triangular matrices are invertible if and only if all of their
diagonal entries are nonzero.
Lower and upper triangular matrices are also used in computer graphics and computer vision,
where they can be used to represent transformations such as rotations, translations, and
scaling. In particular, affine transformations can be represented using upper triangular
matrices, while the inverse of an upper triangular matrix is also an upper triangular matrix.
In summary, lower and upper triangular matrices are important structures in linear algebra
and numerical analysis, as well as computer graphics and computer vision. They have many
useful properties that make them efficient for storing and processing large matrices, and they
are widely used in a variety of applications.
Q.2) What do you mean by the following with respect to the STACK data structure?
(i) PUSH
(ii) POP
(iii) OVERFLOW
(iv) UNDERFLOW
Explain with diagram.
Ans:-
The stack data structure is a last-in, first-out (LIFO) data structure that allows for efficient
insertion and deletion of elements. The following are some common terms used with respect
to the stack data structure:
(i) PUSH: This operation is used to add an element to the top of the stack. The new element
becomes the top element of the stack. The push operation increases the size of the stack by 1.
(ii) POP: This operation is used to remove the top element of the stack. The element that was
added last is the first one to be removed, and the next element becomes the new top element
of the stack. The pop operation decreases the size of the stack by 1.
(iii) OVERFLOW: An overflow occurs when a push operation is attempted on a full stack.
This means that the stack has reached its maximum capacity and cannot store any more
elements. It is important to check for overflow conditions before attempting to push an
element onto the stack.