r/learnprogramming • u/Temporary-Warthog250 • Apr 05 '22
Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them
Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.
Someone else who reads yours and does understand it, try to explain it to them to help them learn
1.6k
Upvotes
1
u/warlaan Apr 06 '22
Linked lists in the strictest sense yes, but the concept is not. For example if you are working on a potentially huge data set you would want an array for performance reasons, but with an array you would need to know in advance how large it must be.
If you have no way of knowing the size in advance you have a problem. You could use a vector (i.e. an array that is resized when it becomes too small), but if the data set is so large that you can't keep all of it in memory at the same time you still have a problem.
One easy solution is to use something in between linked lists and arrays by simply creating "liked arrays". You start with an array of a predefined size, and when it is filled up you append a link to a second array of the same size. That way you have (almost) the performance of arrays because you rarely need to make those "linked list jumps", but you also don't have the performance overhead of having to copy huge arrays when resizing that container, because now you can simple remove whole chunks from the linked list part.