New
Data structures and algorithms simplified

Data structures and algorithms simplified

Data structures and algorithms are two very popular concepts in the software development world.  If you want to become a good software engineer and write good computer programs. You have to know about data structures and algorithms.  Really, there is no way around it.  They are vital for building scalable applications with high efficiency and maximized performance. 

But data structures and algorithms are known as very difficult concepts to master.  They create a lot of fears and get in the way of beginners who want to become good software developers, including myself.  In this article, I am going to share with you my journey of learning data structures and algorithms and how I break them down in order to learn them well and fast.  Let’s start with a simple definition and break it down to a level that makes sense to us. 

What is a data structure?

A data structure is just a fancy term.  What it really means is a bucket (location) to store and organize data.  Think of it this way. When you use the contact application on your phone to search for a specific person or the GPS application to search for routes to a specific destination, or even run a Google search for a specific word. For each of these use cases, the data should be stored and organized in a certain way that makes it easy and efficient to work with. That is where data structure comes into play.  It is just the bucket formatted and organized to store the data. It includes the data itself, including information about the data with application relationships and functions.  

Here is another example. Think of a carpenter or a mechanic. They have a set of tools where each tool is made and customized for a very specific job. It is the same for software developers, data structures are a set of tools in their toolbox. Each data structure can be used in a specific use case to solve a specific problem. We are going over each one later, but for now, what I want you to remember is that a data structure is just a container customized to store data for very a specific use case. 

Data structures are building blocks for any application. They are organized by composing data elements into a logical unit representing the data abstraction relevance to the application. Data structures are specific ways of storing and organizing data so that It could be processed and retrieved quickly and efficiently when needed. 

Data structure classification 

Data structures can be classified in several different ways depending on the properties and use cases.  Let’s consider a more generic approach. They can be classified based on their data type, for instance, Primitive Data Structure vs Non-Primitive Data Structure

Primitive Data Structure: 

This is the fundamental building block of data structure. They come out of the box and are prebuilt with any programming language. They can store single data values in a specific memory allocation. Some examples of primitive data types are int(integer), long, float, boolean, char, byte, double and short.

Non-Primitive Data Structure 

They are user-defined data structures derived from primitive data structures. Generally, they are able to store more than a single data value with defined relationships.  Non-primitive data structures give programmers more flexibility, for example, they can store more than one data type in a contiguous or random memory location. Non-Primitive data structures could be further classified into linear data structures and non-linear data structures. 

Linear data structure 

In a linear data structure, the data elements are arranged sequentially and each of them is connected to the element next to it. Linear data structure makes it easy to access the element in a single direction.  Some examples of linear data structures are arrays, linked lists, Stack, and queues.

Non-linear data structure 

In this data structure, data elements are not arranged in sequence and each one can connect to one or more elements using defined relationships. Generally, there is some sort of hierarchical relationship between the data elements. Some examples of non-linear data structures are graphs, trees, and sets. 

How to choose the best data structure that fit your specific use cases?

Choosing the right data structure involves several factors to consider.  The first step is to have a good understanding of the problem that you are trying to solve and to be very clear about the output expected.  You need to understand the data type that you are working with and the type of operations you are going to perform.  Here are some of the most common operations performed in data structures: searching, traversing, inserting, deletion, sorting, and merging. The next step is to understand the time and space complexity of the algorithm you are going to use.  

Most of the time you will need to make some trade-offs, for example, do you want your program to run fast and take a lot of memory?  Or you want less memory but a slower run time. Having all these details sorted out in advance will help you choose the best data structures and algorithms that suit your use case.

What is an Algorithm?

Most of the time, when people heard the word algorithm, they get scared. They think of highly sophisticated computer programs running very complicated mathematical operations. But in a very simple definition, an algorithm is just a step-by-step procedure with a set of instructions to be executed in a very specific order to produce the desired outcome.  In order words, an algorithm is a step-by-step instruction that tells the computer how to solve a problem.  Algorithms are independent of any programming language, and they can be executed in any chosen programming language. 

Think of cooking recipes.  It is just a set of instructions about how to make a dish.  Anyone can follow the recipe to make the exact same meal.

What are the qualities of a good algorithm?  

As humans to humans interactions, when we are giving instructions, sometimes we skip things and assume the person will figure it out based on previous steps or the person’s general knowledge. But in a computer algorithm, we cannot skip steps and assume the computer will figure it out.  Every step should be included and sometimes repeated in sequence. Here are a few characteristics a good algorithm should follow. 

  • Each step should be very clear and unambiguous
  • An algorithm should be independent of any programming language.  It should be able to implement in any chosen programming language.
  • Input and out should be very precise
  • An algorithm should be resolved after a finite number of steps.
  • All steps should be included following a precise order 

Why learning about data structures and algorithms 

As we recall earlier, data structures and algorithms are tools in the developer’s tool set.  They use them every day to solve various and complex problems. Knowing data structures algorithms not only will make you a better developer but will also allow you to build scalable applications with high efficiency.  By knowing the characteristics of one data structure in contrast to another, you will be able to make the right decision in choosing the right data structure to solve any problem. Data structures and algorithms help us understand the nature of problems at a deeper level. When we understand the problem, we can solve it more efficiently. You will be able to come up with optimized solutions to real-world problems more quickly.

Basic prerequisites to master data structures and algorithms faster. 

Learning data structures and algorithms can be a little bit intimidating, but there is some basic knowledge that could help reduce the learning curve and make the process easier.  The first thing is to learn a programming language.  Just pick one that you like and get good at it.  Master all the fundamental building blocks and get comfortable with the data type collections. Basic knowledge of the following concepts will help you learn and master data structures and algorithms faster.

  • Logarithms and exponential
  • Time complexity and space complexity (Big O)
  • Randomization and probability
  • factorial

Conclusion

Data structures and algorithms are very important concepts in software development.  A data structure is a container formatted to store and organized data.  Algorithms are step-by-step instructions (recipes) for computers to solve problems.  Learning about them is very beneficial because they allow developers to write scalable applications optimized with high efficiency.  To learn more about each topic, check the link provided throughout the article. Don’t forget to check other articles to learn about each data structure and algorithm in deep.

3 Comments

  1. […] computer science, big O Notation is the term used to describe the performance and complexity of an algorithm as the input size is increasing.  Basically, it is the number of operations It would take for an […]

    Reply
  2. […] JavaScript is very powerful and widely used.  There is a lot more JavaScript front-end framework, but learning how to use the suggested ones above will take you a long way in your front-end development journey.  Which one is the best?  Or which one should you use highly depends on your use case and your project scopes and requirements.  You need to fully analyze your project requirement and make an informed choice because each framework has its own advantages and disadvantages.  Please let us know in the comment which one is your favorite and why.  I can wait to read your comments. Find more resources. […]

    Reply

Leave A Reply

Your email address will not be published. Required fields are marked *