|
|
|
|
|
by Matt3o12_
2909 days ago
|
|
A dynamic array has an average (armotized) time of O(1) but a worst case of O(n) – whenever your next insert is longer then the size of the list. Furthermore, it needs a lot of ram whenever copying elements.
A linked list is always O(1) and its ram usage is consistent (although not better – normally it is twice or three times as big). A linked list is basically only better on embedded systems because you have much better knowledge about the used ram/runtime. It’s also useful if you have a very large data structure and you need real time performance (a lag of a few hundred milliseconds are unacceptable for some applications such games or financial applications). But whenever your insert becomes too expensive, a linked list is probably not the best choice either and you should consider why your data structure is so big. Lastly a linked list is rather simple to implement but that’s also only really useful for embedded stuff. |
|