Language: EN

eficiencia-de-colecciones-en-programacion

Comparison of collection efficiency

The efficiency of a collection refers to its ability to perform operations quickly and efficiently, minimizing the time and resources used.

When evaluating the efficiency of a collection, it is important to consider the execution time of key operations (such as reading, inserting, deleting, and searching for elements).

These operations vary depending on the type of collection and its internal implementation.

Efficiency Comparison Table

Let’s take a look at a summary table of the efficiencies of the collections we have seen in the course, regarding different operations:

OperationArrayListLinkedListStackQueueSetDict
Sequential access🟢🟢🟢
Random access🟢🟢🔴🟢🟢
Add to beginning🔴🟢🟢
Remove from beginning🔴🟢
Add to end🟢🟡🟢🟢
Remove from end🟢🟢🟢🟢🟢
Random insertion🔴🟢🟡🟡
Random removal🔴🟢🟢🟢
Search🔴🔴🔴🟢🟢

Where the meaning of each symbol is,

  • 🟢O(1): Constant execution time.
  • 🟡O(1)-O(n): Constant execution time in the best case, but linear in the worst case.
  • 🔴O(n): Linear execution time, proportional to the size of the collection.
  • ⚫N/A: The operation is not applicable or does not make sense for that particular collection.

Description of Operations

Here is a description of each of the operations mentioned in the table:

  1. Sequential access: Refers to the ability to access the elements of the collection in sequence, one after the other, regardless of their position.

  2. Random access: Means the ability to directly access an element at a specific position in the collection, without needing to sequentially traverse from the beginning.

  3. Add to beginning: The operation of adding a new element to the beginning of the collection.

  4. Remove from beginning: The operation of removing the first element from the collection.

  5. Add to end: Adding a new element to the end of the collection.

  6. Remove from end: Refers to the operation of removing the last element of the collection.

  7. Random insertion: Means adding a new element at an arbitrary position in the collection.

  8. Random removal: The operation of removing an element at an arbitrary position in the collection.

  9. Search: Means finding a specific element in the collection.