790 views
1 votes
1 votes

An $n \times n$ matrix is said to be tridiagonal if its entries $a_{ij}$ are zero except when $|i−j| \leq 1$ for $1 \leq i, \: j \leq n$. Note that only $3n − 2$ entries of a tridiagonal matrix are non-zero. Thus, an array $L$ of size $3n − 2$ is sufficient to store a tridiagonal matrix. Given $i, j$, write pseudo-code to

  1. store $a_{ij}$ in $L$, and
  2. get the value of $a_{ij}$ stored earlier in $L$.

2 Answers

0 votes
0 votes

Question (ii)

Since the indexing starts with 1, 1st row has only 2 elements {A[1,1] ,A[1,2]}

And 2nd row onwards each row has 3 elements.{A[i,j-1], A[i.j], A[i,j+1]}

A[i,j] = [2+(i-1)*3 + f(i,j)]

where f(i,j) = 0        (j=i-1)

                      1        (j=i)

                      2        (j=i+1)

Note: A[i,j] where |i-j|>1    ---not valid

edited by

Related questions

2 votes
2 votes
0 answers
2
go_editor asked Jun 3, 2016
361 views
Consider six distinct points in a plane. Let $m$ and $M$ denote the minimum and maximum distance between any pair of points. Show that $M/m \geq \sqrt{3}$.
2 votes
2 votes
1 answer
3
go_editor asked Jun 3, 2016
778 views
The numbers $1, 2, \dots , 10$ are arranged in a circle in some order. Show that it is always possible to find three adjacent numbers whose sum is at least $17$, irrespec...
1 votes
1 votes
0 answers
4