Guys we are going to start data structures and algorithms with notes from today's video so let me tell you a little bit about this course first of all, this course will be primarily for placement preparations it will be for placement preparation, alright. so I write here "Placement Prep" and along with that I want to tell here that I will cover all the topics keeping in mind the placement because let's be honest there are many topics that are there in data structures and algorithms which are very long topics and if I will stay stuck on them and you have very limited time so you would like that I cover only those topics which are important so I'll teach it keeping that thing in mind it's not like I'll just stick to the array or just stick to the linked list or I will just keep exploring the graphs too much. I will give a optimal length to the whole course and by making an optimum length course, I will make this course according to which you get maximum benefit. Along with that, let's talk here that what are the prerequisites of this course? that which programming language am I going to use in this course? I will use C and C++ here let me tell you guys over here "C and C++" However, even if you do not know C++, you will still be able to do this course without any issue and in C++, I will tell you that just learn as much as I have taught in my "C++ in one video" I have an "one video" which is about an hour long "C++ in one video" in that, just the new operators that it has.. I have taught by excluding object orientation in that video so over there, you guys will learn about C++ only as much as you need to shorten syntax of C. Now as there is "malloc" in C and "new operator" in C++ so how to use that new operator so that thing I have told you in this and even if you don't go into the depth of object orientation, it will still work. So you should know that much of C primarily, the C is going to be used even if you don't know C++, then it will still work. The notes that are about to be, I will make you available their pdf so you don't need to worry about that that if there are notes then where is their pdf I will available all of those in the description below and here, what will I do now that I will tell you guys, what is data structures and algorithms? First of all, if you learn something, then you should know what it is so data structures... I put a dot here as the space is a bit less and I write algorithms here, okay So I have written Data Structure and Algorithms I'll change the pen here, get the blue pen it would felt little nice to see. Now what is data structures? the data structure is exactly the same as you have learned the array you probably already know the data structures you have used the array before, so you already know the data structure algorithms and data structures are two different things, what is the difference between the two, understand this thing. First of all, I would like to talk about the data structures Data structures are the ingredients for developing efficient algorithms what is it? these are the ingredients for developing efficient algorithms with the help of which you will create efficient algorithms that is, these are the ways to arrange data in main memory in main memory for efficient usage so I will write here "for efficient usage" and I have written all these things in notes so you don't need to note down it notes are prepared for you so it's not like you need to write this. This is our way to arrange data in main memory for efficient usage I go a little to the side so that you guys can see. Now what is a algorithm? the basic definition of data structures has been told to you let's take the examples of data structures over here we have arrays, linked list, stack, queue, graphs, binary search trees, etc etc. We will learn about everything, I will come to everything there is nothing to be worried about, take it easy just keep following step by step as I am telling It will be easy to understand, there will be no problem and I'll teach in a very different way and I consider this a responsibility when you are teaching data structures and algorithms, you are taking a responsibility so whenever a course like this is taken, a responsibility comes because people are preparing for placements so the course has to be taught with a little caution that's why I delayed this course a bit but I am happy that I have brought this course for you. Now data structure is a way to arrange data in main memory for efficient usage we have given the examples here. what is an algorithm? Algorithm is a sequence of steps to solve a given problem a very simple definition [to solve a given problem] I have written it in notes [to solve a given problem] now what does it mean? Suppose you have to make coffee, alright then what do you do? or you have to make tea you pour the water, add tea leaves, add sugar when it boils, add milk to it the tea is ready what is it? this is an algorithm If I tell you guys that this is an algorithm then you will say, what! I will say, yes this is an algorithm because you've taken some steps here to solve a problem what was the problem? needed to drink tea as I was sleepy this was the problem What were the steps you took to solve it? Step 1: Add water Step 2: Add tea leaves Step 3: Add sugar don't put salt after that you pour the milk after pouring the milk, when it boils then sieve it and your hot tea is ready so what is it? this is an algorithm in the same way when any work is taken from the computer Who got the job done here? it is taken from human similarly, when work will be taken from computer then I'll speak to it in it's language I won't say that pour water into the pot, add sugar, add leaves so I can't say it I'll explain it in its language like int main(), int a = 3; I will implement the algorithm on those languages I'm using C, C++ here but python can also be used to implement the algorithms even you can use java as well for implementing the algorithms why I have used C, C++ here? My main motive to choose C, C++ here is that when you use C, C++ then you are able to understand the basics C is a bare bone programming language you have to do everything yourself in it. The problem I have in python is that if you learn data structures & algorithms through python the first thing to note is that when you are preparing for placements then C and C++ is expected from you by default you can do it in java as well and if you guys are following this course and if you know java then you will be able to follow it very comfortably there is no problem you can also follow it for java but I will write the algorithms in C & C++ but it's not like you can't write in java if you know java, you can also write it in java but I will not recommend python will not recommend javascript as well if you are an advance user then you can use it but for beginners, neither javascript nor python and remove the rest of the programming languages too. I would say learn "C", it will not take much time if you will fall into the trap of learning it through python then you will be harmed if you are a beginner I am telling you this from experience however, you can program algorithms in python as well everything is possible if you talk about the possibility, it is possible but learn C and C++ C++ is optional, learn C I will use C in this I have made a 15 hours long video of C with notes you will also get that, find it by going to the channel and if you are an advance user in java you know everything in java then you will be able to do in java as well. There will be no issue, alright. So we talked about data structures, we talked about algorithms let's take an example of algorithms in computer science language I have given an example of making tea, which is right as per understanding will be felt a little peculiar... don't write tea example in exam and even if you do, you will have to present it very professionally so the example I'm taking here is sorting an array sorting an array now what does this mean? suppose there is "1 7 9 2" it will be the input and what will be its output if you sort it "1 2 7 9" If you want to sort it in ascending order, then "1279" will be its output so you must have taken some steps to sort an array what are those steps? the steps you have taken frames the algorithm which is an algorithm to do the sorting of arrays "to do the sorting of arrays" alright. So here I told you what is data structures, what is an algorithm? I told you that this course is going to be primarily for placements or if you want to switch the job or want to give interviews I will also tell a lot about interviews in later videos but I'll cover the content first I understand this very well that time is very limited when you prepare for placements and I understand that thing and will structure the course accordingly I will structure this course keeping the value of your time and I have made these notes if you can see let me show you I have written complete notes you will understand well I have written all the definitions here I've used some terminologies which I'll just tell you here and after that I have written about memory layout which I will discuss about now. So... by the way, you don't need to write it because I have already written in notes but what will I do over here now? I'll just rub it so I clear this board and I will tell one more thing over here I have told you the course structure and I will start "time complexity" from the next video and after that, data structures have to be explained and then I will take according to the sequence and then I will do the things in order. There are few terminologies, I would like to talk about them "database" and along with that, "data warehouse" and you will get to hear this and it is asked in the interviews, "tell me, what is this?" and one is "big data" What is database? First of all we saw, what is data structure? What was data structure? Data Structure is an arrangement of data in main memory where? In main memory when I say main memory, it means RAM so what is main memory... whenever main memory is being talked about, it means RAM which is of 2, 4, 8 & 16 gb and in some, it is of 32 gb also and in some of them, there is even more but this much is found normally so main memory means RAM. When I'm saying main memory, I'm referring to RAM So now let's understand database, data warehouse and big data here we have understood the data structure that when your program starts in RAM let say there is a program..., let's take the example of microsoft excel or google chrome when you load it then where does it load? it is loaded into the random access memory; it is loaded in RAM and then something will happen with the data that means the program "chrome.exe" if you are on windows. So first of all, chrome will get loaded into the RAM quickly and after that, something will happen inside the RAM whatever is the program's code, whatever has been written, whatever the sequence of steps are there to open a new tab, to download a new file there a lot of things in chrome. So there will be messing with the data inside the main memory itself and fiddling with the data will happen, the work and operations will be done on that and to make that arrangement optimal, it is the responsibility of the people of Chrome who have made the software and make to them optimal that means to minimize the usage of RAM because if chrome uses more RAM then its competitors are standing on the side like firefox internet explorer's edge has also come, the new edge has come so they are standing behind that just somewhere chrome.exe crashes and creates problems for the people and we will come in the market that our is much better since they are standing, so they have to make very efficient use of data structures so that the program is loaded optimally into the main memory, work optimally with it and use minimal memory this is called the data structure that is, how to load a program into the main memory, how to do operations on data? so the operations on the data will be done in main memory in the data structures. The story in the database is kind of same but what happens here is that you retrieve and read the data from hard disk drive and update it. Alright You retrieve it, update it and delete it So if I define it, I have written the definition in the notes Right now, I'm taking the notes in my hands here I have written "collection of information in permanent storage for faster retrieval and updation" you will get the pdf in description, don't worry about it at all and along with that, I have written the definition of data warehouse "management of huge amount of legacy data for better analysis" let me explain this management of huge amount of "legacy data" now what is this legacy data? let me tell you about that. You have understood the database that a huge amount of data is stored in database you have to retrieve and update it it has not come into the memory, we just have to read it and update it like you can use mysql database, you can use mongoDB that database means, a huge amount of data is kept in your hard disk drive because whatever data will be in the RAM whatever data will be in RAM, it will be lost after closing the program so that's why, what we have to do if want to persist the data, want to keep it for longer time then what we have to do is we have to keep it in hard disk and keep it properly for efficient retrieval, updation and deletion and for that, we have to use the databases and to make that kind of designs, we have to learn the theory of databases which is out of this course we will only study data structures & algorithms here but you should know this. What is data warehouse? data warehouse means.. let say, I run a website called facebook.com I don't run it but let say, I run it now a lot of data from facebook.com must have been stored you must have uploaded a photo, your friend will have a birthday how many times did your friend wish you in 2009? well, if it's a birthday, you must have wished only once but it would have been done on Diwali also so I'll keep that count or that data separately from my main system because that is the kind of data, I will probably use later to do the analysis that is called "legacy data" Okay Now, suppose I have prepared some data of 2020 and 2021 but I don't want to keep the 2009's data in the same database because what will happen then if I will try to access it then it will get slowed because I don't want to keep a lot of data in one place I don't want to keep that on my main system. So let's say, this is my facebook.com and this is its database I'm drawing a very simple diagram, facebook is very complicated but let's assume, it interacts with a database so what will I do in this I will keep the fresh data in it and separate the legacy data legacy data will be the data that should be kept a little separate from the main system because I want to keep minimum data on the main system I don't want to load it from the useless data but I also don't want to loose my old data because I might have to do some analysis, I might have to see how many times people clicked on the profile Now how many times did I click on your friend's profile? it has nothing to do with the main system of facebook so they can keep this data separately and by collecting and keeping it separately, it can be analyzed later because data is a very big thing data is the fuel of big algorithms these days so we wouldn't want to lose the data right? I wouldn't want to lose the data so I will separate the data from main system and since this data will be very large, that's why I will separate it and it is called legacy data. Now how to store this legacy data, where to keep it? how to keep it in which disk, what kind of distributed system to be build so that I can store it efficiently that is called data warehousing this is beyond the scope of this course but you should know what it is. Let's talk about big data now what will happen At one point of time you may have to create such an algorithm that... for example, search engine because it deals with such a huge database that your normal algorithm or normal application may not be able to deal with it for example, let's say you want to search in that data and it's a huge data if you will open it in excel then it will not open excel if you have the limited memory. So for that different kind of algorithm, different type of analysis, different type of techniques have to be used and that is a separate field which is called big data. Once again, this is not in this course but you should know all these three terms. Now what I am going to tell after this is very important write the definition of these three and don't take too much tension of this but you should know this and these are asked in interviews too because it is not that if you are giving an interview in any company then you have to only study data structure and algorithm all these things are used within the industry and because all these things are used inside the industry so you can be asked anytime now because it can be asked from you anytime so if you have the answer then you will be given a good preference in comparison to other candidates. Now what I am telling is very important so listen it carefully, alright now let's assume here that this is my memory this is my memory, this is my RAM what is RAM? it is "random access memory" which you install in your computer or you go to increase it and say "make it to 8gb, make it to 16gb, add an another 8gb chip, do you have slot in your computer or not, I have it, I don't have it" that is called RAM, alright. Let's say my RAM is 16 gb most people have 8 gb but mine is 16 which is fine now the RAM which is there and when we talk in the context of C program let me write here "memory layout of C programs" ... memory layout. Alright... I'm talking about C program that's why I say that you get a good picture of memory with the help of C programming therefore, data structures and algorithms is best learned from C and C++ Now here I am dividing it into segments so there is thing called code segment let's say this is my code let's say there is a code with the name "harry.c" now this code will be first loaded into my main memory I told you what is the first thing that happens? whenever you open a program then it gets loaded into the main memory and what happens after that after that.... once it will get loaded, only then something will be done that has to be done now what is there? static and global variables are kept there and I won't talk much about it this is initialized and uninitialized segment I have drawn it in notes, you can look at the notes I have drawn the diagram in notes I will not discuss on this for now static and global variables are kept in this. After this, look carefully at the 2 sections that I am going to draw this is stack and this is heap, alright now, it is very important to understand stack and heap here why? because so many questions are asked on this and if you really want to understand how the C program works then it is very important for you to understand stacks and heaps. So stack is a normal memory it is such a memory... for example, I wrote "int i" or "int j" or let's say I wrote "char c = ch" created a variable and inserted a value inside it it will be created in my stack here now see this diagram carefully let's say there is a main function in my program and I have created a function with the name "fun1()" inside it now the fun1() function that I have I have created a function with name fun2() inside it so fun1() is a function and fun2() is a function which is being called inside fun1() and there is a main() function in my program which is always there. Now what will I do here the main() function that I have ..the main() function that I have, it will be called first so when it will be called then... it will get its place here its stack frame or activation record will be created so what will I do here that I'm creating its activation record it is called stack frame or activation record the activation record of main() has been created here all or whatever variables of main() has been created if I have created a variable "i" as int i = 0; then it will be created here if int j = 3; has been created then it will be created here then what will happen when all these lines get executed? then it will come to this line it will come to fun1(), it will execute fun1(). Now when this function will get executed then its own activation record will be created its own activation record will be created and the activation record that fun1() has what is happening inside it? fun2() is calling inside fun1() now the variables that I had created inside it will be created here let's say I have created "k" & "l" let me write here: initialize k and l and after that I 'm calling fun2() so as soon as fun2() will be called it will say to fun1() that you wait for a while, I call fun2() and be back by fetching the value whatever it will return fun1() replied that you go and get it call fun2() and get its value. Now suppose fun2() has created a lot of variables it has created a, b, c, d, f, g it has created all these variables and inserted values in all of them see here carefully the stack frame that fun2() has all these variables a, b, c, d, f, g are creating in it so it has created all these variables and consumed a lot of memory and finally returned a value whose value is 3. Let's suppose I'm inserting it in a value named "k" I'm doing it as k = fun2() so when I'm doing it as k = fun2() then what will happen as soon as I will do k = fun2() here so "k" will get the value that fun2() is returning you must have studied about function you have studied in any programming language, you must have known them so what will happen once I have this value let suppose, it returned value 3 value 3 has been returned after final calculation value 3 so what will happen that its entire data will be erased I cut it here like this it will get deleted, alright the activation record that it has will get emptied and after getting emptied, it will give whatever value it has returned let say it has returned "3". So it will give "3" to it and then finally, it will return some value and it might not even return, the return value of a function is void as well we had seen in the C so what will happen, it will also get deleted so this memory will get emptied and this will also get emptied and finally, this call will be returned here and after that.. when program will get finished then this space will also get emptied so this entire space will get emptied. Now what is this Heap? we have understood the stack that as the function calls happen, everyone will get the stack of their own function will keep getting it, getting it, getting it. What is this heap? I tell you what is this heap, listen it carefully listen carefully about heap let's suppose you need some money you no longer have money what do you do if you don't have your own money? you go to bank or request somebody that bro, give me 10 Rs, give me 20 Rs. you go to your friend, you go to your father, you go to your uncle you request to take the money you say, Give me the money. I'll give it back when I'm done so let's suppose, give it to me for 10 days or for 20 days you took the money for 20 days and then after arranging your own, you have returned it back to your friend bro, thank you so much. You lent me 20 Rs this is your 20 Rs note. So, you requested and when your work is completed you released it. Let's take the example of phone let's suppose, you say to your friend that I'm getting so bored, give me your phone I use a simple Nokia phone so your friend will say that okay, take it and play PUBG in this but give it back yes I will return it, no problem so requested it and after that when work is done, you returned it and emptied the unused part, alright. So what happens in heap is program allocate dynamic memory in the heap if you want to request dynamic memory then you request it from heap, alright so you request dynamic memory in heap and how do you request that? with the help of a pointer what is a pointer? Pointer is a variable which stores the address I have explained it to you in a very good manner in the C's tutorial I mean, I have explained it very well if you have watched it then you know and you will also say, how well it is explained this is not a question to ask for now so what will I do here is I will create a pointer which stores the address and by using malloc in C language or by using new operator if I'm in C++ I can use new operator in C++ and I can use malloc in C and I can request dynamic memory here let's say I want an array storing 4 integers so what will I do is, I can point this pointer here I will say with the help of this pointer, pt = int * malloc 4 * size of int I have already told you its syntax so I will request it in dynamic memory, right I will say, I want it dynamically now why did I requested it dynamically? I can make it in stack as well if I make it in stack then it stays there forever until I return the function I wanted to create it and then delete it right there inside that function so you can request this memory whenever you want and can delete it whenever you want and after that, from the same function itself you can request it whenever you want and release it whenever you want you can request it whenever you want, release it whenever you want this is a very big power that you can use the heap memory of your RAM and you can allocate the memory from where? By using a pointer from stack, you say that I want to store 4 integers Heap will say, Okay. Where do I give them? like you go to get the milk that.. I want 10 litres of milk then the milkman says where do i give it. Give it in the bucket So that bucket is the pointer What is the pointer? The bucket now don't ever ask what a pointer is "the bucket is the pointer" Pointer is something which stores the address so it will give you the address of the first element and after that, you will be able to use it. Then when you're done you will say, I don't need this anymore and you will inform the heap that I don't want this now. So release it then you will release it and whenever you want or need the memory, you will be able to use it or other programs will be able to use the heap memory. So memory has to be used very efficiently data structure and algorithm is the game of this only we have to use our memory very efficiently and by running our algorithm in very less time space is also important and time is also important and the next topic that we have is this time and space complexity but I hope you have understood this that why do we use heap, why do we use stack? If anyone ask you this question that why heap is used, it can also be done from stack What would be your answer? Your answer should be yes, it can be done but what if I had to delete in the same function If I had to create an array of 1 lakh elements and after doing a little work, if I had to delete it in the same function then how will I do it? so that thing is done here with the help of dynamic memory because when does the stack of a function ends it ends when the function is returned, alright. As the functions are getting called here, a new stack is being created so I started with the main() here after the main(), I stated " int i = 0;" in the main() after that what I've done is I called the fun1() fun1() said to main() that hold for a while main() bro I just come back with the value you just wait here, I bring this value whatever it is returning and then after that you can resume your execution you just pause for now main() will say, Okay I'm paused. You go and get it and then what will happen, fun1() will be called so what is there inside the fun1()? fun2() is there inside fun1() fun2() will say to fun1() that you just wait, I come back by getting executed and give you the value fun1() will say, Okay I stay and wait for you you go and come back by getting the value so it is waiting for fun1() to return fun2() is running and their memory will keep coming into the stack Now as these values will keep returning their execution will keep resuming I hope this thing will be cleared so this is how the C program is run inside our memory. First of all, the code will be copied now the code that is copied is machine code you will run harry.exe, you will not run harry.c so you will compile it first we know this, this is the basics Now here after that, I have told you how stack and heap works you have to use the heap responsibly if you made a mistake while using the heap then you can cause memory leak by using a lot of memory here that situation is called "memory leak" that is, you haven't free up the memory of heap and you keep requesting, keep requesting.... that is called memory leak. It is a very big issue therefore, whenever you are using heap, you have to allocate dynamic memory very carefully I have written all these things in notes so you won't have any problem. I hope you like this video In the coming videos, we will focus on data structures & algorithms it was the pre requisite, you should know little bit of it I will use these terms and understanding of this is necessary when we will see linked list, we will see array, when we will see binary search tree and all of that so there's going to be a lot of use of this thing over there that's why I have told you this and this is worth it and if you still think that you want to do all of these things with python so I am saying that when you will go for an interview then the person in front of you will expect C, C++ or Java from you you must know one of these three languages because if you go there and say that I don't know C, C ++ or Java you are only a python and javascript programmer then you will be taken lightly over there even if you know data structures and algorithms, you will still be down in front of a person who knows C I'm telling this from the experience this is also a mindset and you should do C, C++ or Java I can't emphasize enough you must definitely learn this. I recommend C and if you are preparing data structures & algorithm for any product based company and you are focusing on data structures & algorithm and devoting your time then I recommend C and C++ and I have given their reasons in many more videos I have made. If you don't know C properly then I have made a 15 hours long video of C with notes the way I have given this video with notes, in the same way, I have given that video also with notes therefore, do access it guys. I hope this thing is cleared, I was successful in explaining it to you and along with this, I will to say to you that download the pdf of the notes and do like this video guys tell me in the comment below how was this video. So that's all in this video for now we will explore time complexity and lot of other topics in the coming videos. Don't forget to like this video Thank you so much guys for watching this video and I will see you next time.. [Music] [Music]