Skip to main content
  1. /classes/
  2. Classes, Fall 2025/
  3. CS 2381 Fall 2025: Course Site/

cs2381 Notes: 11-24 Text Editor

·99 words·1 min·

Let’s try to design a data structure for a text editor.

Seems easy. A text file is just a String.

But…

  • Text files can get big.
  • Pretty much all common operations will end up being O(n).
  • And we’d like undo / redo without storing a copy of the whole file for each change.

What do we do?

Common operations:

  • Insert some text.
  • Delete some text.
  • Replace text (delete + insert?)
  • Cut / paste some text.
  • Copy / paste some text.
  • Line operations (insert, delete, replace, move lines)

How do we do this?

  • For extra fun, characters aren’t fixed width.
Nat Tuck
Author
Nat Tuck