Content deleted Content added
Sheep8144402 (talk | contribs) fix linter error (1x missing end tag) Tags: Mobile edit Mobile web edit Advanced mobile edit |
m v2.05b - Bot T5 CW#16 - Fix errors for CW project (Unicode control characters) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1:
In [[computer science]], a '''search data structure'''{{citation needed|date=May 2016}} is any [[data structure]] that allows the efficient [[data retrieval|retrieval]] of specific items from a [[set (mathematics)|set]] of items, such as a specific [[record (computer science)|record]] from a [[database]].
The simplest, most general, and least efficient search structure is merely an unordered sequential [[list (computing)|list]] of all the items. Locating the desired item in such a list, by the [[linear search]] method, inevitably requires a number of operations proportional to the number ''n'' of items, in the [[worst case complexity|worst case]] as well as in the [[average case complexity|average case]]. Useful search data structures allow faster retrieval; however, they are limited to queries of some specific kind. Moreover, since the cost of building such structures is at least proportional to ''n'', they only pay off if several queries are to be performed on the same database (or on a database that changes little between queries).
'''Static''' search structures are designed for answering many [[Information retrieval|queries]] on a fixed database; '''dynamic''' structures also allow insertion, deletion, or [[Update (SQL)|modification]] of items between successive queries. In the dynamic case, one must also consider the cost of fixing the search structure to account for the changes in the database.
==Classification==
Line 40:
|-
| Unsorted [[Array data structure|array]]
| [[Constant time|''O''(1)]]<br /><sup>(see note)</sup>
| ''O''(1)<br /><sup>(see note)</sup>
| N/A
| ''O''(1)
Line 81:
| 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=
| N/A
| ''O''(''n'')
Line 125:
| N/A
| ''O''(''n'')
| ''O''(1) for a ''min-heap''<br />''O''(''n'') for a ''max-heap''<ref name="heap">{{cite book |title=Introduction to Algorithms|publisher=The College of Information Sciences and Technology at Penn State|isbn=
| ''O''(1) for a ''max-heap''<br />''O''(''n'') for a ''min-heap''<ref name="heap" />
| ''O''(''n'')
|-
Line 210:
|}
''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 ''O''(1) operation.<ref name="games">{{cite book|isbn=
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.
|