• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Question from Devaka's Practice 1

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q10 of 72

We need to select 4 true options among 6-7 options on LinkedList. In which the following is one. I selected this one as Vector is syncronized and so LinkedList is more faster than Vector

option : LinkedList provides a fast iteration speed, than [b]Vector [/b]#1

In the above option if it is a [b]ArrayList [/b]instead of [b]Vector[/b], I would not have selected --> LinkedList provides a fast iteration speed than [b]ArrayList[/b]
because According to K&B, it says LinkedList may iterate more slowly than an ArrayList, but it's a good choice when you need fast insertion and deletion.

In his explanation, he said LinkedList has the faster iteration speed than other List classes. as below.

LinkedList is an ordered, unsorted List.
It also implements the Queue interface.
LinkedList has the faster iteration speed than othr List classes, because it has // is it a mistake??? or am I missing something
a doubled-link, and methods of LL is not synchronized(thread-unsafed)


What is right now?


 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think LinkedList has faster insertion and deletion, because you don't need to shift elements in memory. But has slower access time, because you need to traverse the links to access any single element, whereas ArrayList and Vector elements are accessed in constant time, since the offset to access any element can be calculated based on the index.
 
Mahi Mohana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Ruben

Well, thanks for the reason why a LinkedList is slower than ArrayList. Yes, I remember LinkedList has a slower iteration than ArrayList according to K&B.

Then it must be a mistake in that examlab explanation.

I just want to make sure before I go for exam.

Thanks
Hima
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hima,

Better wait for some confirmation from other sources, but I think ArrayList has faster access. I think iteration will be faster also, because iteration involves the access of consecutive elements. In the case of the ArrayList or Vector you can just use increasing indexes directly, but with the LinkedList you still need to perform more expensive operations (you need to read the reference for the next object) which should be slower. Let's see if someone can confirm.
 
Ranch Hand
Posts: 179
Mac Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would go with array list being faster than linked list.
I think this will give is a more clear idea.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question is: Faster for what? I think it is faster for access, but slower for insertion and removal, especially when you have a lot of elements.

That's a nice link, thanks.
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ruben Soto wrote:I think LinkedList has faster insertion and deletion, because you don't need to shift elements in memory. But has slower access time, because you need to traverse the links to access any single element, whereas ArrayList and Vector elements are accessed in constant time, since the offset to access any element can be calculated based on the index.



I think you are right here Ruben, It must be mistake in Devaka Examlab. Let Devaka see this post.
 
Mahi Mohana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone, yes Ravi its a good link to review..

But I am running short of time to go through that as tommorow is my exam date for SCJP 065.

Regards
Hima





 
Ravikanth kolli
Ranch Hand
Posts: 179
Mac Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
all the best for your exam
 
Mahi Mohana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ravi.. Let you guys know tommorrow
 
Marshal
Posts: 7266
1397
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Punit Singh wrote:

Ruben Soto wrote:I think LinkedList has faster insertion and deletion, because you don't need to shift elements in memory. But has slower access time, because you need to traverse the links to access any single element, whereas ArrayList and Vector elements are accessed in constant time, since the offset to access any element can be calculated based on the index.



I think you are right here Ruben, It must be mistake in Devaka Examlab. Let Devaka see this post.




Yep! will be corrected as soon as possible.

Thanks,

Devaka
 
Dinner will be steamed monkey heads with a side of tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic