How does a text editor works on a local machine?
Naive Approach: Using a String You could treat the document as one big string and insert/delete characters by creating new strings each time. But many languages make strings immutable , so every modification creates a new string → slow, memory-inefficient, causes fragmentation. Better Approach: Array of Characters Represent text as an array: Adding/removing at the end = fast Overwriting = fast But inserting in the middle = slow , because you must shift all following characters by one position. With large documents (thousands/millions of characters), this becomes extremely inefficient. Can we use linked lists or more accurately doubly linked lists? Idea: represent each character as a node in a linked list. Pros: Easy insert/delete in the middle (just adjust pointers) Cons: Massive memory overhead: Each character = 1 byte Pointer(s) = 8–16 bytes → Text becomes 17x larger in memory Not cache-friendly Slow for random access Hybrid ap...