Lam Nguyen

Lam Nguyen

Lam Nguyen

November 29, 2023

 • 1 min read

0

Linked Lists vs. Arrays

Let's put the two data structures against each other to find out which is more efficient.

dsa-array-vs-linked-list

Linked List vs. Arrays

Memory Allocation

  • Arrays: takes all space even if it doesn’t contain any element yet
  • Linked List: only takes the portion of the space as it uses

Insertion and Deletion

  • Linked List: constant time O(1) for deleting at head.
  • Array: O(n) time because you have to traverse and shift the array elements left or right.

Search:

  • Array: takes constant time O(1) for searching/access the index
  • Linked List: O(n) because you have to traverse the list from start to end to search for the element

Summary the performace between linked lists and arrays


OperationLinked ListArray
AccessO(n)O(1)
Insert (at head)O(1)O(n)
Delete (at head)O(1)O(n)
Insert (at tail)O(n)O(n)
Delete (at tail)O(n)O(n)

Thank you for reading! Happy coding!

Topics

JavaDSA

More stories

Dec, 2023 • 3 min read

Singly Linked List with Python

ll-python

Oct, 2023 • 2 min read

Project Issue Tracker NextJS Full Stack Project

issue-tracker-cover

Social media

avatar

GitHub

0 followers

Follow
avatar

LinkedIn

438 followers

Follow
avatar

Instagram

410 followers

Follow
avatar

Medium

23 followers

Follow
avatar

Twitter

49 followers

Follow