Content deleted Content added
small typo, character should be Big Theta |
style - get the italics right |
||
Line 27:
====Asymptotic amortized worst-case analysis====
In this table, the [[asymptotic analysis|asymptotic]] [[big-O notation|notation ''O''(''f''(''n''))]] means "not exceeding some fixed multiple of ''f''(''n'') in the worst case."
{| class="wikitable"
Line 42:
|-
| Unsorted [[Array data structure|array]]
| [[Constant time|''O''(1)]]<br><sup>(see note)</sup>
|
| N/A
| ''O''(1)
| ''O''(''n'')
| ''O''(''n'')
| ''O''(''n'')
| ''O''(''n'')
|-
| [[Sorted array]]
| ''O''(''n'')
| ''O''(''n'')
| N/A
| ''O''(1)
| ''O''(log ''n'')
| ''O''(1)
| ''O''(1)
| ''O''(''n'')
|-
| Unsorted [[linked list]]
| ''O''(1)
| ''O''(1)<ref name="listdelete">{{cite book |title=Introduction to Algorithms |publisher=The College of Information Sciences and Technology at Penn State|isbn=9780262530910|authors=Cormen, Leiserson, Rivest|quote=LIST-DELETE runs in ''O''(1) time, but if we wish to delete an element with a given key, Θ(n) time is required in the worst case because we must first call LIST-SEARCH.}}</ref>
| N/A
| ''O''(''n'')
| ''O''(''n'')
| ''O''(''n'')
| ''O''(''n'')
| ''O''(''n'')
|-
| Sorted linked list
| ''O''(''n'')
| ''O''(1)<ref name="listdelete" />
| N/A
| ''O''(''n'')
| ''O''(''n'')
| ''O''(1)
| ''O''(1)
| ''O''(''n'')
|-
| [[Self-balancing binary tree]]
| ''O''(log ''n'')
| ''O''(log ''n'')
| ''O''(log ''n'')
| N/A
| ''O''(log ''n'')
| ''O''(log ''n'')
| ''O''(log ''n'')
| ''O''(''n'')
|-
| [[Heap (data structure)|Heap]]
| ''O''(log ''n'')
| ''O''(log ''n'')
| ''O''(log ''n'')
| N/A
| ''O''(''n'')
| ''O''(1)
| ''O''(''n'')
| ''O''(''n'')
|-
| [[Hash table]]
| ''O''(1)
| ''O''(1)
| ''O''(''n'')
| N/A
| ''O''(1)
| ''O''(''n'')
| ''O''(''n'')
| ''O''(''n'')
|-
| [[Trie]]
| ''O''(''m'')
| ''O''(''m'')
| N/A
| ''O''(''n'')
| ''O''(''m'')
| ''O''(''m'')
| ''O''(''m'')
| ''O''(''n'')
|}
''Note'': Insert on an unsorted array is sometimes quoted as being ''O''(''n'') due to the assumption that the element to be inserted must be inserted at one particular ___location of the array, which would require shifting all the subsequent elements by one position. However, in a classic array, the array is used to store arbitrary unsorted elements, and hence the exact position of any given element is of no consequence, and insert is carried out by increasing the array size by 1 and storing the element at the end of the array, which is a
This table is only an approximate summary; for each data structure there are special situations and variants that may lead to different costs. Also two or more data structures can be combined to obtain lower costs.
|