Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Memory Storage and Array Address Computation, Summaries of Data Structures and Algorithms

An overview of memory storage for one-dimensional and two-dimensional arrays, including the concepts of row-major and column-major order. It also explains the formula for computing the address of an element in a one-dimensional array and the general formula for computing the address of an element in a two-dimensional array. The document further discusses special forms of square matrices, such as diagonal, tridiagonal, lower triangular, upper triangular, and symmetric matrices, and how they can be efficiently represented in memory. It includes examples and algorithms for various array operations like insertion, deletion, and searching. Important topics in data structures and algorithms, particularly related to the representation and manipulation of arrays, which are fundamental data structures in computer science.

Typology: Summaries

2022/2023

Uploaded on 10/01/2023

given-1
given-1 🇮🇳

1 document

1 / 71

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Array
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47

Partial preview of the text

Download Memory Storage and Array Address Computation and more Summaries Data Structures and Algorithms in PDF only on Docsity!

Array

Array ADT

• The simplest but useful data structure.

• Assign single name to a homogeneous collection of

instances of one abstract data type.

– All array elements are of same type, so that a

pre−defined equal amount of memory is

allocated to each one of them.

• Individual elements in the collection have an

associated index value that depends on array

dimension.

float marks[10];

Memory Storage

Memory Storage – One Dimensional Array

int student[4];

float marks[3];

student[1]

student[0] student[2]

student[3]

marks[1]

marks[0] marks[2]

Contd…

• Row-major order

Row0 Row1 Row

• Column-major order

Col0 Col1 Col2 Col3 Col

(0,0) (0,1) (0,2) (0,3) (0,4) (1,0) (1,1) (1,2) (1,3) (1,4) (2,0) (2,1) (2,2) (2,3) (2,4)

(0,0) (^) (1,0) (2,0) (0,1) (^) (1,1) (2,1) (0,2) (^) (1,2) (2,2) (0,3) (^) (1,3) (2,3) (0,4) (^) (1,4) (2,4)

Array Address Computation

1D array – address calculation

• Let A be a one dimensional array.

• Formula to compute the address of the

Ith^ element of an array (A[I]) is:

Address of A[I] = B + W * ( I – LB )

[0] 1

[1] 2

[2] 3

[3] 4

[4] 5

[5] 6

B

W

Given: B = 100, W = 4, and LB = 0

A[0] = 100 + 4 * (0 – 0) = 100

1D array – address calculation

• Let A be a one dimensional array.

• Formula to compute the address of the

Ith^ element of an array (A[I]) is:

Address of A[I] = B + W * ( I – LB )

[0] 1

[1] 2

[2] 3

[3] 4

[4] 5

[5] 6

B

Given:

B = 100, W = 4, and LB = 0 A[1] = 100 + 4 * (1 – 0) = 104 A[2] = 100 + 4 * (2 – 0) = 108 A[3] = 100 + 4 * (3 – 0) = 112 A[4] = 100 + 4 * (4 – 0) = 116 A[5] = 100 + 4 * (5 – 0) = 120

Example – 2

• If LB = 5, Loc(A[LB]) = 1200, and W = 4.

• Find Loc(A[8]).

Address of A[I] = B + W * ( I – LB )

Loc(A[8]) = Loc(A[5]) + 4 * (8 – 5)

Example – 3

• Base address of an array B[1300…..1900] is 1020

and size of each element is 2 bytes in the memory.

Find the address of B[1700].

Address of A[I] = B + W * ( I – LB )

• Given: B = 1020, W = 2, I = 1700, LB = 1300

Address of B[1700] = 1020 + 2 * (1700 – 1300)

2D Array – Address Calculation

  • If A be a two dimensional array with M rows and N

columns. We can compute the address of an element at Ith

row and Jth^ column of an array ( A[I][J] ).

B = Base address/address of first element, i.e. A[LBR][LBC] I = Row subscript of element whose address is to be found J = Column subscript of element whose address is to be found W = Number of bytes used to store a single array element LBR = Lower limit of row/start row index of matrix, if not given assume 0 LBC = Lower limit of column/start column index of matrix, if not given assume 0 N = Number of column of the given matrix M = Number of row of the given matrix

[0] [1] [2] [3] [0] (^1 2 3 ) [1] (^5 6 7 ) [2] (^9 10 11 )

Row-major

Address of A[I][J] = B + W * ( N * ( I – LBR ) + ( J – LBC ))

Address of A[2][1] = B + W * (4 * (2 – 0) + (1 – 0))

M = 3 N = 4

Address of A[2][1] = B + W * (4 * (2 – 0) + (1 – 0))

Address of A[2][1] = B + W * (4 * (2 – 0) + (1 – 0))

Address of A[2][1] = B + W * (4 * (2 – 0) + (1 – 0))

Address of A[I][J] = B + W * ( N * ( I – LBR ) + ( J – LBC ))

Address of A[I][J] = B + W * ( N * ( I – LBR ) + ( J – LBC ))

Address of A[I][J] = B + W * ( N * ( I – LBR ) + ( J – LBC ))

Contd…

• Row Major

Address of A[I][J] = B + W * ( N * ( I – LBR ) + ( J – LBC ))

• Column Major

Address of A [I][J] = B + W * (( I – LBR ) + M * ( J – LBC ))

• Note: A[LBR…UBR, LBC…UBC]

M = (UBR – LBR) + 1

N = (UBC – LBC) + 1

Example – 4

  • Suppose elements of array A[5][5] occupies 4 bytes, and

the address of the first element is 49. Find the address of the element A[4][3] when the storage is row major. Address of A[I][J] = B + W * ( N * ( I – LBR ) + ( J – LBC ))

  • Given: B = 49, W = 4, M = 5, N = 5, I = 4, J = 3, LBR = 0,

LBC = 0. Address of A[4][3] = 49 + 4 * (5 * (4 – 0) + (3 - 0)) = 49 + 4 * (23) = 49 + 92 = 141