Data Structures and Algorithms-Fall-2024-Sheet-02
Data Structures and Algorithms-Fall-2024-Sheet-02
Question One
Describe how the following sparse matrix may be stored using coordinates method, assume 1-based
indexing. Assume 1-based indexing and the number of non-zero elements never exceeds 9.
Question Two
The figure shown below is representation of a 6x6 sparse array S whose non-zero elements will not
exceed 10. Assuming 1-based indexing, reconstruct the array S. The value of top is 8.
Question Three
a) What are the advantages of using access tables to represent orthogonal arrays when compared to
Dope vectors?
b) Assume that each element of an array A is stored in row-major order occupies four units of
storage. If A is declared by each of the following, and the address of the first element of A is
1000, find the address of the indicated array element:
i. Var A: array [1..100] of T; address of A[10]
ii. Var A: array [5..10, -10..20] of T; ‘’ ‘’ A[7, 7]
b) Assume that the elements of array A are stored in row-major order, and that each element
occupies five units of storage. The size of A is declared by A [-100..1 , 1..20] , and the address
of A [-100,1] is 5000.
i. If the array A is to be stored using access tables, how many access tables are needed to get
the location of the element A[i1, i2]?
Lecture Instructors: Prof.Dr. Ahmed El-Nahas Prof. Dr. Saleh Elshehaby Prof. Dr. Nagia Ghanem
Tutorial Instructors: Eng. Ahmed Abdelhamid Wahid Eng. Magdy Sedra
Eng. Ahmed Ashraf Eng. Mohamed Sobhy
Eng. Seif Ahmed Eng. Begad Wael
Course Name: Data Structures
and Algorithms Assigned: 06/11/2024
Course Code: 00108N Due: 11/11/2024
Semester: Fall 2024
ii. Derive formula for the contents of each access table as well as formula for
computing address of the element A[i1, i2].
iii. Derive the address for the element mentioned in (ii).
Question Four
a) A lower triangular matrix, T, such that, T[i, j] = 0, when i < j, where, 0 ≤ i, j ≤ n. What is the
mapping function which will allow this matrix to be stored, row by row, in a vector V, which has,
n(n + 1)/2, elements ?
b) What is the corresponding function for an upper triangular matrix, for which, T[i, j] = 0 when i >
j, and the elements are stored column by column?
c) Show the single vector representation for each of the following triangular matrices.
(Assume 1-based addressing)
Question Five
Show graphically, how the following matrix, assumed to be sparse, may be represented in memory using
the coordinate method. The number of non-zero elements in the matrix will not exceed 12 entries.
Lecture Instructors: Prof.Dr. Ahmed El-Nahas Prof. Dr. Saleh Elshehaby Prof. Dr. Nagia Ghanem
Tutorial Instructors: Eng. Ahmed Abdelhamid Wahid Eng. Magdy Sedra
Eng. Ahmed Ashraf Eng. Mohamed Sobhy
Eng. Seif Ahmed Eng. Begad Wael
Course Name: Data Structures
and Algorithms Assigned: 06/11/2024
Course Code: 00108N Due: 11/11/2024
Semester: Fall 2024
Question Six
a. Derive the appropriate addressing equation for computing the location of the element X [s1, s2, s3]
of a three-dimensional integer array X stored in lexicographic order. Assume that each integer
occupies 4 cells of memory, and X is declared by: var X: array [L..M, O..P, Q..R] of integer
b. If the array X is stored using the access table method, how many tables are needed for accessing
the elements of X? Also, give the addressing formula in this case.
Question Seven
Assume 1-based addressing, represent the given 5 x 5 triangular matrix using a single vector. What is the
size of the vector?
Lecture Instructors: Prof.Dr. Ahmed El-Nahas Prof. Dr. Saleh Elshehaby Prof. Dr. Nagia Ghanem
Tutorial Instructors: Eng. Ahmed Abdelhamid Wahid Eng. Magdy Sedra
Eng. Ahmed Ashraf Eng. Mohamed Sobhy
Eng. Seif Ahmed Eng. Begad Wael