03 Array
03 Array
• Fixed-Size: Because other data may follow immediately after the block of
memory occupied by your array, expanding the block would overwrite that
data, potentially causing severe errors or malfunctions. Therefore, when
you allocate memory for an array, you must know its size upfront without
the possibility of changing it later.
Array Cont…
Types of Array: There are two main types of arrays:
Parameters
• Type code − The type code character used to create the array.
• initializer − array initialized from the optional value, which must be a list,
a bytes-like object, or inerrable over elements of the appropriate type.
Representation of Arrays in Data Structures
Example
Representation of Arrays in Data Structures
Traversal
Basic Operations on Arrays in Data Structures
Insertion
Basic Operations on Arrays in Data Structures
Insertion
Basic Operations on Arrays in Data Structures
Deletion Operation
Basic Operations on Arrays in Data Structures
Deletion Operation
Basic Operations on Arrays in Data Structures
Search Operation
Basic Operations on Arrays in Data Structures
Update Operation
Complexity Analysis of Operations on Arrays
Advantages of Arrays in Data Structures
• Fixed-size: The size of an array is fixed at the time of its creation, which means that
once the array is created, its size cannot be changed. This can be a limitation in
situations where the size of the data is not known in advance.
• Memory wastage: There will be a wastage of memory if we store less number of
elements than the declared size because there is static memory allocation in arrays.
• Inefficient insertion and deletion: Arrays store data in contiguous memory locations,
which makes deletion and insertion very difficult to implement. All the elements after
insertion or deletion must be shifted to accommodate the new element or fill in the
gap. This can be a time-consuming process, especially for large arrays.
• Homogeneous data: Arrays can only store elements of the same data type, which
can be a limitation in situations where the user needs to store data of different types.
• No built-in support for dynamic resizing: While some programming languages provide
built-in support for dynamic resizing of arrays, many do not. In those cases, the
developer may have to implement their resizing logic, which can be complex and
error-prone.