Overview of One Dimensional Array
Array: A data structure which stores homogenous data types in continuous memory allocation is known as an Array. It stored several related items using a single name. Different elements can be accessed using the index.
Consider a cupboard in your local library. It has different sections for different genres of book. Each section can accommodate a specific number of books.
Now consider the section of Mathematics wherein one would only find books on mathematics.
From the above figure, we can derive the following analogy with Array:
Mathematics genre - data type
width of a book- size of data type
size of section- the size of the array
colour of a book- data
The index of memory starts at 0.
While using C and C++ programming languages, the size of the array is fixed.
The size of the array in Python, Java, Kotlin, JavaScript and PHP is not fixed.
Applications of Array:
- To maintain a list of data. For example: To search if a person has registered in a list of registered names.
- Sort the numbers to find the median.
- Use for CPU scheduling.
- Use to implement abstract data structures like stacks and queues.
Advantages of a single-dimensional array:
- Convenient searching and sorting of elements.
- Makes code reusable.
- Use lesser memory then linked list, tree, graph etc.
Disadvantages of a single-dimensional array:
- The programmer has to guess the required size. Large size leads to wastage of memory space. Less size than required leads to problems in execution.
- Difficult Insertion and deletion. Shifting of elements requires additional computation during the stated operations.
Comments
Post a Comment