Chapter 6 · Simulation

List ADT Simulator

← Chapter 6

Array-based storage

Linked storage

Ready.

List ADT Simulator

Every operation runs on two implementations at once: an array-based list (like ArrayList) and a singly linked list with head and tail references (like LinkedList). The step counters show how much work each one does.

How to use it

  • Value and Index are the arguments. Add Last appends, Add First inserts at index 0, and Add at Index inserts at the given index.
  • Get reads the element at an index and Remove deletes it; Search finds the first occurrence of the value, and Traverse visits every element.
  • Sample and Random fill the list (at most 8 elements), Clear empties it, and Cancel stops a running animation.

Notes

  • The array reaches any index directly, but inserting or removing in the middle shifts every element after it.
  • The linked list has to walk from the head to reach an index; once there, it changes only a couple of references.

Complexity

OperationArray-based listLinked list
access(i)O(1)O(i)
add lastO(1) amortizedO(1) with tail
add firstO(n)O(1)
add / remove at index iO(n − i)O(i)
search, traversalO(n)O(n)