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

Notes

Uploaded by

pranshusahu862
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)
12 views

Notes

Uploaded by

pranshusahu862
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
You are on page 1/ 2

Arrays in Data Structures

1. Introduction
An array is a collection of elements, each identified by an index or key. Arrays store data in
contiguous memory locations.

2. Types of Arrays
• One-Dimensional Array: A single list of elements.
• Multi-Dimensional Array: Arrays of arrays (e.g., 2D array is an array of arrays).

3. Array Representation
• In Memory: Elements are stored sequentially.
• Indexing: The first element is at index 0.

4. Operations on Arrays
• Insertion: Adding an element at a specific position.
• Deletion: Removing an element at a specific index.
• Traversal: Accessing each element in sequence.
• Searching: Finding an element (linear search, binary search).
• Updating: Changing the value of an element at a given index.

5. Advantages
• Constant-time access: Array elements can be accessed in constant time, O(1).
• Memory efficiency: Arrays use a contiguous block of memory.

6. Disadvantages
• Fixed size: The size of an array is fixed at the time of creation.
• Inefficient insertions and deletions: Operations like inserting or deleting elements may be
inefficient as they might require shifting elements.

7. Example Code (in C)


c
Copy code
#include <stdio.h>

int main() {
int arr[5] = {10, 20, 30, 40, 50};

// Traversing the array


for(int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
return 0;
}
8. Applications of Arrays
• Storing multiple items of the same type (e.g., a list of integers, strings).
• Matrix representation for 2D games, graphics.
• Implementing other data structures like heaps, hash tables.

You might also like