Skip to main content

Command Palette

Search for a command to run...

#12: Elixir Lists - Performance Considerations

Published
2 min readView as Markdown
#12: Elixir Lists - Performance Considerations
S

I am a full-stack developer from Austria who has studied and worked in many countries including the UK, Australia, and the US. I have worked extensively with Ruby on Rails, React, and Typescript, and I am also building projects using Elixir and Phoenix.

In this short post, I wanted to briefly touch on some performance considerations when using lists in Elixir. In particular, the performance of adding, removing elements, and determining the size of the list can be explained in terms of Big O Notation:

  1. Adding Elements:

    Adding an element to the beginning of a linked list in Elixir has a time complexity of O(1) (constant time). This is because adding an element to the head of the list involves creating a new node and updating the reference to the current head, which can be done in constant time regardless of the size of the list.

  2. Removing Elements:

    Removing an element from the beginning of a linked list in Elixir also has a time complexity of O(1) (constant time). Similar to adding elements, removing an element from the head of the list involves updating the reference to the head, which can be done in constant time.

  3. Determining the Length:

    Determining the length of a linked list in Elixir has a time complexity of O(n) (linear time). This is because to determine the size of the list, you need to traverse the entire list from the head to the end, counting each element along the way. As the size of the list grows, the time taken to determine the size increases linearly with the number of elements in the list.

In summary:

  • Adding and removing elements at the beginning of a linked list in Elixir have a time complexity of O(1) due to the efficient nature of linked lists for these operations.

  • Determining the size of a linked list in Elixir has a time complexity of O(n) as it requires traversing the entire list to count the elements.

Understanding the performance characteristics of these operations in terms of Big O Notation can help in designing efficient algorithms and data structures when working with linked lists in Elixir.

More from this blog

Stephan Yu's Tech Journal

28 posts

This is my space for writing about tech-related topics that I find interesting. It allows me to share the things I have learned with the world.