If your structure is trash, you ain’t gettin’ the cash
The mark of a good programmer is one who understands the tools and implements they have at their disposal and can use them effectively to engineer their code. And one of the most important tools that a programmer will use is the data structure. Here are five basic data structures that every programmer will need:
An array (or list) is the fundamental, most basic structure of storing values. Arrays are ordered by indexes, with the i-th index pointing to the i-th location plus the array’s starting location in the program’s memory.
This allows for fast search-up of an element in the array, but makes it hard to add elements (since the array can interfere with the memory locations of other parts of the program). Removing elements is also difficult because removing an element in the middle would mean changing the indexes of all elements after.
A linked list is a simpler version of an array. Each element stores its value and a pointer to the memory location of the next element.
This makes it extremely easy to modify the list. Adding an element in the middle of a linked list is just changing the pointer of the previous element and setting the element’s pointer to the following element. Subtracting an element is, similarly, just setting the previous element’s pointer directly to the following element. However, linked lists don’t have index access, so it’s more difficult to find the i-th element in the list.
Stacks and queues are like one-way arrays. A stack is like a stack of trays in a cafeteria. The last element added is the first one taken out (popped). A queue is like a line to checkout grocieres. The first element added is the first one removed.