A data structure in computer science is a system used to store data, keep it organized, and enable easy modification and access. Put simply, a data structure refers to a group of data values, how they relate to each other, and the operations or functions that can be carried out on them.
Once you learn data structures, you’ll have an easier time learning different programming languages as you’ll have a solid base understanding to work from. Understanding the following most common data structures and how they work is the first step.
A hash table (hash map) is a data structure which implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
Ideally, the hash function will assign each key to a unique bucket, but most hash table designs employ an imperfect hash function, which might cause hash collisions where the hash function generates the same index for more than one key. Such collisions must be accommodated in some way.
A heap is a specialized tree-based data structure that satisfies the heap property described below.
In a min heap, if
P is a parent node of
C, then the key (the value) of
P is less than or equal to the key of
C. In a max heap, the key of
P is greater than or equal to the key of
C. The node at the “top” of the heap with no parents is called the root node.
A linked list is a linear collection of data elements, in which linear order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a group of nodes which together represent a sequence.
Each node is composed of data and a reference (in other words, a link) to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration.
A drawback of linked lists is that access time is linear (and difficult to pipeline). Faster access, such as random access, is not feasible. Arrays have better cache locality as compared to linked lists.