GSLC Data Structure
GSLC DATA STRUCTURES
M. Daffa Syamsuddin
(2301957603
Linked list is a linear collection of data elements, whose order is
not given by their physical placement in memory. Instead, each element points to the next. It is a data
structure consisting of a
collection of nodes which together represent a sequence.
Why Linked
List?
Arrays can be
used to store linear data of similar types, but arrays have the following
limitations.
1) The size of
the arrays is fixed: So we must know the upper limit on the number of elements
in advance. Also, generally, the allocated memory is equal to the upper limit
irrespective of the usage.
2) Inserting a
new element in an array of elements is expensive because the room has to be
created for the new elements and to create room existing elements have to be
shifted.
A
linked list is a dynamic data structure. The number of nodes in a list is not
fixed and can grow and shrink on demand. Any application which has to deal with
an unknown number of objects will need to use a linked list.
One disadvantage of a linked list
against an array is that it does not allow direct access to the individual
elements. If you want to access a particular item then you have to start at the
head and follow the references until you get to that item.
Another disadvantage is that a
linked list uses more memory compare with an array - we extra 4 bytes (on
32-bit CPU) to store a reference to the next node.
Singly linked
lists contain nodes which have a data field as well as 'next' field, which
points to the next node in line of nodes. Operations that can be performed on
singly linked lists include insertion, deletion and traversal.
In a 'doubly
linked list', each node contains, besides the next-node link, a second link
field pointing to the 'previous' node in the sequence. The two links may be
called 'forward('s') and 'backwards', or 'next' and 'prev'('previous').
Source:
https://www.cs.cmu.edu/~adamchik/15-121/lectures/Linked%20Lists/linked%20lists.html
Komentar
Posting Komentar