Arrays 1D and 2D
Arrays 1D and 2D
CSE Department
National Institute of Technology Rourkela
Reference
Most of the content of this presentation belongs to the following
book:
Worst-case O(n)
Average-case O(n)
Best-case O(1)
Worst-case space O(1)
If the arrays are unsorted, then merging the arrays is very simple,
as one just needs to copy the contents of one array into another.
1 5 9 2 6 10 3 7 11 4 8 12
Solution
Address(A[I][J]) = Base_Address + w{N (I – 0) + (J – 0)}
Address(marks[18][4]) = 1000 + 2 {5(18 – 0) + (4 – 0)}
= 1000 + 2 {5(18) + 4}
= 1000 + 2 (94)
= 1000 + 188 = 1188
Therefore,
arr[0][0] = *(arr)[0] = *((*arr)+0) = *(arr[0]+0)
arr[1][2] = (*(arr+1))[2] = *((*(arr+1))+2) = *(arr[1]+2)
Array of structure:
struct student{
int rollno;
char name[10];
};
struct student st[5];
NIT Rourkela Puneet Kumar Jain “Data Structure and Algorithms”
Initialization of array