Array&Linked List
Array&Linked List
Technology
Array
• Arrays are defined as the collection of
similar type of data items stored at
contiguous memory locations.
• Arrays are the derived data type in C
programming language which can store
the primitive type of data such as int,
char, double, float, etc.
• Array is the simplest data structure where
each data element can be randomly
accessed by using its index number.
Amity School of Engineering &
Technology
Space Complexity
In array, space complexity is O(n).
Amity School of Engineering &
Technology
Advantages of Array
• Array provides the single name for the
group of variables of the same type
therefore, it is easy to remember the name
of all the elements of an array.
• Traversing an array is a very simple
process, we just need to increment the
base address of the array in order to visit
each element one by one.
• Any element in the array can be directly
accessed by using the index.
Amity School of Engineering &
Technology
Amity School of Engineering &
Technology
int arr[max_rows][max_columns];
Amity School of Engineering &
Technology
Amity School of Engineering &
Technology
Mapping 2D array to 1D array
When it comes to map a 2 dimensional
array, most of us might think that why this
mapping is required. However, 2 D arrays
exists from the user point of view. 2D arrays
are created to implement a relational
database table lookalike data structure, in
computer memory, the storage technique for
2D array is similar to that of an one
dimensional array.
Amity School of Engineering &
Technology
• Answer- 210
Amity School of Engineering &
Technology
• Answer- 157
Amity School of Engineering &
Technology
Sparse Matrix
A matrix can be defined as a two-
dimensional array having 'm' columns and 'n'
rows representing n*m matrix. Sparse
matrices are those matrices that have the
majority of their elements equal to zero. In
other words, the sparse matrix can be
defined as the matrix that has a greater
number of zero elements than the non-zero
elements.
Amity School of Engineering &
Technology
Why do we need to use a sparse matrix
instead of a simple matrix?
We can also use the simple matrix to store
the elements in the memory; then why do
we need to use the sparse matrix. The
following are the advantages of using a
sparse matrix:
• Storage: As we know, a sparse matrix that
contains lesser non-zero elements than
zero so less memory can be used to store
elements. It evaluates only the non-zero
elements.
Amity School of Engineering &
Technology
Linked List
A linked list is also a collection of elements,
but the elements are not stored in a
consecutive location. A linked list can also
be defined as the collection of the nodes
in which one node is connected to
another node, and node consists of two
parts, i.e., one is the data part and the
second one is the address part.
Amity School of Engineering &
Technology
Memory efficient
Its memory consumption is efficient as the
size of the linked list can grow or shrink
according to our requirements.
Amity School of Engineering &
Technology
• Traversal
In a linked list, the traversal is not easy. If
we want to access the element in a linked
list, we cannot access the element
randomly, but in the case of an array, we
can randomly access the element by
index.
Amity School of Engineering &
Technology
• Reverse traversing
In a linked list, backtracking or reverse
traversing is difficult. In a doubly linked list,
it is easier but requires more memory to
store the back pointer.
Amity School of Engineering &
Technology
Applications of Linked List
With the help of a linked list, the polynomials
can be represented as well as we can
perform the operations on the polynomial.
We know that polynomial is a collection of
terms in which each term contains
coefficient and power. The coefficients and
power of each term are stored as node and
link pointer points to the next element in a
linked list, so linked list can be used to
create, delete and display the polynomial.
Amity School of Engineering &
Technology