As I understand BASIC had line numbers because at the time you had to use a line editor to input your program. It allowed you to do something like this:
20 END
10 PRINT "HELLO WORLD"
This program would print "HELLO WORLD". My question is how did BASIC allow you to enter lines this way? How were they stored in memory? I suppose it was a map of line numbers and pointers to lines themselves which was updated every time you input a line. But this map would have to be sorted before running a LIST/RUN command. Is that so? If not then how exactly did BASIC store commands in the memory?