Detailed_Array_Notes
Detailed_Array_Notes
1. ARRAYS
An array is a collection of elements, all of the same type, placed in contiguous memory locations.
Advantages of Arrays:
Types of Arrays:
- One-dimensional (1D)
- Two-dimensional (2D)
--------------------------------------------------
Definition:
Memory Layout:
Assume the base address of arr is 1000 and each int takes 4 bytes:
...
Example:
--------------------------------------------------
Definition:
Declaration:
Memory Representation:
Two approaches:
Example:
matrix[1][2] = 6
Memory layout: 1 2 3 4 5 6
--------------------------------------------------
4. TRIANGULAR ARRAYS
Example 3x3:
[1 0 0]
[2 3 0]
[4 5 6]
Efficient Representation:
Index Mapping:
5. SPARSE MATRICES
Definition:
Representation Methods:
Store only non-zero elements with their row and column indices.
Example matrix:
[0 0 3]
[0 0 0]
[0 7 0]
Triplet form:
0 2 3
2 1 7
Structure:
struct Node {
Node* next;
};
- Saves memory
--------------------------------------------------
Conclusion:
Arrays are a foundational data structure. Specialized techniques like triangular and sparse matrix