What are the advantages and disadvantages of using an Array?

  1. Advantages:

  2. Random access is enabled

  3. Saves memory

  4. Cache friendly

  5. Predictable compile timing

  6. Helps in re-usability of code

  7. Disadvantages:

  8. Addition and deletion of records is time consuming even though we get the element of interest immediately through random access. This is due to the fact that the elements need to be reordered after insertion or deletion.

  9. If contiguous blocks of memory are not available in the memory, then there is an overhead on the CPU to search for the most optimal contiguous location available for the requirement.

Now that we know what arrays are, we shall understand them in detail by solving some interview questions. Before that, let us see the functions that Python as a language provides for arrays, also known as, lists.

append() – Adds an element at the end of the list
copy() – returns a copy of a list.
reverse() – reverses the elements of the list
sort() – sorts the elements in ascending order by default.