0% found this document useful (0 votes)
8 views4 pages

Array

Uploaded by

animationc219
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Array

Uploaded by

animationc219
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

1.

Array

An array is a collection of items of same data type stored at

contiguous memory locations.

Array

Characteristics of Array Data Structure:

•Homogeneous Elements: All elements within an array must be of the same

data type.

•Contiguous Memory Allocation: In most programming languages,

elements in an array are stored in contiguous (adjacent) memory locations.

•Zero-Based Indexing: In many programming languages, arrays use zero-

based indexing, which means that the first element is accessed with an index

of 0, the second with an index of 1, and so on.


•Random Access: Arrays provide constant-time (O(1)) access to elements.

This means that regardless of the size of the array, it takes the same amount

of time to access any element based on its index.

Types of arrays:

•One-Dimensional Array: This is the simplest form of an array, which

consists of a single row of elements, all of the same data type. Elements in a

1D array are accessed using a single index.

One-Dimensional Array

•Two-Dimensional Array: A two-dimensional array, often referred to as a

matrix or 2D array, is an array of arrays. It consists of rows and columns,

forming a grid-like structure. Elements in a 2D array are accessed using two

indices, one for the row and one for the column.

Two-Dimensional Array:
•Multi-Dimensional Array: Arrays can have more than two dimensions,

leading to multi-dimensional arrays. These are used when data needs to be

organized in a multi-dimensional grid.

Multi-Dimensional Array

Types of Array operations:

•Accessing Elements: Accessing a specific element in an array by its index

is a constant-time operation. It has a time complexity of O(1).


•Insertion: Appending an element to the end of an array is usually a

constant-time operation, O(1) but insertion at the beginning or any specific

index takes O(n) time because it requires shifting all of the elements.

•Deletion: Same as insertion, deleting the last element is a constant-time

operation, O(1) but deletion of element at the beginning or any specific

index takes O(n) time because it requires shifting all of the elements.

•Searching: Linear Search takes O(n) time which is useful for unsorted data

and Binary Search takes O(logn) time which is useful for sorted data.

You might also like