0% found this document useful (0 votes)
14 views

Array and Its Address Calculation....s

Uploaded by

ebhattacharjya
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Array and Its Address Calculation....s

Uploaded by

ebhattacharjya
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

TECHNO MAIN SALT LAKE

DEPARTMENT NAME: B.TECH IN ELECTRONICS AND COMPUTER SCIENCE


SUBJECT NAME: DATA STRUCTURE &ALGORITHMS
TOPIC: ARRAY AND ITS ADDRESS CALCULATION
COURSE CODE: PC-ECS301
SUPERVISOR NAME: DR. MONU BHAGAT
GROUP MEMBERS NAME WITH ROLL NO:
ESHITA BHATTACHARJYA(13032223011)
PRIYA MONDAL (13032223019)
SAMRIDHI JALAN (13032223020)
SHREYA KUTARIYAR (13032223023)
TANISHA GUPTA (13032223030)
Introduction to Arrays
An array is a fundamental
data structure that stores a
collection of elements of
the same data type in a
contiguous block of
memory. Arrays provide
efficient access to
individual elements and
allow for rapid processing
of data.
Memory Representation of Arrays
 Contiguous Memory
Arrays are stored in contiguous memory
locations, allowing for efficient access and
manipulation of elements.
 index-Base Addressing
Each element in an array is
identified by a unique index,
which maps to a specific
memory address.
 Fixed-Size Allocation
The size of an array is fixed at the
time of declaration, limiting the
number of elements it can store.
Address Calculation for Arrays

Base Address
The starting memory address of the array, which serves
as the reference point for calculating the addresses of
individual elements.

Element Address
The final memory address of an element, calculated by
adding the base address and the index offset.

Index Offset
The offset from the base address, determined by the
index of the element and the size of each element in the
array.
Indexing and Accessing Array Elements

Zero-Based Indexing
Array indices typically start from 0, with the first element at index 0 and the last element at
index (n-1), where n is the size of the array.
Direct Access
Arrays allow for constant-time access to any element, as the address of an element can be
calculated directly from its index.
Bounds Checking
It's important to ensure that array indices are within the valid range to avoid accessing elements
outside the array's bounds, which can lead to undefined behavior or runtime errors.
Array Traversal and Iteration
Sequential Iteration
Arrays can be easily traversed by iterating through the elements in sequential order, often using a loop
structure.

Random Access
Arrays allow for random access to any element, enabling efficient searching and manipulation of specific
elements.

Pointer Arithmetic
Pointers can be used to navigate through an array, with pointer arithmetic allowing for efficient traversal and
access.
Dynamic Arrays and Memory
Allocation

Fixed-Size Limitation
Array Operations Insertion , Deletion
, and Searching Traditional arrays have a fixed size, which can be a
limitation when the number of elements is not known
Insertion in advance.
Inserting an element into an array requires shifting
existing elements to make room for the new element, Dynamic Resizing
which can be time-consuming for large arrays.
Deletion
Dynamic arrays, such as vectors or Array Lists, can
automatically resize themselves to accommodate new
Deleting an element from an array involves shifting the
remaining elements to fill the gap left by the removed elements, providing more flexibility.
element, which can also be inefficient.
Memory Allocation
Searching
Arrays support efficient searching algorithms, such as Dynamic arrays allocate memory in larger blocks,
linear search and binary search, to quickly locate specific
elements within the data structure.
allowing for efficient insertion and deletion of
elements without the need for constant memory
reallocations.
Multidimensional Arrays and Address Array Applications and Use
Calculation Cases
2D Arrays
Multidimensional arrays can have more than one dimension,
such as 2D arrays that can be visualized as tables or grids. Data Storage
Address Calculation Arrays are commonly used to store and manage large
collections of data, such as in databases, spreadsheets, and
scientific computing.
The address of
an element in a multidimensional array is calculated by
considering the offsets for each dimension, using a formula
Image Processing
that takes into account the size of each dimension.
Arrays are essential for representing and manipulating digital
Efficient Storage images, where each pixel is stored as an element in a 2D array.

Multidimensional arrays store elements in contiguous Signal Processing


memory locations, allowing for efficient access and
manipulation of data. Arrays are used to represent and process digital signals, such as
audio and video data, in various applications like multimedia and
telecommunications.
Calculating the address of any element In the 1-D
array:
Example:
Address of A[I] = B + W * (I – LB) Given a 1D array A[1300 ... 1900] with base
Where: address B = 1020 and element size W = 2
B = Base address of the array bytes, find the address of A[1700].
W = Storage size of one element (in Solution:
bytes) B = 1020
I = Index of the element whose W = 2 bytes
address is to be found I = 1700
LB = Lower bound of the array LB = 1300
index (assume 0 if not specified) Address of A[1700] = 1020 + 2 * (1700 –
1300)
= 1020 + 2 * 400
= 1020 + 800
= 1820
Calculating the address of any element In the 2-D
array: Example:
Find the address of A in a 2D array A[0:15,
Row Major Order:
15:35] with base address B = 1500, element
Address of
size W = 1 byte, using row major order.
A[I][J] = B + W * [N * (I – Lr) + (J – Lc)]
Solution:
Column Major Order:
B = 1500
Address of
W = 1 byte
A[I][J] = B + W * [(I – Lr) + M * (J – Lc)]
I = 15
Where:
J = 20
B = Base address of the array
Lr = 0
W = Storage size of one element (in bytes)
Lc = 15
I = Row index of the element
N = 21 (35 – 15 + 1)
J = Column index of the element
Address of A = 1500 + 1 * [21 * (15 – 0) +
Lr = Lower bound of row index
(20 – 15)]
Lc = Lower bound of column index
= 1500 + 1 * [21 * 15 + 5]
N = Number of columns
= 1500 + 1 * [315 + 5]
M = Number of rows
= 1500 + 320
= 1820
Conclusion
 Efficient Data Storage

Arrays provide a compact and efficient way to store and access


large collections of data in contiguous memory locations.
Flexible Data Structures
Dynamic arrays, such as vectors and Array Lists, offer the ability
to resize and grow as needed, providing more flexibility than
fixed-size arrays.
Diverse Applications
Arrays are a fundamental data structure with a wide range of
applications, from data storage and processing to image and
signal analysis.
References
1) "The Art of Computer Programming, Volume 1: Fundamental Algorithms" by Donald E. Knuth
2) IEEE Xplore Digital Library (https://ieeexplore.ieee.org)
3) Articles on arrays: Geeks for Geeks (https://www.geeksforgeeks.org)
4) Tutorials Point (https://www.tutorialspoint.com)

THANK YOU

You might also like