B.Tech / B.E — Core CS

Data Structures — Arrays Complete Notes

📖 Data Structures· ⌨️ Typed notes · 🌐 English

Complete Core CS notes for B.Tech / B.E. Covers all important topics with formulas, examples and PYQ solutions.

🏫 eGuru24 Team
⬇️0 downloads
❤️0 likes
👁️12 views
📅23 Jul 2026
Preview

Arrays — Data Structures



Definition


An array is a collection of elements of the same data type stored in contiguous memory locations.

Declaration (C Language)


``c
int arr[10]; // Integer array of size 10
float marks[5]; // Float array of size 5
char name[20]; // Character array
`

Types of Arrays


1. 1D Array — Single row: int a[5] = {1,2,3,4,5}

2. 2D Array — Matrix: int matrix[3][3]

3. Multi-dimensional — 3D and beyond


Memory Representation


• Elements stored in consecutive memory locations

• Address of element: Base_Address + (index × size_of_datatype)

• Example: If base = 1000, int size = 4 bytes

- a[0] = 1000, a[1] = 1004, a[2] = 1008

Operations & Time Complexity


| Operation | Time Complexity |

|-----------|----------------|

| Access | O(1) |

| Search | O(n) linear |

| Insertion | O(n) |

| Deletion | O(n) |


Important Algorithms on Arrays


Linear Search


`c
int linearSearch(int arr[], int n, int key) {
for(int i=0; i<n; i++)
if(arr[i] == key) return i;
return -1;
}
`

Binary Search (sorted array only)


`c
int binarySearch(int arr[], int n, int key) {
int low=0, high=n-1;
while(low <= high) {
int mid = (low+high)/2;
if(arr[mid]==key) return mid;
else if(arr[mid]<key) low=mid+1;
else high=mid-1;
}
return -1;
}
``

Advantages


• Fast access O(1) using index

• Easy to implement

• Cache-friendly (contiguous memory)


Disadvantages


• Fixed size (static)

• Costly insertion/deletion

• Memory waste if not fully used


PYQ (Previous Year Questions)


Q1. What is time complexity of accessing an element in an array? — O(1)
Q2. Difference between array and linked list? — Array: fixed size, O(1) access; Linked List: dynamic, O(n) access
Q3. Write program for bubble sort on array. (See Sorting topic)