# Time Complexity of a Collection

Vivek Nidhi

Ranch Hand

Posts: 133

posted 11 years ago

Hi,

Can some tell what is this time complexity of a collection??.

what its value of Arraylist, Vector, LinkedList.

regs

Vivek Nidhi

Can some tell what is this time complexity of a collection??.

what its value of Arraylist, Vector, LinkedList.

regs

Vivek Nidhi

Ulf Dittmer

Rancher

Posts: 42970

73

jiju ka

Ranch Hand

Posts: 308

posted 11 years ago

Time Complexity is not something remaining constant throughout the universe. It varies with how (insert, lookup, iterate, clear etc) you use the collecton, what (application specific: to store shared or non shared resources, thread safe or non thread safe resources) you use the collection for and where(Implementation specific : batch, online, long continous use) you use it.

From http://en.wikipedia.org/wiki/Computational_complexity_theory

[ December 06, 2005: Message edited by: jiju ka ]

Can some tell what is this time complexity of a collection?.

what its value of Arraylist, Vector, LinkedList.

Time Complexity is not something remaining constant throughout the universe. It varies with how (insert, lookup, iterate, clear etc) you use the collecton, what (application specific: to store shared or non shared resources, thread safe or non thread safe resources) you use the collection for and where(Implementation specific : batch, online, long continous use) you use it.

From http://en.wikipedia.org/wiki/Computational_complexity_theory

The time complexity of a problem is the number of steps that it takes to solve an instance of the problem as a function of the size of the input (usually measured in bits), using the most efficient algorithm. To understand this intuitively, consider the example of an instance that is n bits long that can be solved in n� steps. In this example we say the problem has a time complexity of n�. Of course, the exact number of steps will depend on exactly what machine or language is being used. To avoid that problem, we generally use Big O notation. If a problem has time complexity O(n�) on one typical computer, then it will also have complexity O(n�) on most other computers, so this notation allows us to generalize away from the details of a particular computer.

[ December 06, 2005: Message edited by: jiju ka ]

posted 11 years ago

Going back to the original question, Vector is theoretically slower than ArrayList or LinkedList, since its synchronized, but I don't have metrics for this. Are you concerned with which is faster or worst case algorithm analysis?

[ December 06, 2005: Message edited by: Scott Selikoff ]

[ December 06, 2005: Message edited by: Scott Selikoff ]

[OCA 8 Book] [OCP 8 Book] [Blog] * SCJP (1.4, 1.6) * OCAJP 8 * OCPJP 8