Swapna Kumar Panda
Swapna Kumar Panda

@swapnakpanda

14 Tweets 4 reads Jun 28, 2022
What is the difference between
➤ An Array
➤ A Linked List
Data Structures?
💭 Thoughts behind this Thread
⬘ These differences will make you grasp the fundamentals of both Array and Linked List really quick.
⬙ And, if you are preparing for any interviews, it would definitely help you.
Let's explore 👇
We will discuss differences about
➊ Storage
➋ Size
➌ Access to Elements
➍ Insertion/Deletion of Elements
➎ Search for Elements
➏ Memory Allocation
➐ Memory Usage
➑ Memory Utilisation
➒ Use case
➊ Storage
⬘ Array
Elements are stored consecutively in contiguous memory locations.
⬙ Linked List
Elements are mostly stored in random memory locations. Each element stores the address of the next element.
➋ Size
⬘ Array
The size of an Array depends upon the implementation. But by default, it's static and declared during memory allocation.
⬙ Linked List
The size of a Linked List is not fixed. Linked Lists can grow and shrink after each element insertion/deletion.
➌ Access to Elements
⬘ Array
Access is direct. Elements are accessed using the index. Time Complexity is O(1).
⬙ Linked List
Access is sequential. Traversal always happens from the beginning. Time Complexity is O(n).
➍ Insertion/Deletion of Elements
⬘ Array
It is slower as space has to be made by shifting existing elements. Time Complexity is O(n).
⬙ Linked List
It is faster, easier and more efficient. No need to shift elements, only pointer values are changed. Time Complexity is O(1).
➎ Search for Elements
⬘ Array
Both linear [O(n)] and binary search [O(log n)] can be performed. If elements are sorted, binary search is too efficient.
⬙ Linked List
Only linear search is efficient [O(n)]. The binary search takes even more time [O(n log n)].
➏ Memory Allocation
⬘ Array
For static-sized arrays, memory is allocated ahead of time whereas, for dynamic-sized arrays, new memory is allocated at runtime only.
⬙ Linked List
Memory for an element of a Linked List is allocated as and when it is inserted.
➐ Memory Usage
⬘ Array
It requires less usage of memory as only values are stored.
⬙ Linked List
It requires high usage of memory as every element stores both value and pointer to the next element.
➑ Memory Utilisation
⬘ Array
High and ineffective. Because the array is allocated the entire "size" of memory even if zero or only 1 element is to be stored.
⬙ Linked List
Very efficient. Memory is allocated for only existing elements.
➒ Use case
⬘ Array
Use an array when elements need to be
❍ accessed randomly
❍ in a fast manner
⬙ Linked List
Use a linked list when
❍ memory utilisation is of high importance
❍ sequential access of elements is fine
👩‍💻 Practice 200+ Problems
You need to practice a lot of problems to be familiarised with a programming language.
I have curated 200+ problems for your practice. Grab this ebook now!!!
swapnakpanda.gumroad.com
Hey 👋
I am a Tech Educator and, Mentor from India 🇮🇳
I am sharing Tutorials, Tricks, Infographics, Cheat Sheets, Practice Questions, Project Ideas and Roadmaps on Web Development, DSA and, Databases.
To never miss anything, Follow Me ✅

Loading suggestions...