• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedList

 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The elements in a LinkedList are doubly linked to each other? what does it mean?
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means each element has a reference to two other elements. The first one is the element before the current element and the second is the element after the current element...
 
Sanjeev Nair
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each element in the linked list will have three parts
First part stores the reference to previous element
Second stores the data
and
Third stores reference to next element

Such a linked list which stores reference of both previous and next element, at each element is known as a doubly linked list.
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is said because ArrayList is faster than LinkedList in traversal but ArrayList is very slow in insertion and deletion...
 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok..thanks...i got it.
 
Campbell Ritchie
Sheriff
Posts: 51366
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ankit Garg:
This is said because ArrayList is faster than LinkedList in traversal but ArrayList is very slow in insertion and deletion...


Bit of an exaggeration to say ArrayList is very slow in insertion and deletion. Slower than a LinkedList, yes, but not very slow.
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
Bit of an exaggeration to say ArrayList is very slow in insertion and deletion. Slower than a LinkedList, yes, but not very slow.


Yup. You are right. When we add or delete elements to it, then we don't even realize it.

But there is a reason why I said it. ArrayList is slower than LinkedList but HashMap is faster than LinkedHashMap in insertion and deletion. So in the beginning I used to get confused between these as one of the Linked collection is fast and one is slow. So I memorized it by thinking that ArrayList is very slow, Linked collections are fast but HashMap is ultra fast. So the statement came out of mind out of intuition ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic