Part 3 — Data Structures and Algorithms in Plain English | Data Structures
Welcome back to the third part of this series. I want to believe that you’ve followed through till now and I’ve gained quite the insight over the course of the weeks. We may not be coursing fast but we sure are learning well. What’s more important is the insight gained, not just the ground covered. The last question from part 2 of this series got us thinking if our understanding of data structure is actually correct or needs to be modified.
If you have ever learned a computer language, then you most definitely have come across the term data types. A data type is simply the most basic way in which data can be classified. This classification allows a computer to better understand how to deal with the input it receives. In plainer English, you could say data type is just a label assigned to the information passed into a computer’s compiler (the technology responsible for interpreting codes) for it to better understand things. Data types vary in name based on the Programming Language; nevertheless, one consistent thing is that they all encapsulate primitives like Strings, Numbers (Integers & Float), Boolean, etc.
Now, let’s say you need to store information about the scores of some students and information about whether they passed or not, how do you go about this? Here’s how you would approach it using the algorithm logic we learned in part 2.
- Store the students’ names
- Store the students’ scores
- Loop over each student
- Check if they met or surpassed the pass mark
- Record this as either true or false
We now have a workable algorithm… great! But how do we keep all these data in one place? The first thing you should notice is that storing the names requires that we store String data type, storing the scores requires storing Number data type, and storing a true or false value requires storing a Boolean data type. We now have 3 data types in our hands that need to be stored in one place for each retrieval.
Let me guess… you are thinking of using something called JSON, right? Or maybe a dictionary if you happen to be a Python person. Either way, one thing you realize is that you need a structure to better organize these data and such structure can be provided by things used in JSON and these include Arrays and Objects.
Don’t confuse it, JSON is not a data structure! It is just a way of exchanging data while relying on two data structures called Arrays(list) and Objects (hash table).
Now that we have those few things sorted and cleared out, we can further streamline our knowledge with a definition that goes thus.
A data structure is simply a collection, a storage that allows for the organization of different data types (strings, numbers, boolean, etc) such that we can easily and efficiently perform insertion, deletion, and search operations on them.
Depending on what you are working on, you will need to store complex data in some ways that make it simple to retrieve and it is only a sound knowledge of data structures that can allow you to perfectly achieve this. We have two categories of data structures which includes
- Linear Data Structure
- Non-linear Data Structure
If you have a basis in Mathematics, then you know from your regular straight-line graph progression that Linear refers to things that follow a particular order, maybe an equation or a sequence. The same applies to data structures. In a linear data structure, data are arranged in a sequential manner such that they succeed and precede one another depending on the read path. This means elements in a linear data structure are ordered which makes them quite easy to implement. Examples of linear data structures include
- Array Data Structure (This is quite familiar… it is the same as lists in Python)
- Stack Data Structure (Elements are stored in a last-in-first-out order… A practical example is the back button on your phone or browser… or just a regular stack of plates)
- Queue Data Structure (Think of this as a queue for a movie ticket or JAMB registration, first-in-first-out… you find a regular application in your printer or computer scheduled tasks)
- Linked List Data Structure (Data here are stored such that position doesn’t matter since one data is connected to the next via a node. This node allows you to locate where the next item is. This means you can’t skip through since you need each node to know the location of the next one…. A practical example is the Control Z for undoing things.)
Don’t worry, we will talk more on Array Data Structures and Linked Lists in the coming series as they are pivotal to our learning.
Contrary to the sequential pattern of the linear data structure, a non-linear data structure stores elements (data) arbitrarily such that one element can remain connected to one or more elements. Examples of non-linear data structures include
- Graph Data Structure
- Trees Data Structure (Binary Tree)
Below are the major differences between the Linear and non-linear data structures.
While we might touch on or make mention of a few things relating to non-linear structures, we will confine most of our studies to things involving linear data structures.
In the next part of this series, we will be digging into things like Big O notation while we write our first computer-coded algorithm for a Binary Search system… yea! Binary Search.
Found this article interesting too? Then clap it up while we all wait for the next. Thank you and stay safe.