liveBook · Manning

Sorted list

As explained in Advanced Algorithms and Data Structures

A sorted list is a sequence of elements maintained in an order that supports locating an element's position by comparison.

A sorted list maintains its elements in comparison order, making position-based lookup efficient. It suits small collections or workloads where insertion, removal, and modification are infrequent. section 2.3 section 4.4.2

For an array-backed sorted list, the main operations trade search speed against update cost:

  • Find an insertion position with binary search in O(log n), then shift subsequent elements; insertion takes O(n) on average. section 2.3
  • Look up an entry in O(log n) using binary search and use no extra memory. section 4.4.2
  • Add or remove an entry in O(n), because maintaining order can require many elements to change position. section 2.3 section 4.4.2

Alphabetical index

An alphabetical index lets you locate a rare word without scanning every page. Open near the expected position, compare the current entry, and continue before or after it—binary search in practice. section 4.4.2

Table 4.2 Using sorted arrays as dictionaries (view table figure)

Operation

Running time

Extra memory

Creating the structure

O(n*log(n))

O(n)

Looking up an entry

O(log(n))

No

Add a new entry

O(n)

No

Remove an entry

O(n)

No

Compare construction, lookup, insertion, removal, and memory costs for sorted arrays used as dictionaries. section 4.4.2

How Advanced Algorithms and Data Structures covers it

How deep it goes
Explains binary-search lookup and linear update costs, but stops short of implementation code or internal proofs.
Examples
Uses alphabetical indexes, phone books, and sorted arrays used as dictionaries.
What you can do after
Evaluate sorted-list suitability by comparing lookup speed against insertion, removal, memory, and collection-size costs.
How it connects
Contrasts sorted lists with unsorted arrays, balanced trees, heaps, priority queues, and binary search.

Also explained in

Compare how 3 books explain sorted list →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.