Summary of functions and complexity of common data structures

Source: Internet
Author: User

Indefinite long array

Maintain a sequence

At the end insert/remove the averaging O (1)

Insert O (n) at any position

Specify location query/modify O (1)

Space O (N)

Linked list

Maintain a sequence

Positioning to position I O (n)

Insert/delete/modify O (1) at any location (positioned to this location)

Space O (N)

Hash table

Maintaining the existence of key-value correspondence or maintenance keys

1. Open addressing method hash list

If the number of inserted keys is less than 3/4 of the table size can be considered to query/modify/Insert expected O (1), the worst O (n) if the correct choice of hash function is generally not appear

Delete can only be flagged for deletion

Generally, the required space should be greater than 4/3 of the maximum number of keys to ensure efficiency

2. Chain hashing Hash List

If the table in the number of keys a, table size n, then query/modify/insert/delete the desired O (1+a/n), the worst O (n) if the correct choice of hash function is generally not appear

If necessary, you can use the balance tree instead of the linked list to do the worst O (logn) But the practical value is not very

and check Set

Maintains a number of elements and whether they are homogeneous (transitive) between 22 and supports the class of two elements belonging to the same category

1. And the forest realization of the search set

Merge by rank + path compression query/merge averaging O (α (n))

Single operation guaranteed O (LOGN) only by rank combined

Only path compression one-time operation guaranteed O (LOGN)

2. The linked list implementation of the check set

Query/merge averaging O (Logn)

Support for traversing a collection of elements

Tree-like array

Maintain a sequence

Set sequence length n, operation number m

Modifies the value of the specified position element O (logn)

The and O (logn) of the specified interval elements

Promote:

The value of the element is queried by maintaining the difference by adding the specified value to the O (logn) interval

The prefix and the maintenance of any operation that satisfies the interval addition

The interval and the operation of the interval method are maintained.

K-Dimensional Promotion:

Space O (NK), using the hash list dynamic open point can be done O (MLOGKN)

One-time modification of/k and O (LOGKN)

Balance Tree

Maintain a monotone sequence

Pre-query/insert/delete O (logn)

Can support O (logn) query rank/number of elements less than k after maintaining size

Do not maintain sequence monotonicity and only maintain normal sequence can support O (logn) specify location Insert/delete/query

Splay allows for interval rollover but all operations are equally complex

The rules of the segment tree can be used to maintain interval information

Segment Tree

Maintain interval information for a sequence

can support single point/interval modification/query, general single operation O (Logn), required to maintain the information to meet the interval addition

Promote:

Using rules like the balance tree to insert/delete O (logn) at a specified location

Heap

Maintain some unordered elements

Query min/insert element/delete min O (logn)

(positioned to the specified element) increases/decreases the value of the specified element O (logn) (Fibonacci heaps for averaging O (1))

Can be combined with a heap to support O (LOGN) merging

St Table

Maintain a sequence

Build time Space is O (NLOGN)

Query Interval max O (1)

The maximum value can be swapped for any other value that can be valued out of a range of two intervals.

Block Linked list

Maintain a sequence

Specify location query/modify/insert/delete/interval flip/interval query/Interval modification O (n0.5)

k-d Tree

Maintaining point k>1 in K-dimensional space

Build O (Knlogn)

Space O (N)

Insert O (LOGN)

Query/modify (specify interval per dimension) Information O (n0.5)

Query nearest/Furthest point O (n0.5)

Data structures that can be persisted

The original data structure has a strict space-time complexity, it can be persisted can still guarantee the complexity

Wakahara data structures are linear data structures and complexity is multiplied by the previous Logn

The general space inevitably increases logn or greater per operation, but does not exceed the complexity of time

Averaging complexity is generally degraded after it is persisted

The data structure tree promotes

The tree chain can be used to decompose the invariant tree into a chain for maintenance, and the complexity is the original data structure multiplication Logn

If the information matches the interval subtraction of the unchanging tree, it can be maintained by DFS sequence, and the complexity is the same as the original data structure.

Link-cut tree can support simple modification operations in the form of trees, with a general complexity of averaging O (LOGN)

Point Division/Edge Division governance can also be used to maintain data structures

Summary of functions and complexity of common data structures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.