Unit 3 – Detailed Notes (Arrays and Related Concepts)
1. Array Notation and Representation
Arrays are collections of elements of the same data type stored in contiguous memory locations.
Each element can be accessed using an index, starting from 0. Arrays simplify storing large
volumes of similar data such as marks, temperatures, or IDs. Representation typically uses square
brackets: arr[i].
2. Manipulating Array Elements
Array operations include traversing, inserting, deleting, updating, and searching. Traversing uses
loops to visit each element. Inserting and deleting require shifting elements since array sizes are
fixed. Updating simply assigns a new value to a given index.
3. Multi-Dimensional Arrays
These store data in more than one dimension, commonly 2D arrays (matrices). They are declared
as int a[rows][columns]. C stores multi-dimensional arrays in row-major order. Ideal for grids, tables,
and matrix-based computations.
4. Character Arrays and Strings
A character array stores characters sequentially. A string is a character array ending with a null
terminator '\0'. Strings in C are handled through arrays, not a separate type. Common operations
include reading input, printing, copying, concatenation, and comparison using functions from
string.h.
5. Structure
A structure is a user-defined data type that groups variables of different data types under one
name. It organizes complex data like student records or employee details. Each member is
accessed using the dot operator. Structures help model real-world entities effectively.
6. Union
A union is similar to a structure but uses shared memory for all its members, meaning only one
member can hold a value at a time. Useful when working with multiple possible data types but
needing memory efficiency. Access is also done using the dot operator.
7. Enumerated Data Types (enum)
Enums assign names to integer constants, making programs easier to read and manage. Example:
enum day {Mon, Tue, Wed}. Enums can improve clarity, especially when working with categories or
fixed sets of values.
8. Array of Structures
This stores multiple structure variables in an array form. Useful for handling lists such as student
records or employee databases. Access is done using index and dot operator, such as s[i].roll.
They combine the power of arrays and structures to handle organized datasets.
9. Basic Searching Algorithms: Linear Search
Linear search checks each element one by one until the target is found. Simple to implement but
slow for large arrays. Time complexity: O(n).
10. Basic Sorting Algorithms: Bubble Sort
Bubble sort repeatedly compares adjacent elements and swaps them if out of order. The largest
value moves to the end in each pass. Easy to write but inefficient for large datasets. Time
complexity: O(n^2).