Table of Contents
I’m a sophomore now and have data structures and algorithms courses this semester. I’ll try to explain to you what they mean. I want to stress that you need to learn them by heart to be a better programmer.
We work with data everywhere in computer science from processor to RAM and from the operating system to the cloud database. We manipulate and process them to yield the desired results, so it becomes a crucial task to handle data efficiently. Ever since the computing era has begun, human minds have shown eagerness to develop better and efficient techniques of working with data which is only because to reduce time consumption in yielding results and also to save storage space.
What do you mean by data? #
Data is any set of values. It can be the depth of the river Ganga or the marks in your mark sheet.
In computing, data is all about binary digits 0s and 1s (bits or binary digits are the smallest units of data). Computers are electronic machines and are constructed of billions of ON/OFF switches, known as transistors. 1 is the ON state of a transistor, and 0 is the OFF. A computer stores real-world data in the form of binary digits.
How can we organize data? #
Imagine an office workplace where files are scattered everywhere and another workplace where files are neatly placed one above the other. Now, if you were supposed to find a particular file then which workplace arrangement would make your task easier?
The latter one. Why? Because it is much easier to find a particular file from an organized stack of files. Here, intuitively you have used the concept of data structures. That’s the same concept behind the stack data structure.
What is a data structure? #
A data structure is a way of storing and organizing data to access and use data efficiently.
There are two types of data structures on the basis of the organization of the elements:
- Linear data structure - Elements are accessed in a sequential order but it is not compulsory to store all elements sequentially. It can only have one successor and one predecessor. Examples: arrays, linked lists, stacks and queues.
- Non-linear data structure - Elements of this data structure are stored/accessed in a non-linear order. It can have more than one successor and predecessor. Examples: trees and graphs.
What is an algorithm? #
Below are the instructions to turn ON a computer:-
- Switch ON the main power supply.
- Is there a UPS?
- If Yes, then turn it ON.
- If No, then go to step 3.
- Click the power button on the cabinet.
Algorithms are instructions backed by logic. We need to follow certain steps to achieve any task or solve any problem. So, an algorithm is a step-by-step procedure to solve a problem. Every algorithm works on a set of data supplied to it as input. Manipulates it with the concept of data structures and gives us the output.
Before there were computers, there were algorithms. But now that there are computers, there are even more algorithms, and algorithms lie at the heart of computing.
excerpt from book, Introduction to Algorithms, CLRS
How good an algorithm can be? #
The answer to it depends on the running time of an algorithm (time complexity) and space it would take up in the memory (space complexity). These two factors conclude the efficiency of an algorithm. The less is both the factors, the better is the algorithm. But there is always a trade-off between the two. Like trying to reduce the time complexity may increase the space complexity.
I tried to introduce you to the domain of data structures and algorithms. I hope this article piqued you. The internet is full of resources to learn more about them. I would recommend you to start with GeeksForGeeks and solve a few problems there.
In today’s world, our lives are being shaped by algorithms and they are behind everything.