Introduction to DSA
In this series, we will go through all of the concept related to Data Structures and Algorithms. We will use the most loved programming language C++ to implement all these concepts so let's dive in!
Note this course assumes you have a little knowledge of C++ Programming language.
So, what is a Data Structure?
A data structure is a blueprint for storing, managing and accessing some kind of data. It simply makes it easy to work with any kind of data. There are several types of data structure each designed to suit a specific purpose.
In order to better understand, what is a data structure we have to first clear what is a datatype. It is something that is the base for a data structure.
Introducing Data Type
A data type is simply a classification that specifies which kind of data a variable can hold and what kind of operations can be performed on it.
Some example of data types are integers, arrays and Linked Lists. Notice, how each type is different from the other. For example, you can't loop over an integer like an array.
Categories Of Data Type
We can split data types in three different categories:
Primitive Data Type
Composite Data Type
Abstract Data Type
These types are simpler than it seems. Let's deep dive and try to understand the difference between these types!
Let's start with Primitive Data Type!
Primitive data types are the fundamental building blocks representing the type for values directly stored in the memory.
Example are int, char and bool.
As you noticed, all of these types are the base types which are built-in with all of the programming language and are implemented behind the scenes and the programmer doesn't need to know about the implementation of these types. All the programmer has to know is how to use them. As we are going focus on C++ only, here is the how we can use these primitive data types in C++:
int x = 34;
float y = 3.14;
char z = 'k';
Next one is Composite Data Type!
Composite data type is just a combination of primitive data types.
Yeah, that's all. It's as simple as that. Obvious examples are arrays and strings.
One thing to notice here for these data types, some of implementation detail is hidden. But the structure will be obvious, and we can see how everything is put in place. For example, in the example below, we can see how and in which order are element placed in an array.
int x[3] = {10, 20, 30};
Alright, what about Abstract Data Type?
Abstract data type is different from primitive and composite data type. It's more focused on the behavior rather than the implementation. There is strong abstraction layer so we don't get any implementation detail. Now, let's understand this data type in a deeper manner!
One of the basic data structures is linked list. Notice how the actual memory containing linked list differs as compared to our imagination.
Let's imagine a linked list with 5 items in it. Here is how we conceive it vs how it is actually stored it in the memory.
In Memory:
In our imagination:
As you can see, it's very different how we imagine it to be while working with a linked list. It may feel like something organized but in reality, it places every single item in random spots in the memory. While the end user doesn't know any of this detail.
So yeah, this is the abstraction layer we are talking about. This is how we abstract out the details of the data type and the user will only work with what is exposed while never knowing how it is actually implemented.
It doesn't mean user can't google it up on how the linked list works under the hood. It's more like the idea that user doesn't need to know that to work with it.
In addition to linked lists, we have many other abstract data types like stacks, queues, trees and graphs.
Alright, now back to data structure
Data Structure is simply the implementation of ADT (Abstract Data Type). We will literally implement those abstract data types like lists, tree and stacks from scratch in order to learn how they actually work.
You may be wondering why learn this? The answer is because data structures allow us to store and manage data in the memory in a very efficient manner.
Alright, now let's move on to our first DSA topic...