Name some advantages and disadvantages of Arrays

Technology CommunityCategory: ArraysName some advantages and disadvantages of Arrays
VietMX Staff asked 3 years ago

Pros:

  • Fast lookups. Retrieving the element at a given index takes O(1) time, regardless of the length of the array.
  • Fast appends. Adding a new element at the end of the array takes O(1) time.

Cons:

  • Fixed size. You need to specify how many elements you’re going to store in your array ahead of time.
  • Costly inserts and deletes. You have to shift the other elements to fill in or close gaps, which takes worst-case O(n) time.