. NET Collection Type performance analysis

Source: Internet
Author: User

Collection

Add

Insert

Remove

Item

Sort

Find

List<t>

If the collection resets size, it is O (1) or o (n)

O (N)

O (N)

O (1)

O (n log n), worst case O (n^2)

Stack<t>

Push (), if the stack must be reset size, is O (1) or o (n)

N/A

Pop,o (1)

N/A

N/A

N/A

Queue<t>

Enqueue (), if the queue must be reset size, is O (1) or o (n)

N/A

Dequeue,o (1)

N/A

N/A

N/A

Hasset<t>

If the size must be reset, it is O (1) or o (n)

Add (), O (1) or o (n)

O (1)

N/A

N/A

N/A

Sortedset<t>

If the size must be reset, it is O (1) or o (n)

Add (), O (1) or o (n)

O (1)

N/A

N/A

N/A

Linkedlist<t>

AddLast (), O (1)

Addafter (), O (1)

O (1)

N/A

N/A

O (N)

Dictionary<tkey,tvalue)

O (1) or o (n)

N/A

O (1)

O (1)

N/A

N/A

Sorteddictionary<tkey,tvalue)

O (log n)

N/A

O (log n)

O (log n)

N/A

N/A

Sortedlist<tkey,tvalue)

Unordered data is O (n); If the size must be reset to O (n), the tail of the list is O (log n)

N/A

O (N)

Read/write is O (log n); If the key is in the list, O (log n),if the key is not in the list O (n)

N/A

N/A

Note:

O (1) indicates that the time required for this operation is constant regardless of the number of data items in the collection.

O (n) indicates that the time required to perform an operation on the collection is n in the worst case , indicating a linear increase as the element increases.

O (log n) indicates that the time required for the operation increases with the increase of the elements in the collection, but the increment time required for each element is not linear, but is a pair of curves.

. NET Collection Type performance analysis

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.