Overview of Arrays


<aside> <img src="/icons/table_red.svg" alt="/icons/table_red.svg" width="40px" /> Table of Contents

</aside>

<aside> 💡

  1. Basics of arrays </aside>

<aside> 💡

</aside>


Basics of arrays


  1. Arrays: Basics of Arrays, Operations on Arrays

    1. Arrays are one of the most fundamental data structures in computer science. They provide a way to store and manipulate multiple elements in a single structure, offering a foundation for building more complex data structures and algorithms.

  2. Basics of Arrays

    1. What is an Array?

      1. An array is a collection of elements, all of the same data type, stored in contiguous memory locations. It allows indexed access to its elements, which makes operations like traversal and searching efficient.

      2. Key Characteristics:

        1. Fixed Size: The size of an array is determined when it is created and cannot be changed later.
        2. Same Data Type: All elements in the array must be of the same data type (e.g., integers, floats, strings).
        3. Indexed Access: Elements are accessed using indices, starting from 0 in most programming languages.
      3. Example:

        An array of integers to store the marks of five students:

        Index:      0   1   2   3   4
        Marks:     85  90  78  92  88
        
    2. Why Use Arrays?

      1. Efficient Data Storage: Arrays allow storage of multiple elements in a single variable, reducing memory overhead.
      2. Indexed Access: Enables direct access to elements using their index, making retrieval and updates efficient.
      3. Foundation for Other Structures: Arrays form the basis of many advanced data structures like stacks, queues, and matrices.
    3. Types of Arrays

      1. One-Dimensional Arrays: A linear array where elements are stored in a single row.
        1. Example: [10, 20, 30, 40, 50]
      2. Multi-Dimensional Arrays: Arrays with more than one dimension, such as 2D arrays (matrices).
        1. Example: A 2x3 matrix:

          1  2  3
          4  5  6