August 2020
Intermediate to advanced
508 pages
11h 53m
English
After our analysis, it emerges that the comparison of linked lists and arrays breaks down as follows:
Operation | Array | Linked list |
|---|---|---|
Reading | O(1) | O(N) |
Search | O(N) | O(N) |
Insertion | O(N) (O(1) at end) | O(N) (O(1) at beginning) |
Deletion | O(N) (O(1) at end) | O(N) (O(1) at beginning) |
In the grand scheme of things, linked lists seem to be lackluster when it comes to time complexity. They perform similarly to arrays for search, insertion, and deletion, and are much slower when it comes to reading. If so, why would one ever want to use a linked list?
The key to unlocking the linked list’s power is in the fact that the actual insertion and deletion steps are just O(1).
But isn’t that only relevant when inserting or deleting at the beginning ...
Read now
Unlock full access