What is a data structure?
In computer science, data structure is how we organise a collection of data in computer memory so that we can use them efficiently. Two main characteristics we use to describe different data structures are the relationship amongst the data and the functions that can be executed on them.
Data structure can be also divided into 2 main categories, linear and non-linear.
Linear data structure
A collection of data of which each element is connected to another unique element creating a series of linked elements. This relationship is formed with pointers.
Types of linear data structure include arrays, linked lists, stacks, and queues.
-
Arrays
A contiguous data structure of a predefined size where elements are adjacent to each other. Arrays, though, are static structures and thus they have a disability to dynamically increase or decrease in size, which is a major disadvantage.
-
Linked Lists
A dynamic data structure of which we can easily adjust it’s size. Linked lists, again, have their own weaknesses such as no random access like what we have in arrays.
-
Stacks & Queues
Stacks are a LIFO (Last In First Out) data structure where we can add and remove elements only from one side of the stack called the Top.
Queues are a FIFO (First In First Out) data structure where we add elements from the tail and remove elements from the head of the queue.
Both stacks and queues can be array-based or list-based. We usually use them when we want to build a more practical solution to a problem. I’m going to talk about this in examples later in a future post on algorithms.
Non-Linear data structure
A collection of data of which each element has multiple relationships, meaning it’s connected to more than one different elements in the collection. Again, this is achieved with pointers.
Types of non-linear data structure are trees and graphs.
-
Trees
A collection of data formed of a root element that has children elements and it’s children have their own children and so on. Usually, we use Binary trees which are trees formed of a root element that has only a left and a right child.
A very common use of such a tree, is a Binary Search Tree, which is a tree of which every left child is less than it’s parent and every right child is greater.
Binary search tree data structure are used in large data sets as they have faster access time. -
Graphs
A data structure with two main components. One component comprises of data representing nodes that are called vertices. The second comprises of data pairs, which, are essentially two connected nodes forming a line called edge.
In a graph we also have paths; which are formed by all the connected edges or “lines” from a node X to a node Y.
These type of data structure are commonly used amongst social networking platforms like Facebook, LinkedIn and Google.
Lets take LinkedIn for example. A graph is formed of a user “the node” connected to his connections (1st connections) as well as to his connections-connections (2nd connections) and so on.
This example demonstrates how we use graph data structure in our every day lives, and their importance.
Why are data structure important?
Computers sole purpose is to process information in a way that people can’t, and the science behind it is the how.
We use computers to store and process information (data), that are either a huge amount of data or require complex processing. And, we do that because computers process them a lot faster than humans do. Though, computers still have weaknesses which had to be addressed in our age of information.
Data structures are a powerful tool for making processing the enormous amounts of data we generate today more efficient; enabling the practical use of those data in our daily lives.
Let’s take Youtube for example, which has billions of hours of video stored for us to watch. When we want to watch a specific video, finding it on Youtube could potentially take hours and that wouldn’t be so efficient.
So, by storing videos (data) in certain structure along with the appropriate search algorithms, can make finding a video a matter of seconds making our life easier.
Not all scenarios are the same and that is why we have multiple data structures each with its unique abilities.