Java Collection Question - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Java Collection Question (762 Views)
| Java Collection Question by mludwig01(op): 9:27pm On May 25, 2010 |
When talking about Java Collections: - How long does it take to add an element to : * a map * a list - How long does it take to find an element from: * list * array * sorted list * sorted array * tree * hashmap - How long does it take to sort a list of n elements ***I'm new to technology so thank you so much for your answers/help and thanks for bearing with me!*** |
| Re: Java Collection Question by logica(m): 11:12pm On May 25, 2010 |
Why don't you write a program to check all these? |
| Re: Java Collection Question by candylips(m): 1:29pm On May 26, 2010 |
The time taken is related to their relative complexity - How long does it take to add an element to : * a map - constant * a list - constant - How long does it take to find an element from: * list - depends on the algorithm . . binary search or linear search * array - same as list * sorted list - linear if u do a linear search. But binary search is faster * sorted array - as as sorted list * tree - quadratic * hashmap - constant - How long does it take to sort a list of n elements Depends on the sort algorithm you use. Quick or Merge sort are usually the fastest So if you are concerned about speed the best datastructure to use is a Hashmap/Hashtable (although they are not suitable for most uses) because they are the fastest for addition and retreival of elements |
| Re: Java Collection Question by Seun(mod): 3:14pm On Jun 01, 2010 |
What program do you have in mind? |
Laravel:call To Undefined Method Illuminate\database\eloquent\collection::save() • Collection Of Nigerian Programming Gurus • 2 • 3 • 4
I Need A Tutor In Web Design And Other Related Programme In Lagos. • HTML 5 Canvas Aminations • What Are The Basic Features Of Java Programming Language