Choosing data structures
With this many data structures to choose from, it can be hard to know which one to choose during a specific problem. There are some rules to follow, and here is a short summary of the main characteristics of the individual data structures.
Arrays
Arrays are efficient if you have to know the size of the collection beforehand. That means the size is fixed, and if you want to change the size, you have to create a new array and copy the elements over. On the other hand, random access is very fast; it can be done in constant time.
Lists
Lists are implemented using linked lists, which are items linked together using pointers. This means that traversing a linked list is not super-efficient, because a lot of pointers have to be followed. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access