Find a common data structure, insert, delete time complexity

 

                    Find insert delete

Number 组 o (n) o (1) o (n)

An ordered array of o (lgn) o (n) o (n)

链表 o (n) o (1) o (n)

Ordered list o (n) o (n) o (n)

Binary worst o (n) o (n) o (n)

General binary o (lgn) o (lgn) o (lgn)

Flat 衡树 o (lgn) o (lgn) o (lgn)

Hash table o (1) o (1) o (1)

 

(1) is inserted into an ordered array of time complexity of a number is how much?

Lookup to find the insertion position is traversed if O (n), with binary lookup is O (log2n).

However, the need to insert the array element after the insertion position of a shift after all, this requires O (n).

Therefore, the overall time complexity of O (n). (O (n) + O (n) = O (n), O (log2n) + O (n) = O (n))

(2) an ordered list of time to find what is the reason of the complexity of O (n) is?

For binary search on a linked list can not achieve O (logN) efficiency. When the time is only one element in the collection is any constant O (1) time, in order to achieve binary search O (logN), where the average time to access the list of elements is O (N) time i.e. linear. With a collection of binary search in order to use the array structure.

Guess you like

Origin www.cnblogs.com/fengff/p/11008721.html