A Basic Introduction to Data Structure

A Basic Introduction to Data Structure

Data structure is a collection of values. Understanding data structures will help you write great programs, the beauty is that data structure is timeless, no matter what programming language, whether you prefer one library over the order, whether you write code in angular or react in the front-end development world or you are a game developer, underneath it all, is all data structure.

If you understand this then you can easily adapt and tackle all sorts of technical problems. This is why companies like Google, Facebook, and Amazon, ask questions specific to data structure because although it may be important to know the latest and greatest JavaScript syntax or the latest and greatest library, these things change, if you know the fundamentals, then they can tell you any problem, any situation and you are able to make the right decision.

This knowledge is extremely valuable, the longer you are in the field the more and more you realize you need these fundamental principles of data structure in other to be a great developer or engineer.

In this article, we will examine the basic fundamentals of data structure so as to get familiar with the concept so we can be able to write great programs, let's get started.

What Is Data Structure?

As written above data structure is a collection of values, the value can have relationships amongst themselves and can have functions applied to them, each one is different in what it can do and what its best used for. The most important thing to take away is that each data structure is Specialized for its own thing.

Analogy

container.PNG

You can think of data structure as any form of compartment or container. a data structure is simply a cabinet of different types you, have your backpack a place where you put your school books, you have a drawer, a place where you put your clothes, a fridge where you put your food, a folder for your files, and a packing box maybe for your toys. Each of these containers is used for its own thing, for example, you will not put your food in a drawer because the food will go bad in there, likewise, you're not going to put paper into your backpack or perhaps a toy box because it's just going to get all missed up and disorganized. Each one of the containers is specific for its own thing and that is what data structure really is. It is a way for us to organize data so that we can always go back and retrieve that data. We can put things in a data structure and we can take things from a data structure.

You may have heard of Bitcoin and know it uses blockchain technology, well blockchain at the end of the day is simply a data structure; a way to hold information.

In our programming world with data structure, we can store things like numbers, strings, and Boolean types.

Two parts to understanding data structures

  1. How to build one; this entails building with code some of these data structures.

  2. How to use it; this entails understanding how to apply data structure in solving real-time problems.

    The second one is pretty much the most important because data structures are usually just tools and most of the time they are already pre-built for us, the most important part is how to use them and when to use one over another.

Based on different scenarios, data needs to be stored in specific formats. We have a hand full of data structures that cover our need to store data in different formats.

How Computers Work

In order to really understand the value of data structures we have to dig down into how a computer works at the fundamental level.

In order for a computer to run code it needs to keep track of things like variables, numbers, strings, and arrays. These variables are stored in what we call random access memory (RAM) that’s how programs run. We still have storage, where we store things like our video files, music files, and documents, and the storage can be a disk drive, a flash drive, or a solid-state drive.

drives.PNG

Data on storage is permanent or what we call persistent, so when you turn off your laptop or computer it’s still going to be there when you turn it back on. In RAM you lose the memory when the computer turns off.

So why wouldn't we just use storage so we don't lose data? well, the problem is that persistent storage is slow, and a computer is run by its CPU, you can think of the CPU as the little worker that does all the calculations that we need. It does the actual work inside our computer and this CPU needs access to the RAM and the storage, but it can access the RAM and the information in the RAM a lot faster.

process.PNG

You can think of RAM in our computers as massive storage areas the massive storage areas have shelves that are numbered we this address(s) and it's a really big shelf that holds a lot of information and it allows us to run programs on our computer. Each of these shelves holds what we call eight (8) bits or numbers.

holderdata.PNG

Each one of these numbers is a bit, a bit is a tiny electrical switch that can be turned on or off, but instead of calling it on or off we call it 1 or 0, and eight bits are called a byte. Each shelf has one byte of storage and the CPU is connected to something called the memory controller, and a memory controller does the actual reading and writing of the memory.

In case you're wondering why this is important for data structure? Remember data structure I way for us to store information, therefore understanding the fundamentals of how the computer works will help a developer in writing cleaner and better codes.

Types of Data Structures

There are a ton of data structures however, they are just a few that you will be very likely to use regularly. These are the most used data structures;

1. Arrays

2. Stacks

3. Queues

4. Linked List

5. Tree

6. Tries

7. Graphs

8. Hash Tables

They might be specific reasons why you want to use any of these, but it is important to note that they all have trade-offs. By trade-offs, I Mean each of these may have merits and demerits depending on the situation or the scenario. But as long as you learn when and why you should use them you're going to be way ahead of most people.

Various operations can be performed on different data structures. Do note that each data structure has its trade-offs, some are good at certain operations and some are good at other operations.

These operations are;

1. Insertion; this has to do with adding a new data item to a given collection.

2. Deletion; removing a data item.

3. Traversal; this means assessing each data item exactly once so that it can be processed.

4. Searching; finding out the location of a particular data item if it exists in a given collection.

5. Sorting; having data that is sorted.

6. Access; this is probably the most important. How we access data on our computer.

Each data structure has its pros and cons for each one of these operations listed above. Your first responsibility is to understand the problem you trying to solve as this will inform your decision of which data structure to use. Every existing solution out there has a data structure they use based on the uniqueness of its production.

Thank you for reading this article, I hope you got value for your time. If you did please like and share with your friends, colleagues, and family. let me what you learned in the comment section.