Hello everybody, I'm Aya Bouchiha, on this amazing day, we'll talk about the difference between array and linked list.
The array is a collection of elements stored at contiguous memory of a similar data type.
- Array elements are stored in a contiguous block of memory
- fixed size
- accessing directly a specific element O(1)
- slow when performing delete and insert operations.
- fast when it comes to finding an element (binary search)
- one-dimensional array
- two-dimensional array
- multidimensional array
A linked list is a linear data structure, in which the elements are linked using pointers, additionally, they are not stored at contiguous memory locations. A Linked List consists of Nodes that contain value ( data ) and a pointer to the next node in the chain. The head pointer points to the first node if the list is not empty, and the last element of the list points to null.
- Linked List elements are stored randomly.
- dynamic size
- for accessing an element we need to pass all linked list elements that are preceded by the specified element O(n)
- faster than array when It comes to performing insert and deletes operations.
- take more extra space to store node pointers
for more information about linked lists like the time and space complexity, Linked list's advantages and disadvantages, implementation
- Singly Linked List
- Doubly Linked List
- Circular Linked List