Skip to main content

List

Overview

A List is an abstract data type (ADT) that represents an ordered collection of elements. Elements maintain a specific sequence, and duplicates are usually allowed.

Lists define what operations are possible, not how they are implemented.


What Is a List?

A list:

  • Preserves insertion order
  • Allows positional access
  • Can grow or shrink dynamically
  • May allow duplicate elements

Concrete implementations include array lists and linked lists.


Core List Operations

OperationDescription
InsertAdd element at a position
DeleteRemove element
AccessGet element by index
UpdateModify element
SearchFind element
TraverseIterate through list

How It Works

As an ADT:

  • The list specifies behavior
  • Implementation decides performance
  • Indexing is conceptual, not guaranteed efficient

Example

Pseudocode

list.add(10)
list.add(20)
list.addAt(1, 15)

print(list[1]) // 15

Real-world Analogy

A list is like a playlist. Order matters, repeats are fine, and you can insert a song anywhere 🎶.

Time Complexity (Typical)

OperationArray ListLinked List
AccessO(1)O(n)
InsertO(n)O(1)*
DeleteO(n)O(1)*

* When position is known.


Use Cases

  • Collections frameworks
  • Sequential data storage
  • Task queues
  • History tracking

Advantages

  • Ordered data
  • Flexible size
  • Simple abstraction

Limitations

  • Random access not guaranteed
  • Performance varies by implementation
  • Not optimized for key-based lookup