There is no summary available of the big O notation for operations on the most common data structures including arrays, linked lists, hash tables etc.
If you don't know the location, then you need to traverse the list to the location of deletion/insertion, which takes O(n) time. ** The deletion cost is O(log n) for the minimum or maximum, O(n) for an arbitrary element.
Deleting an element from an array takes O(n) time even if we are given index of the element to be deleted. The time complexity remains O(n) for sorted arrays as well. In linked list, if we know the pointer to the previous node of the node to be deleted, we can do deletion in O(1) time.
Information on this topic is now available on Wikipedia at: Search data structure
+----------------------+----------+------------+----------+--------------+ | | Insert | Delete | Search | Space Usage | +----------------------+----------+------------+----------+--------------+ | Unsorted array | O(1) | O(1) | O(n) | O(n) | | Value-indexed array | O(1) | O(1) | O(1) | O(n) | | Sorted array | O(n) | O(n) | O(log n) | O(n) | | Unsorted linked list | O(1)* | O(1)* | O(n) | O(n) | | Sorted linked list | O(n)* | O(1)* | O(n) | O(n) | | Balanced binary tree | O(log n) | O(log n) | O(log n) | O(n) | | Heap | O(log n) | O(log n)** | O(n) | O(n) | | Hash table | O(1) | O(1) | O(1) | O(n) | +----------------------+----------+------------+----------+--------------+ * The cost to add or delete an element into a known location in the list (i.e. if you have an iterator to the location) is O(1). If you don't know the location, then you need to traverse the list to the location of deletion/insertion, which takes O(n) time. ** The deletion cost is O(log n) for the minimum or maximum, O(n) for an arbitrary element.
I guess I will start you off with the time complexity of a linked list:
Indexing---->O(n)
Inserting / Deleting at end---->O(1) or O(n)
Inserting / Deleting in middle--->O(1) with iterator O(n) with out
The time complexity for the Inserting at the end depends if you have the location of the last node, if you do, it would be O(1) other wise you will have to search through the linked list and the time complexity would jump to O(n).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With