Skip to main content

Time Complexity Cheat Sheet

HashMap

  • Access: O(1)
  • Search: O(n)
  • Insert: O(1)
  • Remove: O(1)

HashSet

  • Access: O(1)
  • Search: O(1)
  • Insert: O(1)
  • Remove: O(1)

ArrayList

  • Access: O(1)
  • Search: O(n)
  • Insert: O(1) (at the back of the ArrayList)
  • Remove: O(n)
  • Sort: O(nlog(n))

Heap

  • Access Max / Min: O(1)
  • Insert: O(log(n))
  • Remove Max / Min: O(log(n))

Queue

  • Access: O(n)
  • Search: O(n)
  • Insert: O(1)
  • Remove: O(1)

Stack

  • Access: O(n)
  • Search: O(n)
  • Insert: O(1)
  • Remove: O(1)

Linked List

  • Access: O(n)
  • Search: O(n)
  • Insert: O(1)
  • Remove: O(1)