[User] Please transcribe this text

[Assistant] So normally, proper English would require you to say or write you'd better. However, the way the D in you'd sounds when said against the B in better makes it almost inaudible. You can barely hear it.


[User] Please transcribe this text

[Assistant] As a result, many English speakers end up saying, and even writing, you better.


[User] Please transcribe this text

[Assistant] The player called Beater does exactly what Harry just did. They beat the bludger ball with a bat.


[User] Please transcribe this text

[Assistant] So we hear Oliver say that Harry would make a fair beater.


[User] Please transcribe this text

[Assistant] Although the adjective fair is mostly used in the sense of justice, it can also refer to the level of quality of something or somebody, meaning ordinary or acceptable.


[User] Please transcribe this text

[Assistant] So, Wood is saying that Harry would make a fair beater. He could play as a beater and it wouldn't be that bad, above average.


[User] Please transcribe this text

[Assistant] In Quidditch, the bludger is a heavy ball that magically moves through the air by itself, as if it were alive, trying to hit and knock down players.


[User] Please transcribe this text

[Assistant] Hey, do you want to learn the vocabulary that you actually need to understand natives and communicate confidently?


[User] Please transcribe this text

[Assistant] With 20 plus page, PDF power lessons, vocabulary memorization software, access to our Fluency Circle global community, and so much more. And you can try it for free right now with our three-part masterclass. Just click up here or down the description below to learn more and sign up.


[User] Please transcribe this text

[Assistant] Even though this is a made-up word from the Wizarding World, it reads and sounds similar to the verb to bludgeon.


[User] Please transcribe this text

[Assistant] In this sense, the adjective nasty refers to something or somebody that behaves in a bad or very unpleasant way that is dangerous, unkind, or violent.


[User] Please transcribe this text

[Assistant] Bugger is a slang expression used to refer to a silly or annoying person, animal, or thing.


[User] Please transcribe this text

[Assistant] To seek is to try to find or get something, especially something that is not a physical object, like a job or an opportunity. Example. If you're not feeling better by the end of the day, seek medical attention.


[User] Please transcribe this text

[Assistant] Finally, Oliver introduces Harry to the ball called the Golden Snitch.


[User] Please transcribe this text

[Assistant] It is golden because it's colored like gold, or it's made of gold.


[User] Please transcribe this text

[Assistant] Now, the name snitch in real English comes from the verb to snitch. If you snitch something, you steal it quickly and quietly.


[User] Please transcribe this text

[Assistant] The slang expressions wicked and damn function as adjectives and are used with the same effect to give emphasis.


[User] Please transcribe this text

[Assistant] So, he is saying that the Golden Snitch isn't just fast, it's wicked fast. It's super fast.


[User] Please transcribe this text

[Assistant] And it isn't simply near impossible to see, it's damn near impossible to see.


[User] Please transcribe this text

[Assistant] Have you heard the popular gaming expression, game over? Although most English learners know of these words,


[User] Please transcribe this text

[Assistant] Many don't actually understand the meaning of the word over in this collocation.


[User] Please transcribe this text

[Assistant] In this application, if something is said to be over, it is finished. It has reached the end.


[User] Please transcribe this text

[Assistant] So, you can actually collocate it with any other noun you would like to, not just with sports games. For example, you can say that the movie is over, the day is over,


[User] Please transcribe this text

[Assistant] I highly recommend that you check that out after you finish this video by clicking up here or down in the description below.


[User] Please transcribe this text

[Assistant] Hey, thanks so much for joining me today. Keep going on your journey to English fluency with our Harry Potter playlist. And now it's time to go beyond the classroom and live your English! Aww yeah!


[User] Please transcribe this text

[Assistant] Marshall, how have I always described my perfect woman? Ah, let's see. She likes dogs?


[User] Please transcribe this text

[Assistant] The olive theory is based on my friends Marshall and Lily. He hates olives, she loves them. And in a weird way, that's what makes them such a great couple. Perfect balance.


[User] Please transcribe this text

[Assistant] No green clarinet? Nope. Come on, no purple tuba? It's a Smurf penis.


[User] Please transcribe this text

[Assistant] So? Did you kiss her? No, the moment wasn't right.


[User] Please transcribe this text

[Assistant] Okay, not a perfect metaphor, because for me it's fall in love and get married, and for him it's death.


[User] Please transcribe this text

[Assistant] Great, great pleasure. Pleasure to meet you too, sir. Uhm, Ron Measley.


[User] Please transcribe this text

[Assistant] I'll tell you more about bazaars in our next class. Right, off you go. Please, don't forget your rat tail.


[User] Please transcribe this text

[Assistant] Hey, what's going on guys? Tanmay here for simple snippets and welcome back to another video tutorial on data structures and algorithms.


[User] Please transcribe this text

[Assistant] And today we're gonna talk in detail about the comparison between an array data structure and a linked list data structure.


[User] Please transcribe this text

[Assistant] Now before we proceed ahead, I'm assuming you guys already know what is array data structure, what is linked list data structure. If you have any doubts, please check out this course, please check out this playlist. We've already covered both of these topics, both of these data structures extensively in detail.


[User] Please transcribe this text

[Assistant] And this video is very important because here we are going to see the pros and cons of array data structure versus linked list data structure.


[User] Please transcribe this text

[Assistant] And try to understand which data structure is better in which scenarios.


[User] Please transcribe this text

[Assistant] So what do I mean by these scenarios or conditions? Essentially what I'm trying to say is there is no such thing as one best


[User] Please transcribe this text

[Assistant] And they work efficiently in certain conditions while they don't work well in other conditions.


[User] Please transcribe this text

[Assistant] So just note it down that no one particular data structure is the absolute best and this is what we're gonna try to find out in this tutorial. That's why this is a detailed video and it is also important as to which data structure that is whether array or linked list is better in certain scenarios and those scenarios as you can see are listed on the screen. So we're gonna go through all these different points and conditions and compare the two data structures.


[User] Please transcribe this text

[Assistant] If you're new to my channel, my name is Tanmay Sakpal and I do a lot of computer science and information technology video tutorials like computer programming, development, technology talks and a lot more on this channel. So if that's something you're interested into, then definitely subscribe and turn on the notifications to get the latest updates and never miss out on such important topics.


[User] Please transcribe this text

[Assistant] Now before we start off, a quick introduction for those who might have a little bit of doubt about these two data structures.


[User] Please transcribe this text

[Assistant] What is an array? An array is a collection of elements of same type.


[User] Please transcribe this text

[Assistant] Placed in contiguous memory locations. So this contiguous is a very important point or important keyword. We'll talk about it in a minute. And, and that can be individually referenced.


[User] Please transcribe this text

[Assistant] By using an index to unique identifier.


[User] Please transcribe this text

[Assistant] So when I say int arr and I give it a static size and let's say these are the elements.


[User] Please transcribe this text

[Assistant] So in the memory, so imagine this is a computer memory. This is the RAM. In the memory,


[User] Please transcribe this text

[Assistant] Four blocks are assigned to these four individual elements in this array. And if you note the addresses, so these are fictitious addresses. These are not real addresses. I've just tried to denote them so that they sound or they look like they are contiguous. And when I say contiguous, it means right besides each other. Now, this is an integer array, right? So we say int arr four.


[User] Please transcribe this text

[Assistant] They have unique indexes 0, 1, 2, and 3. That's how you can access individual elements.


[User] Please transcribe this text

[Assistant] But they are not right next to each other, they are right besides each other, which means that after hash 10, obviously we will have hash 11, 12, 13, right? But you can see hash 10 and then directly hash 14.


[User] Please transcribe this text

[Assistant] So why is there a gap of four? Now that is because a int


[User] Please transcribe this text

[Assistant] A variable of int data type generally takes 4 bytes in the computer memory.


[User] Please transcribe this text

[Assistant] It also takes 8 bytes depending upon your architecture. So I guess on a 64-bit architecture, it takes 8 bytes. But let's assume that an integer variable or integer element will take 4 bytes. So the first variable or the first element in the array is at the index position 0 and it is having a value of 45.


[User] Please transcribe this text

[Assistant] It's stored at the address of hash 10. Let's assume this is just address 10 and not hash. Usually addresses are, you know, complex hexadecimal values. For simplicity purpose let's assume it is 10. Obviously the next element


[User] Please transcribe this text

[Assistant] Will be stored 4 bytes after hash 10.


[User] Please transcribe this text

[Assistant] Since it is contiguous, which means it is right next to each other, obviously at address position hash 14, we will have the second element with the index of 1.


[User] Please transcribe this text

[Assistant] The index positions obviously start with zero, so that's why at one we will have the second element. Again, if you add plus four,


[User] Please transcribe this text

[Assistant] We will get 18, so hash 18 is where we have the third element and plus 4 hash 22 is where we have the last element.


[User] Please transcribe this text

[Assistant] So this is what contiguous memory allocation means, it means that right next to each other. Now if this was some other data type, if it was a char data type, so char takes 1 byte, right? 1 or 2 byte I guess. Let's assume it is 1 byte.


[User] Please transcribe this text

[Assistant] So, in a char data type, what would have happened? The addresses would have been, let's say hash 20. If the first address, that is the base address is hash 20, the second address would be hash 21. Third address would be hash 22.


[User] Please transcribe this text

[Assistant] Okay, so this is what an array is in general and this is how it looks like in a code format as well as in the memory. Now moving on to a linked list.


[User] Please transcribe this text

[Assistant] A linked list is a collection of elements, again just like an array which is also a collection of elements. And these elements in a linked list are also called as nodes.


[User] Please transcribe this text

[Assistant] That are not stored in contiguous memory locations.


[User] Please transcribe this text

[Assistant] So this is one major difference because in a linked list these nodes are scattered all across the computer memory. So in the computer memory diagram you can see first N1 and N2 are right besides each other but N3 and N4


[User] Please transcribe this text

[Assistant] Are basically somewhere in random positions in the computer memory.


[User] Please transcribe this text

[Assistant] Now obviously since it is a linked list, there has to be some link between these nodes, right? So the nodes are linked to each other using pointers. So pointers


[User] Please transcribe this text

[Assistant] Is not literally pointers because then it will only be available in C and C++. A pointer is nothing but an entity that points to the next node.


[User] Please transcribe this text

[Assistant] Now of course in C and C++ we use the concept of pointers, but in other general purpose programming languages we have different methodologies.


[User] Please transcribe this text

[Assistant] So essentially this pointer is nothing but an entity that points to the next node so that there is a link.


[User] Please transcribe this text

[Assistant] Now talking about this node, a node usually consists of two fields, namely data and next. So, data is the actual value, data is also called as value.


[User] Please transcribe this text

[Assistant] N2 will store the address of N3 and N3 will store the address of N4 in their next pointers. So that is what this next is all about.


[User] Please transcribe this text

[Assistant] And data is nothing but the actual value. However, sometimes you also have a third field called as id and name.


[User] Please transcribe this text

[Assistant] And, uh, it is also used. So in our examples of linked list, whichever examples we've seen, singly linked list, doubly linked list and whatnot in this course,


[User] Please transcribe this text

[Assistant] We always had key value as two fields and then the next pointer as the third field. Okay. So this is particularly for a singly linked list. If it was a doubly linked list, obviously we would have a previous pointer as well.


[User] Please transcribe this text

[Assistant] And this is how the data structure visually looks like. So we have N1.


[User] Please transcribe this text

[Assistant] Which is created at memory address hash hundred. Again, these addresses are fictitious. They are not real addresses. Okay. So don't take them literally. This is just for representation purpose.


[User] Please transcribe this text

[Assistant] So n1 is created at hash 100. It has the key of 1. So key is 1 in orange.


[User] Please transcribe this text

[Assistant] 45 is the actual value stored inside this node. Value is also known as data.


[User] Please transcribe this text

[Assistant] Over here in the memory also you can see. So 102 is stored inside the next pointer of N1. So that this link is made.


[User] Please transcribe this text

[Assistant] Similarly n2 is pointing to n3, n3 is pointing to n4. And in the next pointer of n4 we have null because n4 is not pointing to anything. We don't have anything over here. So a null is stored. Okay. Now we've already seen this in detail so I'm not gonna


[User] Please transcribe this text

[Assistant] Get more into individual details. We want to compare the two different data structures based on certain criteria. So now let's move on to those criteria and try to compare which data structure is better in which certain scenarios.


[User] Please transcribe this text

[Assistant] Okay, so the first parameter is the size of data structure. So the size in this case is how flexible is the size of the data structure. Now talking about arrays,


[User] Please transcribe this text

[Assistant] In most general purpose programming languages, the simple arrays have to be


[User] Please transcribe this text

[Assistant] Declared and the size has to be given at compile time.


[User] Please transcribe this text

[Assistant] So in C++ also you create an array and you give the size initially itself. So this is a very static way.


[User] Please transcribe this text

[Assistant] And when I say static it means that once you decide the size of the array, it will not change.


[User] Please transcribe this text

[Assistant] But you cannot have one more extra element. So let's say right now we have 34, 56, 6 and 7. Let's say you want to store one more value of 75. You cannot create an extra space at the runtime when the program is running to store this 75. This is not possible in an array, right?


[User] Please transcribe this text

[Assistant] So this is a major limitation when the size of the data structure is not flexible. Similarly, what if your data structure that is the array


[User] Please transcribe this text

[Assistant] Is not storing 4 values. So right now you can see we have 34, 56, 6 and 7.


[User] Please transcribe this text

[Assistant] So in that scenario, you can see that I have erased the two values. However, once you create an array of size four in the computer memory four blocks,


[User] Please transcribe this text

[Assistant] Will be reserved for this array. So regardless of whether you want to store or whether you have any data in these last two elements or not, your array will always occupy four memory blocks each for one int. And if you were to calculate, if we say four bytes for one element, we have four elements, right? So four into four equals to 16 bytes.


[User] Please transcribe this text

[Assistant] So even though right now we have only two values in the array, still,


[User] Please transcribe this text

[Assistant] The array will always occupy 16 bytes in the memory. So this is not flexible, right? This is wastage of memory.


[User] Please transcribe this text

[Assistant] So this is not efficient, right? This is wastage of two memory blocks and wastage of memory. Now I know this is just very trivial when it comes to two memory blocks and in today's time we have a lot of memory storage.


[User] Please transcribe this text

[Assistant] But this becomes a little inefficient when it comes to larger applications where a lot of flexibility of size of data structure is required. Now, how does linked list fair in this comparison?


[User] Please transcribe this text

[Assistant] So coming to the linked list, linked list has dynamic size in nature. When I say dynamic, what I mean is there is no fixed size of a linked list. Linked list can grow and shrink depending upon our requirement, depending upon the program's requirement at runtime.


[User] Please transcribe this text

[Assistant] But there is nothing written like we can only have 4 nodes. There is no rule. We didn't declare a linked list with size 4 like we did in array.


[User] Please transcribe this text

[Assistant] So whenever you want to add a new node, what you can do, you can simply create that node object. So I'll create a new node object. I'll name it N5. Let's say the address that is this created at is hash 21. Okay. Let's say the key is 5. Data being stored is 65.


[User] Please transcribe this text

[Assistant] And of course the next pointer for this is going to be null. Now simply what you have to do is,


[User] Please transcribe this text

[Assistant] In the next pointer of n4, you have to store the address of n5. Right? So this null has to be erased. And at the place of null, what do we want? We want the address of hash 21. So hash 21 would be added over here. And now,


[User] Please transcribe this text

[Assistant] This linking will be done, so n4 will start pointing to n5. And that's how you can see I have dynamically added one node.


[User] Please transcribe this text

[Assistant] Now similarly at any point in the program, let's assume that you don't really require n-phi. So you can also completely erase it out, right? So you can completely erase this out and make n-4 again point to null. So you can see now I've dynamically shrink the size. So this is one major benefit.


[User] Please transcribe this text

[Assistant] When it comes to the flexibility of size of data structure. So the size in linked list can grow and shrink depending upon the requirements. The size of array data structure cannot grow and shrink depending upon the requirements. So this is where linked list wins. Let's see the next criteria of comparison.


[User] Please transcribe this text

[Assistant] Okay, so the next criteria of comparison is data access, read, and update. So of course, in the array and linked list, we have multiple elements stored. In an array, our example is an integer array.


[User] Please transcribe this text

[Assistant] In a linked list, it is a node which is storing integer data only, so the 34, 56, 6, and 1 are all integer values. Then we also have a key.


[User] Please transcribe this text

[Assistant] And the next pointer, so we have extra information for node. But now.


[User] Please transcribe this text

[Assistant] Whenever you want to access one particular element inside the array, how do you do it? What do we want to find out is the cost. So when I say cost, it means the time complexity.


[User] Please transcribe this text

[Assistant] Now if you don't know what is time complexity, what is space complexity, we have individually discussed these two topics in very detail. Those are absolutely important. Do check them out.


[User] Please transcribe this text

[Assistant] But in general, time complexity is nothing but the time required to perform a particular operation. So in this case, the operation is data access and data read, which is pretty much one and the same thing.


[User] Please transcribe this text

[Assistant] So when you access one particular element in the array, you're basically reading it, right? So data access and read is pretty much the same.


[User] Please transcribe this text

[Assistant] And once you access that element, let's assume you want to update it.


[User] Please transcribe this text

[Assistant] So again, after that, after accessing, you also can update it then and there.


[User] Please transcribe this text

[Assistant] Which data structure is efficient when it comes to data access read and update. Okay.


[User] Please transcribe this text

[Assistant] Now talking about arrays, one advantage of array data structure is that we have random access availability.


[User] Please transcribe this text

[Assistant] So the feature and functionality of random access is available. So when I say random access, in the array, you can access any element directly. What do I mean by this?


[User] Please transcribe this text

[Assistant] So when you create an array, let's say arr of 4, what happens is this arr array basically points to the base address


[User] Please transcribe this text

[Assistant] So the first element is at index position 0. The base address of this is hash 10.


[User] Please transcribe this text

[Assistant] Now if you have any general purpose programming language knowledge and you've seen the concept of arrays, whenever you want to access one particular element, let's say I want to access this last element, what do I do? I simply say arr of 3 and let's say if I want to update it I'll say arr of 3 equals to


[User] Please transcribe this text

[Assistant] And we make the certain update, we make 7 as 75. And the updation is done.


[User] Please transcribe this text

[Assistant] So you don't really have to traverse from index position 0 to 1 to 2 and to 3, right? You can directly use the index position to access the element in the array data structure. So this is called random access, okay? So random access is nothing but


[User] Please transcribe this text

[Assistant] Now if you are wondering how this happens, as I mentioned, the array, since it is an integer array, knows the information of the base address. When I say base address, it means the address of the first element in the array.


[User] Please transcribe this text

[Assistant] Now we've already known that in array elements are stored in contiguous memory allocations.


[User] Please transcribe this text

[Assistant] So that means the next address obviously is gonna be at address hash 14.


[User] Please transcribe this text

[Assistant] And that is because it is an integer array. We just said that let's assume int data type to take 4 bytes.


[User] Please transcribe this text

[Assistant] Now depending upon what system it is, it might be 8 bytes also, but we are assuming it is 4 bytes. So,


[User] Please transcribe this text

[Assistant] If you want to access the last element, that is index position 3,


[User] Please transcribe this text

[Assistant] You can do it simply by using a formula which is given by


[User] Please transcribe this text

[Assistant] Elements of the same data type. So over here it is int, which takes four bytes. So your size of one element.


[User] Please transcribe this text

[Assistant] Plus, what is index position that we want to find out? We want to access index position 3.


[User] Please transcribe this text

[Assistant] So it is 3 into what is the size of one element that is


[User] Please transcribe this text

[Assistant] Calculate it, it is 3 4's at 12, 12 plus 10, it would be 22. And this my friends is the exact address of


[User] Please transcribe this text

[Assistant] The last element in the array. So this is how when you say arr of 3,


[User] Please transcribe this text

[Assistant] And when you want to update it to 75, what is happening at the backend is this formula is applied.


[User] Please transcribe this text

[Assistant] And then the address is found out and the value is accessed at that address and then you make the updation. So 7 is made to 75. But behind the scenes, this is what is happening. Okay?


[User] Please transcribe this text

[Assistant] So you can see data access and read is pretty fast in an array. And the cost of data access, read and update in an array is termed as constant time. So when I say constant time, O of n equals to 1.


[User] Please transcribe this text

[Assistant] We've already talked about different types of complexities and the reason why it is constant time is


[User] Please transcribe this text

[Assistant] It will take the same amount of time to access 2. It will take the same amount of time to access 1. And let's say your array has n elements.


[User] Please transcribe this text

[Assistant] The nth element also will be accessed in the same amount of time.


[User] Please transcribe this text

[Assistant] That will take to access the first element because it is a simple formula. You don't have to traverse the entire array, right? You don't have to use a loop to go from one element to other and to the next. That would take a lot of time. That would be linear time, right?


[User] Please transcribe this text

[Assistant] And that's what is gonna happen in linked list, so we'll come there. But in array, as I mentioned, since random access is possible.


[User] Please transcribe this text

[Assistant] Constant time is taken to access any element in the array, be it at the start or be it at the end.


[User] Please transcribe this text

[Assistant] Now, let's see what happens in a linked list when you have to access, read and update a particular data. Now, in a linked list, we know that the nodes are not


[User] Please transcribe this text

[Assistant] In contiguous locations, they are not right next to each other. They are, they are at random positions and hence we require this link to, you know, figure out where the next node is. So you can see in n1's next pointer, we have hash 34, hash 34 is the address of n2. Right? So that's why the linking is made.


[User] Please transcribe this text

[Assistant] Which is a separate pointer which points to the first node. So this is the first node.


[User] Please transcribe this text

[Assistant] Now what happens if I want to access N4? Now in a linked list as I mentioned, we do not have the facility and the feature of random access. Which means I cannot use any particular formula to directly jump to N4. Because obviously the addresses are random. These nodes are created at random memory addresses in the computer memory.


[User] Please transcribe this text

[Assistant] So, the only way to reach to N4 is to use this front pointer which is pointing to N1, then traverse to N2.


[User] Please transcribe this text

[Assistant] Then traverse to N3 and then traverse to N4. So you can see I have to loop through the entire linked list to access the last element. Now of course how the element will be accessed can be used by passing the key of this N4 node.


[User] Please transcribe this text

[Assistant] And that is one major reason why in our entire tutorials, we are using


[User] Please transcribe this text

[Assistant] Key field also, because we've decided that every node will have a unique key.


[User] Please transcribe this text

[Assistant] So if I want to find out a node which has the key of 3,


[User] Please transcribe this text

[Assistant] I know that n3 is the only node which will have key of 3 and no other node. So that is how I can also find out


[User] Please transcribe this text

[Assistant] Which node I want to access and update. So if I want to access a node with the key of 3.


[User] Please transcribe this text

[Assistant] I will start from the front. I will check the key of N1. N1's key is 1. Is it matching with 3? No. Then I will move forward. I will check the key of N2. I will match it with 3.


[User] Please transcribe this text

[Assistant] Is 2 equal to 3? No. Then I'll move forward and when I get a match, then I will access node entry and make the appropriate change. So let's say I want to change the data of 6 to 60. So once I access entry, I can make it to 60. Okay?


[User] Please transcribe this text

[Assistant] But here as I mentioned, random access is not possible. So what is possible is sequential access. So the only way you can access a data in linked list is by performing sequential access.


[User] Please transcribe this text

[Assistant] Now this is a time consuming task because just to access N4, you can see we have to start from N1, then go to N2, then go to N3, then go to N4. So in terms of time complexity, the Big O notation


[User] Please transcribe this text

[Assistant] For sequential access in a linked list is basically n. So n is nothing but linear time. Which means that the time required to access nth node is directly proportional


[User] Please transcribe this text

[Assistant] To the number of nodes we want to traverse, right? So let's say in the linked list we have


[User] Please transcribe this text

[Assistant] 100 nodes. And you want to access the 90th node.


[User] Please transcribe this text

[Assistant] So you'll have to go from 1 to 2 to 3 to all the way till 90.


[User] Please transcribe this text

[Assistant] So that would take time directly proportional to those 90 hops, right? Those 90 jumps. If your linked list was 1000 nodes long and you want to access 900 nodes, obviously it will take more time.


[User] Please transcribe this text

[Assistant] Then a linked list which is of size 100 and you want to access 90th node.


[User] Please transcribe this text

[Assistant] So it is directly proportional to n, right? That is the number of nodes in the linked list. So hence, it is called linear time.


[User] Please transcribe this text

[Assistant] So hence we can conclude that data access read and update is much more faster in an array data structure in most scenarios compared to data access read and update in linked list.


[User] Please transcribe this text

[Assistant] Alright, so let's move on to the next criteria of comparison.


[User] Please transcribe this text

[Assistant] So the next criteria of comparison is insertion and deletion of elements in the data structure.


[User] Please transcribe this text

[Assistant] So which data structure is better when it comes to inserting and deleting elements from it? Is it array or linked list? Let's find out. Now of course we have three different places where insertion and deletion can happen.


[User] Please transcribe this text

[Assistant] Insertion can happen at the beginning, which means at the very start. Insertion can happen at, at the end, which means at the end. So in linked list also at the start and at the end. And insertion and deletion can happen at any random nth position in between somewhere.


[User] Please transcribe this text

[Assistant] So that is also possible. So these are three different scenarios for which different cost


[User] Please transcribe this text

[Assistant] Is required and we'll figure that out in this video itself right now and hence we have three different scenarios. Alright, let's start off with arrays.


[User] Please transcribe this text

[Assistant] Okay, so in the array, let's assume we've created an integer array of size four, but right now we only have three values inside the array. The fourth memory block is idle. And now we want to insert, let's start off with insertion, we'll come to deletion later on. So when you want to insert at the beginning, you want to insert a new value, let's say the new value


[User] Please transcribe this text

[Assistant] Is 75. You want to insert this 75 at index position 0.


[User] Please transcribe this text

[Assistant] Now before you insert, what you have to do is you have to shift all these elements one place ahead, right?


[User] Please transcribe this text

[Assistant] So 56 comes in 6th place, 6th comes at index position 3, and 34 goes over here.


[User] Please transcribe this text

[Assistant] Only after shifting these values ahead,


[User] Please transcribe this text

[Assistant] Only then you can put 75 over here. So after doing that,


[User] Please transcribe this text

[Assistant] Now you can take this 75 and insert it at this place. Right?


[User] Please transcribe this text

[Assistant] But if you observe, you have to unnecessarily make these shifts happen first.


[User] Please transcribe this text

[Assistant] So again, all those 9 elements first have to be shifted. So 9 hops has to be made.


[User] Please transcribe this text

[Assistant] So inserting a new value in the array is a little time consuming.


[User] Please transcribe this text

[Assistant] Where a extra overhead is required to shift the existing elements one position ahead. So here the time required to make that shift happen is directly proportional to the


[User] Please transcribe this text

[Assistant] Size of the elements, right, in the array. So, O of n


[User] Please transcribe this text

[Assistant] Even if your array is size 10 and if you have 6 elements in it and you want to add a 7th element,


[User] Please transcribe this text

[Assistant] Those six elements have to shift one position each which means six hops are required and hence you can see that


[User] Please transcribe this text

[Assistant] That activity is directly proportional to the number of elements in the array, not the size of the array, the number of elements existing in the array.


[User] Please transcribe this text

[Assistant] So over here in our current scenario, we were having three elements and we wanted to add a fourth element 75. So first those three elements had to make three hops ahead to make space for the new element. And that is why insertion at the beginning takes linear time because


[User] Please transcribe this text

[Assistant] Those n elements which are there in the array have to be shifted one place ahead. Okay? Alright, so I hope you've got this basic thing. Okay, so now let's talk about insertion and deletion at the end.


[User] Please transcribe this text

[Assistant] So again, taking our very same example, initially let's say we have 34, 56 and 6.


[User] Please transcribe this text

[Assistant] And we want to insert a new value, 75.


[User] Please transcribe this text

[Assistant] But assume that we have memory space. You simply push that value.


[User] Please transcribe this text

[Assistant] So there is no extra effort or extra overhead over here. So over here O of n, that is Big O notation is gonna be 1 which is constant time. Okay?


[User] Please transcribe this text

[Assistant] Now talking about the last thing that is insertion and deletion at random nth position, let's say I want to insert one value at index position 1.


[User] Please transcribe this text

[Assistant] Now again the same scenario happens that when I want to push a new value, let's say I want to push 75 at this index position, which is index position 1. So obviously 56 and 6 has to go one indexes ahead, right?


[User] Please transcribe this text

[Assistant] So again there is an overhead and it is also gonna be proportional to the number of elements which have to be shifted ahead. So generally again it is given by O of n equals to n, which is linear time.


[User] Please transcribe this text

[Assistant] Now the reason why insertion and deletion at the beginning and insertion at random nth position


[User] Please transcribe this text

[Assistant] Has the same time complexity. It is because in a real world scenario, obviously it is not gonna be same.


[User] Please transcribe this text

[Assistant] The time required to insert at a random nth position is gonna be slightly less.


[User] Please transcribe this text

[Assistant] Then the time required to insert at the beginning because when you insert a new element in the beginning, all the elements have to be shifted ahead.


[User] Please transcribe this text

[Assistant] But when you want to insert at this index position, you can see we did not have to move 34. We only had to move 56 and 6. So the time will be a little less. But it is still proportional to the number of elements after that particular index position.


[User] Please transcribe this text

[Assistant] So when you consider n elements, of course it will be directly proportional to n only, and hence in a generalized way,


[User] Please transcribe this text

[Assistant] We depict O of n equals to n only. That's why it is similar and same over here. Okay. Now we've discussed how to calculate time complexity in detail.


[User] Please transcribe this text

[Assistant] In the time complexity video, so if you're still confused, do watch that. But now let's talk about deletion. So this was all about insertion. And when it comes to deletion also, the same scenario happens. So let's assume that you want to delete at the beginning. So when you want to delete 34,


[User] Please transcribe this text

[Assistant] When you delete this 34, what happens is, now you have to shift


[User] Please transcribe this text

[Assistant] This 56 over here and this 6 over here, right? So again, shifting has to be done.


[User] Please transcribe this text

[Assistant] Because the first element is deleted. Deletion at the beginning means deleting the first value in the array. Once you delete the first element, obviously,


[User] Please transcribe this text

[Assistant] 56 becomes the first element, so it has to go at the index position 0 only to maintain the consistency.


[User] Please transcribe this text

[Assistant] So that's why 56 will be shifted one position back, then 6 will be shifted one position back, and if you have n elements in the array, n hops will be required and that's why again the O of n for deletion also is linear. That is n. Similarly, deletion at the end will not require any extra overhead, so again,


[User] Please transcribe this text

[Assistant] Let's say we have one value 75 over here, and you want to delete it at the end, you simply go to that place and you delete it. Do you have to make any switches to the existing elements? No. So, deletion at the end requires constant time.


[User] Please transcribe this text

[Assistant] And lastly again, deletion at random end position also will require linear time because if you delete 56,


[User] Please transcribe this text

[Assistant] You'll have to switch or shift 6 over here.


[User] Please transcribe this text

[Assistant] So every element ahead of 56, if you have n elements, they require n hops. So that's why.


[User] Please transcribe this text

[Assistant] It is also directly proportional to the number of elements ahead of that position, right? Hence, it is also linear in nature that is equal to n.


[User] Please transcribe this text

[Assistant] So I hope I'm making sense. And now that we've completely computed the cost of insertion and deletion of elements in an array,


[User] Please transcribe this text

[Assistant] In these three different scenarios, let's see the cost of insertion and deletion of elements in a linked list. Now in a linked list we already know that nodes can be dynamically added and dynamically deleted at any point and the size is flexible, which means it can grow and shrink. So talking about insertion at the beginning, the only thing that you have to do is


[User] Please transcribe this text

[Assistant] You simply have to take a new node, let's say this is nphi, with a key value of 5, which is created at address 10 and


[User] Please transcribe this text

[Assistant] The data is 75, you have to take this new node and what you have to do is you have to simply say


[User] Please transcribe this text

[Assistant] This front will now start pointing to N5. N1's address which is hash12 has to be stored over here. So hash12 will be stored over here.


[User] Please transcribe this text

[Assistant] And the new front value will now be n-phi. So front will start pointing to n-phi. You can see eh, front is now pointing to n-phi.


[User] Please transcribe this text

[Assistant] So over here we did not have to go through N1, N2, N3, N4 or we did not have to run through a loop. We simply had to take this node N5.


[User] Please transcribe this text

[Assistant] And make this linking happen and make the front pointer point to this new node nphi. Because nphi now becomes the front of this linked list because we are inserting at the beginning.


[User] Please transcribe this text

[Assistant] Now these three steps of creating N5, then N5 pointing to N1, and then the front pointing to this new node N5 will have constant time, right? So every time you want to add a new node,


[User] Please transcribe this text

[Assistant] The same process is followed which means now you will simply say front will start pointing back to n1. So you erase this link and then you can simply delete this node and now n1 becomes the front.


[User] Please transcribe this text

[Assistant] So every time you want to delete one node from the front,


[User] Please transcribe this text

[Assistant] You simply have to make the front pointer point to the next node.


[User] Please transcribe this text

[Assistant] So that is also gonna take constant time, right? So you don't have to iterate through the entire list. You don't have to run any loops.


[User] Please transcribe this text

[Assistant] So again, deletion at the beginning also takes constant time, so O of n is 1 for both insertion and deletion. Okay? Alright. Now let's talk about insertion and deletion at the end. Now this is where the traversal of the entire linked list is required.


[User] Please transcribe this text

[Assistant] Now remember in linked list, as we know, nodes are created at random positions. We can only access directly N1 using the front pointer. But since we want to insert a new node at the end,


[User] Please transcribe this text

[Assistant] And now what we want to do, we want to make N4 point to N5. N4 currently has null over here.


[User] Please transcribe this text

[Assistant] But when you want to insert or delete at the end, let's talk about insert first. We will have to traverse till the end using the front pointer. So the front pointer right now is pointing to N1.


[User] Please transcribe this text

[Assistant] You'll have to go over here, then you'll have to go over here, then you'll have to go over here, and when you reach the end, the last node obviously will have null in its next pointer, so that's where you stop.


[User] Please transcribe this text

[Assistant] The looping and you determine that now, okay, now you're at the end, but you can see you require


[User] Please transcribe this text

[Assistant] So you require 100 hops or 100 iterations to reach the end, starting from the front node.


[User] Please transcribe this text

[Assistant] So over here, inserting a new node at the end.


[User] Please transcribe this text

[Assistant] is directly proportional to the size of the linked list which is the number of nodes.


[User] Please transcribe this text

[Assistant] In the next pointer of n5, we have null which means we've arrived at the last node. Then you can easily delete this out.


[User] Please transcribe this text

[Assistant] So again, deletion also requires linear time, which is directly proportional to n.


[User] Please transcribe this text

[Assistant] Because you have to traverse, you cannot directly jump to the end. Alright?


[User] Please transcribe this text

[Assistant] Random nth position, let's say you want to insert a new node in between. Again, you'll at least have to traverse


[User] Please transcribe this text

[Assistant] Till that point, right? So, if you want to insert a new node between N2 and N3, you will have to start from N1, you will have to go to N2.


[User] Please transcribe this text

[Assistant] How the linking happens we've discussed in linked list in detail. But right now what I'm trying to say is, when you want to insert or delete a node in a random position in between,


[User] Please transcribe this text

[Assistant] Again, it is directly proportional to the linear time, which is n hops are required to reach that position.


[User] Please transcribe this text

[Assistant] So let's say you have 1000 elements or 1000 nodes and you want to enter a new node at the 50th position. So you'll have to make 50 hops to reach that position, right?


[User] Please transcribe this text

[Assistant] So that's why again O of n is directly proportional to n.


[User] Please transcribe this text

[Assistant] And this n represents the hops required to reach that particular position. Okay. So again, this is linear.


[User] Please transcribe this text

[Assistant] So now if you compare both arrays and linked list, it is pretty much a tie when it comes to insertion and deletion at the end. The array is much more efficient with constant time when it comes to insertion and deletion at the beginning.


[User] Please transcribe this text

[Assistant] Seems like the node is efficient with constant time.


[User] Please transcribe this text

[Assistant] And otherwise it is n and n, which is linear time. So it's pretty much a tie over here.


[User] Please transcribe this text

[Assistant] And I hope you got a good idea about insertion and deletion of elements with these both different data structures.


[User] Please transcribe this text

[Assistant] Okay so the next criteria is related to memory requirement and memory usage and efficiency. So these are two separate terms and separate things but I've clubbed them together because they are both related to memory and we'll understand them better


[User] Please transcribe this text

[Assistant] When we take them or club them together. So let's talk about arrays when it comes to memory requirement.


[User] Please transcribe this text

[Assistant] So over here we've declared an int array of size 4 and considering int data type to take 4 bytes, we can easily


[User] Please transcribe this text

[Assistant] Now let's take the similar scenario in linked list. Okay. So in a linked list,


[User] Please transcribe this text

[Assistant] Int is gonna take 4 bytes. In a node n1,


[User] Please transcribe this text

[Assistant] There are two elements, which is the key, which is 1.


[User] Please transcribe this text

[Assistant] And which is the data that is 34. So there are two integer elements, which means we already have 8 bytes plus we also have one pointer.


[User] Please transcribe this text

[Assistant] Now clearly, just by observing these two values, 16 bytes and 48 bytes, you can see that array is using much less memory to store the same data. You know, you can see the same data is stored. We are storing integer data, 34, 56, 6 and 7. In the nodes also, we are storing 34, 56, 6 and let's assume this is 7. Okay, I made it 1, let's take it 7. But clearly, storing the same integer values in a linked list, it is taking more data.


[User] Please transcribe this text

[Assistant] So you might conclude that okay, arrays are much more better, right? But that is not true.


[User] Please transcribe this text

[Assistant] That is because in array, the size of the array is fixed. And right now, since the array was having all the, you know, index positions filled with data, we could conclude that array is better than linked list. Now, imagine if the array was of size 100. So, arr of 100. Okay.


[User] Please transcribe this text

[Assistant] So 100 integer data type elements will require how, how much memory? So 4 into 100, right? So that would be 400 bytes.


[User] Please transcribe this text

[Assistant] So let's see we create an array of size 100. However, in the array we are only currently having 4 elements filled and rest of them are all blank. We created the array


[User] Please transcribe this text

[Assistant] And we gave the static size in the start of the program because we didn't know how many number of elements we are gonna store in array. So that's why we gave a large value. And generally that is what happens, right? So let's say initially we only have 34, 56, 6 and 7.


[User] Please transcribe this text

[Assistant] Rest of all the 96 blocks are going to waste because in the computer memory obviously 400 bytes are only gonna be used. And now if you compare this with the linked list, remember in linked list,


[User] Please transcribe this text

[Assistant] Depending upon the requirement, the nodes are created. So now we have 4 values in the array, but the array size is 100. So that's why it is taking 400 bytes. But if you compare the linked list, we have 4 values in the linked list, that is 4 nodes, and we are taking only 48 bytes. So now the linked list is more efficient.


[User] Please transcribe this text

[Assistant] So that's where memory usage and efficiency comes into picture. So now you can see, linked list is faring better. So it all depends upon the situation.


[User] Please transcribe this text

[Assistant] Another use case can be shown as, let's assume or let's imagine that the array is not of integer data type.


[User] Please transcribe this text

[Assistant] Let's say you are creating a class. I'll show the class on the screen. Let's say you are creating a person class.


[User] Please transcribe this text

[Assistant] It has name, which is a character array of size 10. It has age, which is an integer type. And it has salary. Let's assume also as integer type.


[User] Please transcribe this text

[Assistant] So collectively when you create a person object, so person obj,


[User] Please transcribe this text

[Assistant] The size of one OBJ object in the memory is 10 bytes of the character array name plus 4 bytes of age and plus 4 bytes of salary which is going to be 18 bytes. Alright.


[User] Please transcribe this text

[Assistant] But let's say you create an array of person obj. You can also create an array of objects, right? So let's say you say person obj. You say 100. So you are creating a person obj array of size 100. So that would require 18 bytes.


[User] Please transcribe this text

[Assistant] When you create an array of object of size 100, so 18 x 100, we will have 1800 bytes. And imagine if you are only storing three elements or three person objects, which means you are only utilizing 18 x 3, which is 54 bytes. Okay. Now take the same scenario in the linked list side. You create three nodes, n1, n2,


[User] Please transcribe this text

[Assistant] So n1 is not gonna store integer, it is going to store a person object. So n1 already has


[User] Please transcribe this text

[Assistant] One extra key which is taking 4 bytes plus this person object which we just concluded which takes 18 bytes, so 18 bytes.


[User] Please transcribe this text

[Assistant] Now the reason why you gave 100 sizes is because in the program you don't know how many number of objects will be added at runtime. So just to be on the safe side, you gave 100.


[User] Please transcribe this text

[Assistant] Which means in the memory you've blocked 1800 bytes of memory.


[User] Please transcribe this text

[Assistant] But in reality, if you would have used a linked list, you would have only utilized 78 bytes when you create three nodes. So now you can see there is a considerable difference. 1800 is much more larger than 78. You're wasting a lot of memory when you create a person object array, which is


[User] Please transcribe this text

[Assistant] Which means one node over here was taking 12 bytes, one element in the integer array was taking only 4 bytes. But when it comes to a larger application, that is when it comes to memory usage and efficiency, since linked list can


[User] Please transcribe this text

[Assistant] Add and delete nodes dynamically at runtime depending upon whether you need or not. You're not gonna waste any kind of memory.


[User] Please transcribe this text

[Assistant] In arrays, you can see that since we don't know how many number of elements are supposed to be added, if you give extra size, that size is wasted.


[User] Please transcribe this text

[Assistant] If you give less size and let's say you want to store extra elements, then you'll have to recreate a new array with a larger size. So that's another problem.


[User] Please transcribe this text

[Assistant] So I hope you've got an overall picture of memory requirement and memory usage. These are two separate terms.


[User] Please transcribe this text

[Assistant] And how they are applied in an array or in a linked list. So it's pretty much a tie over here and as I mentioned again it depends upon the application and depends upon the condition. If you want to store


[User] Please transcribe this text

[Assistant] If you are working with complex data types and if you don't know how many number of elements are required at any given point in the program, then you are better off with linked list and you'll save a lot of memory. So again, depends upon the condition. Okay, so let's move on to the next criteria.


[User] Please transcribe this text

[Assistant] The next criteria is pretty basic, which is ease of use.


[User] Please transcribe this text

[Assistant] Now of course, ease of use has to be given hands down to arrays. Arrays are much more easier to use. When it comes to a linked list, it is a little tedious because you have to make these linkings yourself. When it comes to C and C++ programming, you're dealing with pointers and a lot of memory leaks can happen. And you have to write a lot of code to manage these linked lists. So hence,


[User] Please transcribe this text

[Assistant] Arrays are much more easier to use. You can directly create an array. You don't really have to write a separate class also when you want to, you know, utilize arrays.


[User] Please transcribe this text

[Assistant] In linked list, you'll have to create your own class or use some other library for linked list.


[User] Please transcribe this text

[Assistant] So ease of use is hands down given to arrays. Let's move on to the last criteria.


[User] Please transcribe this text

[Assistant] The last criteria is searching methods. So when it comes to searching an array, you can have two different types. You have sequential search. You can also have binary search.


[User] Please transcribe this text

[Assistant] And you can also do the mapping of indexes. So if you already know the index, you can directly go to that. So random access is also possible. But when it comes to linked list, you cannot do binary search.


[User] Please transcribe this text

[Assistant] You'll have to compare key of N1, you'll have to compare key of N2, then N3 and keep on jumping till you find a node with the same key of 4. So that's why in searching,


[User] Please transcribe this text

[Assistant] Linklist has a clear drawback, which has only sequential search. Okay. Please don't mind my handwriting. I always had a very bad handwriting, but yeah, you get the point, right?


[User] Please transcribe this text

[Assistant] So these were the different conditions, these were the different criteria on which we can make a comparison between arrays and linked list and ultimately we come to the same conclusion which I initially mentioned that there is no such thing as


[User] Please transcribe this text

[Assistant] It is depending upon your requirement, depending upon the program conditions and the logic that you have to select that appropriate data structure. Okay.


[User] Please transcribe this text

[Assistant] So each and every data structure is unique and has its own pros and cons and you have to select them accordingly.


[User] Please transcribe this text

[Assistant] Okay so that's it for this video guys, I'm gonna conclude it over here, I know it was a little lengthy but it was important and a detailed


[User] Please transcribe this text

[Assistant] I hope you've understood all the different parameters. If you liked this video, if you understood it, please give this video a like. Let me know in the comments how this video was. If you have any queries, you can put them in the comments. Do share this video with your friends. This is an important one.


[User] Please transcribe this text

[Assistant] And I'm gonna wrap this video over here. So thanks for watching. See you in the next one. Peace.


[User] Please transcribe this text

[Assistant] Well, that's just completely off the point. Don't worry.


[User] Please transcribe this text

[Assistant] He's a time strap. Your friend hides him with the enemy.


[User] Please transcribe this text

[Assistant] There's a Durmstrang. You'll fraternise him with the enemy.


[User] Please transcribe this text

[Assistant] Lily, you squeaked? She said something about me, didn't she? Come on, spill it, Red!


[User] Please transcribe this text

[Assistant] Cause it's a game. I wanted to skip to the end and do the whole happily ever after thing. But you don't get there unless you play the game. So you gonna ask her out?


[User] Please transcribe this text

[Assistant] Oh, you know, just, uh, shopping for a dip.


[User] Please transcribe this text

[Assistant] Think of something else muscles help you do. Draw a picture and write about it. Science.


[User] Please transcribe this text

[Assistant] Back at the bar, Girls Night Out wasn't going as Robin had hoped.


[User] Please transcribe this text

[Assistant] So it turned out Uncle Marshall really was the jealous type. Unfortunately, that guy's boyfriend? Also the jealous type.


[User] Please transcribe this text

[Assistant] And that was when I realized why I hung out with Barney. I never got where I thought I wanted to go, but I always got a great story.


[User] Please transcribe this text

[Assistant] Kids, every story in a man's life is like a dot in an impressionist painting. And when you- So that's a no? Yeah, that's a no. What? Come on.


[User] Please transcribe this text

[Assistant] I think there's a fire and did you see all the lane was on the right waiting for the fire truck to pass? It's a law in the US.


[User] Please transcribe this text

[Assistant] Uhm, the FedEx office is uhm, it's like UPS, FedEx, you know, for mailing stuff. You can do it internationally, or you can do it like same day within the same city.


[User] Please transcribe this text

[Assistant] Okay, we're almost there, you can kinda tell. It's already really Japanese. You start seeing characters everywhere, a lot of sushi bars.


[User] Please transcribe this text

[Assistant] Ask pedestrians what they think is most representative of Little Tokyo. Okay, so what they like about Little Tokyo. Okay, take the card. Here I go. Alright.


[User] Please transcribe this text

[Assistant] Kula Rava Sushi Bar, right here. Okay, sounds good. Thank you guys so much.


[User] Please transcribe this text

[Assistant] So right here there's a revolving sushi bar.


[User] Please transcribe this text

[Assistant] They, it's a restaurant, they have, uh, beef bowl, they have sushi, they have ramen. Specialty is ramen. Okay, so our...


[User] Please transcribe this text

[Assistant] Did you, was the one you referred to Daikokuya? Cause a couple of them said that too.


[User] Please transcribe this text

[Assistant] There were two dads. See, more and more, uhm,


[User] Please transcribe this text

[Assistant] You know, same-sex couples, uhm, using, you know, high-tech and, you know, medical technology to have babies, which is really, really awesome, and that's what we saw. So, I love that. It's awesome. Okay. It is, uh, food truck.


[User] Please transcribe this text

[Assistant] I really like little Tokyo. We had a lot of nice little snacks, saw a lot of cute things, and I even got to interview people. Oh, by the way, give me my pass card for that. And uhm, yeaah, I think.


[User] Please transcribe this text

[Assistant] Today's a good day. Need to wrap it up. Are you guys hungry? Yes. Yeah, okay. Well, we can probably hop in the car and go get some dinner. Alright. Long day.


[User] Please transcribe this text

[Assistant] Hidden deep in the mountains of western China's Sichuan province, there is a primitive and dreamy valley called Zhoujiaigou.


[User] Please transcribe this text

[Assistant] It has preserved one of the most stunning view of nature.


[User] Please transcribe this text

[Assistant] The secret of colouring the lake is the Spirogyra, Charophyte, and other kinds of ferns that grow in the water.


[User] Please transcribe this text

[Assistant] These colors vary according to the season, light, and viewing angle.


[User] Please transcribe this text

[Assistant] Besides these magical lakes, Zhoujiaigou also has China's widest waterfall, Nuorilang Waterfall, with a width of 270 meters.


[User] Please transcribe this text

[Assistant] If you visit Jojai Go during the right time, you may even experience the rotation of four seasons in one day.


[User] Please transcribe this text

[Assistant] From the colourful scene to the white appearance, Jojai Goh could do it in very short time.


[User] Please transcribe this text

[Assistant] This smells so dirty.


[User] Please transcribe this text

[Assistant] Hello, boys and girls. My name is Larry. And today, we will study Brain Bank Science Book Number 18. The title of this book is Tunnels. Tunnels. Now, a tunnel is a passage. In Korean, you can say, 통로. 통로. And tunnels go through


[User] Please transcribe this text

[Assistant] Many different things. Mountains. Maybe they go through the road. Maybe they go under the earth. Maybe they go under buildings.


[User] Please transcribe this text

[Assistant] We're going to learn a lot of different kinds of tunnels. Look at this picture. Is this a mountain? Hmm. Maybe it's the side of a mountain. If we did not build a tunnel, we would have to drive all the way around. That could be very difficult.


[User] Please transcribe this text

[Assistant] We can drive our car through this tunnel.


[User] Please transcribe this text

[Assistant] Let's learn more about tunnels.


[User] Please transcribe this text

[Assistant] We're going to learn about tunnels for traveling.


[User] Please transcribe this text

[Assistant] That was like the picture you just saw.


[User] Please transcribe this text

[Assistant] Driving or walking some place, we often have to go through a tunnel.


[User] Please transcribe this text

[Assistant] These are tunnels built for some kind of specific purpose, not traveling. Tunnels for safety. Sometimes we build tunnels


[User] Please transcribe this text

[Assistant] To protect people or animals.


[User] Please transcribe this text

[Assistant] Planning tunnels. Hmm, where should we build it? How big should it be? Should it be long or short? Should it be high or should it be shallow? This is planning. And then, how do we build it? What equipment do we use?


[User] Please transcribe this text

[Assistant] And then we can test two tunnels and review some very important vocabulary in the glossary. Are you ready? Let's get started. Look at these tunnels. We have a tunnel here. What is going through the tunnel? A car. Now this is a hill.


[User] Please transcribe this text

[Assistant] So the tunnel goes through the hill. If there was no tunnel, we would have to drive over the hill. Here we have a train tunnel. The train is coming through the tunnel. You can see the train tracks there.


[User] Please transcribe this text

[Assistant] This is a very special kind of tunnel. Where is this? In the mountains? No.


[User] Please transcribe this text

[Assistant] This tunnel is under the water.


[User] Please transcribe this text

[Assistant] And you can see many different kinds of fish.


[User] Please transcribe this text

[Assistant] So we have three very different kinds of tunnels, used for different things.


[User] Please transcribe this text

[Assistant] Tunnels go under the ground. Right here. They go through the mountains. Could be this picture and this picture. They go underwater too. In this picture here. If there was no tunnel, these people would be swimming in the water.


[User] Please transcribe this text

[Assistant] Now we will learn about tunnels for travel. Travel.


[User] Please transcribe this text

[Assistant] Moving from one place to another place. One place to another. In this first picture, we can see a boat. B-O-A-T. Boat. This tunnel


[User] Please transcribe this text

[Assistant] We build tunnels so the subway can go through them. Just like in your city. How about this one? How are people traveling here? Hmm. Are they on a boat?


[User] Please transcribe this text

[Assistant] Are they in a subway? No.


[User] Please transcribe this text

[Assistant] Are they in a car? Yes, they are traveling by car. How many tunnels can you count? One, two, three. There are three tunnels.


[User] Please transcribe this text

[Assistant] Put on your reading glasses and let's read about these tunnels.


[User] Please transcribe this text

[Assistant] Tunnels carry cars and trains. Cars and trains.


[User] Please transcribe this text

[Assistant] This is a special kind of train called a subway train.


[User] Please transcribe this text

[Assistant] They carry boats too, in this picture. They make travel easier. Easier. It is easier to go through the tunnel than over the mountain.


[User] Please transcribe this text

[Assistant] That's why we build tunnels, to make it easier to travel. The next time you travel, look for some tunnels. Let's continue with our story.


[User] Please transcribe this text

[Assistant] These tunnels are called service tunnels. One, two, three.


[User] Please transcribe this text

[Assistant] We do not use these tunnels for travel.


[User] Please transcribe this text

[Assistant] You will not see any cars or boats or trains in these tunnels. We can use these tunnels for work. W O R K


[User] Please transcribe this text

[Assistant] Work tunnels or service tunnels. Let's read about these tunnels.


[User] Please transcribe this text

[Assistant] See, you can see the water here. This brings water to the city and also away from the cities. Tunnels carry power cables. Power cables. This one's a little bit difficult. A or B. Power cables are usually very big. Which one do you think? A or B?


[User] Please transcribe this text

[Assistant] This one. These are big power cables.


[User] Please transcribe this text

[Assistant] They bring electricity to your home.


[User] Please transcribe this text

[Assistant] Meaning tunnels carry telephone cables too. Telephone cables. In this one here.


[User] Please transcribe this text

[Assistant] There's many different wires that you can see in this picture.


[User] Please transcribe this text

[Assistant] These tunnels are called service tunnels.


[User] Please transcribe this text

[Assistant] They're providing some kind of service to us.


[User] Please transcribe this text

[Assistant] Or we can call them also work tunnels. This tunnel here, do you see this picture?


[User] Please transcribe this text

[Assistant] Is this a service tunnel? Hmm. Let's look at the picture more closely. I can see a car. Are there cars in these pictures? No.


[User] Please transcribe this text

[Assistant] Do you remember what kind of tunnel this is? Very good. This is called a travel tunnel.


[User] Please transcribe this text

[Assistant] These are called service tunnels. We finished part one of our book.


[User] Please transcribe this text

[Assistant] We've learned about travel tunnels and service tunnels.


[User] Please transcribe this text

[Assistant] I'll see you again very shortly for part two.


[User] Please transcribe this text

[Assistant] Welcome back to part two of the book Tunnels.


[User] Please transcribe this text

[Assistant] In part one, we learned about tunnels for travel.


[User] Please transcribe this text

[Assistant] And tunnels for service, or service tunnels.


[User] Please transcribe this text

[Assistant] Now, in this part, we will learn about tunnels for safety. For safety. To be safe. What does that mean?


[User] Please transcribe this text

[Assistant] It means we want to protect someone or something from danger.


[User] Please transcribe this text

[Assistant] So we use tunnels to protect people or animals from danger. We keep them safe. S, A, F, E. Safe. Let's look at our three different tunnels. Can you see what's in that picture? A little bit small, but we can see some crabs. Crabs.


[User] Please transcribe this text

[Assistant] In this picture, we have many what? Children. Children. So here, we want the crabs to be safe.


[User] Please transcribe this text

[Assistant] Here, we want the children or people to be safe. In this one, you can see horses and cowboys on the horses and the road above.


[User] Please transcribe this text

[Assistant] We want to keep the horses, the animals, and the people safe.


[User] Please transcribe this text

[Assistant] Put on your reading glasses and let's read from the book.


[User] Please transcribe this text

[Assistant] Some tunnels go under busy roads.


[User] Please transcribe this text

[Assistant] This tunnel is going under a busy road. You can see the car on top.


[User] Please transcribe this text

[Assistant] They let people cross roads safely. Safely.


[User] Please transcribe this text

[Assistant] If I have to walk across this road, maybe I will get hit by a car.


[User] Please transcribe this text

[Assistant] So they build a tunnel under the road to keep people safe.


[User] Please transcribe this text

[Assistant] Maybe you have tunnels like this in your hometown.


[User] Please transcribe this text

[Assistant] Some tunnels let animals cross safely too. Let's move on to the next picture.


[User] Please transcribe this text

[Assistant] Now we can really see the tunnel for the crabs. Tunnels for safety. Here we have a special road.


[User] Please transcribe this text

[Assistant] Maybe we can even call that a bridge.


[User] Please transcribe this text

[Assistant] And here is the tunnel, and there are the crabs. The crab crossing.


[User] Please transcribe this text

[Assistant] So now the crabs can travel safely from here, over there, or from over there to here. They will not get hit by a car.


[User] Please transcribe this text

[Assistant] Okay, now when we build a tunnel, we have to plan first. We cannot just build the tunnel. So planning tunnels. Hmm. We have men in this picture.


[User] Please transcribe this text

[Assistant] We have two men in this picture and a big piece of machinery. Do you know how to plan a tunnel? I don't. Let's read how to plan a tunnel.


[User] Please transcribe this text

[Assistant] Engineers plan tunnels. Engineer? What's an engineer? An engineer is a person.


[User] Please transcribe this text

[Assistant] So these men might be engineers. I am a teacher. They are engineers.


[User] Please transcribe this text

[Assistant] No, they look at it. They make sure you can build a tunnel in that ground. If the ground is too soft, maybe you cannot build a tunnel. If the ground is too hard,


[User] Please transcribe this text

[Assistant] Maybe you cannot build a tunnel. They take rock samples.


[User] Please transcribe this text

[Assistant] Check it to see if they can build a tunnel in or through that rock.


[User] Please transcribe this text

[Assistant] They also, they take soil samples. Soil. Soil is the dirt. So we're taking samples of rock, samples of soil. These together are the ground. Soil, rock,


[User] Please transcribe this text

[Assistant] Maybe some creatures or leaves, all different parts of the ground.


[User] Please transcribe this text

[Assistant] The engineer does all of this.


[User] Please transcribe this text

[Assistant] The engineer must say, okay, you can begin working. If the engineer says no, they don't build a tunnel.


[User] Please transcribe this text

[Assistant] They turn on the machines like this and they start digging using a shovel.


[User] Please transcribe this text

[Assistant] If you build a tunnel with a shovel, like that, that will take a very long time.


[User] Please transcribe this text

[Assistant] So they use machines here and here.


[User] Please transcribe this text

[Assistant] To build a tunner, tunnel much more quickly.


[User] Please transcribe this text

[Assistant] And you can see they're building a circular tunnel here.


[User] Please transcribe this text

[Assistant] We have finished part two of our tunnel book.


[User] Please transcribe this text

[Assistant] We learned about tunnels for safety and planning tunnels.


[User] Please transcribe this text

[Assistant] I'll see you again very shortly for part three.


[User] Please transcribe this text

[Assistant] Welcome back to part three of the book Tunnels. In part one, what did we learn? We learned about


[User] Please transcribe this text

[Assistant] Travel tunnels for cars, boats, and people.


[User] Please transcribe this text

[Assistant] And we also learned about service tunnels.


[User] Please transcribe this text

[Assistant] Where water might go through or cables or wires. Then in part two, what did you learn? We learned about tunnels for safety.


[User] Please transcribe this text

[Assistant] Do you remember the crabs? We want to make sure the crabs and people and animals can cross safely under the road. Then we learn planning to build a tunnel. Do you remember what those people are called who plan? Very good. Engineers. Now we will learn building tunnels.


[User] Please transcribe this text

[Assistant] Look at all of these people. Wow. Look at that machine. Can you see in these pictures? They're all wearing a white hat. Hmm. Why are they wearing a white hat?


[User] Please transcribe this text

[Assistant] Is it bigger than a car? Yes. Now, can you see a shape in these tunnels? Are these shape, these tunnels square? Do they look square to you?


[User] Please transcribe this text

[Assistant] We'll find out why most tunnels are shaped like this.


[User] Please transcribe this text

[Assistant] Do you have your reading glasses? Let's read the story.


[User] Please transcribe this text

[Assistant] Many workers help build a tunnel. Can you count all of them? Maybe 20 or 30. That's a lot of people.


[User] Please transcribe this text

[Assistant] Sometimes they dig at both ends. Hmm.


[User] Please transcribe this text

[Assistant] So one group of workers start here. The other group of workers start here.


[User] Please transcribe this text

[Assistant] And they dig, dig, dig, dig, dig, and then they meet in the middle. Wow, that's pretty cool.


[User] Please transcribe this text

[Assistant] There are four men building that tunnel. Let's continue reading the story.


[User] Please transcribe this text

[Assistant] Now we get to practice making your very own tunnel. This will be a test to tunnels.


[User] Please transcribe this text

[Assistant] So you will build two different kinds of tunnels. They will look a little bit different. This is what you will need. You need card stock. This is heavy paper. You will need at least two pieces. You need four heavy books. One, two, three,


[User] Please transcribe this text

[Assistant] You need a pair of scissors, one pair of scissors, and some molding clay.


[User] Please transcribe this text

[Assistant] You can remember the name because you can see the letter A, arch. Now, let's look at these colors. What color is this arch? Very good, it's red. And you can see the books here. One yellow book, one green book, one purple book, and one blue book.


[User] Please transcribe this text

[Assistant] Now what is the boy putting on top of the arch? What is that? Is that a little book? No. That is the molding clay. Molding clay.


[User] Please transcribe this text

[Assistant] Okay, which shape do you think is stronger?


[User] Please transcribe this text

[Assistant] Which shape is stronger? We have an arch here. Do you remember how to spell arch? A R C H What shape is this? This is a kind of rectangle.


[User] Please transcribe this text

[Assistant] So which shape do you think is stronger? Arch or rectangle? And we can ask this question in just a minute.


[User] Please transcribe this text

[Assistant] The first thing we have to do to build our two tunnels, cut two strips of card stock. Two.


[User] Please transcribe this text

[Assistant] Make them the same size. Same size.


[User] Please transcribe this text

[Assistant] Bend one strip into an arch. Like this.


[User] Please transcribe this text

[Assistant] Put it between the two books. One, two.


[User] Please transcribe this text

[Assistant] Fold one strip into a rectangle. Put it between, in between two books. One book, two books. Different shapes.


[User] Please transcribe this text

[Assistant] Break the clay into little bits. Little bits. Small pieces. Small pieces.


[User] Please transcribe this text

[Assistant] Make them the same size. Try and make all of the pieces the same size.


[User] Please transcribe this text

[Assistant] Put some bits on the arch. Right up here. Put some there. Put some there.


[User] Please transcribe this text

[Assistant] And put some bits on the rectangle, here. Okay, you can see these two pictures.


[User] Please transcribe this text

[Assistant] Now why do you think most tunnels look like this?


[User] Please transcribe this text

[Assistant] You saw in all the pictures they looked like a circle or they had an arch. Why? Why don't tunnels look like that? Because this shape is stronger. Much stronger than this shape.


[User] Please transcribe this text

[Assistant] Okay, so we try and make tunnels that look like arches or circular in shape.


[User] Please transcribe this text

[Assistant] Let's go over some very important vocabulary from the book Tunnels. The first word is arch. Remember how to spell it because you can see the letter A.


[User] Please transcribe this text

[Assistant] It is a shape that is rounded at the top. Rounded. Or you can say curved. Curved.


[User] Please transcribe this text

[Assistant] Remember we saw the cables in the service tunnels. Service tunnels.


[User] Please transcribe this text

[Assistant] A cable is a wire used to carry telephone lines or electricity.


[User] Please transcribe this text

[Assistant] So if you have electricity in your home, there are cables that go to your home from someplace far away. An engineer. Am I an engineer? I am a teacher. An engineer


[User] Please transcribe this text

[Assistant] That bridge was with the travel tunnels and there were three of those tunnels and the cars were driving on the bridge. We saw some of them. And we saw many tunnels. Can you remember?


[User] Please transcribe this text

[Assistant] All of the tunnels, what kinds of tunnels we learn? Number one, travel tunnels. Travel tunnel. Number two, service tunnels. Service tunnels. And number three, tunnels for safety. Tunnels for safety.


[User] Please transcribe this text

[Assistant] The last word, sample. A sample. A small amount of something.


[User] Please transcribe this text

[Assistant] This can be rocks, or dirt, or soil. Maybe even food. If you are eating some food, maybe you're eating, uh, Jayoktokbap, and I want to try some of your food, I will take a little sample and say thank you.


[User] Please transcribe this text

[Assistant] We have finished our book about tunnels.


[User] Please transcribe this text

[Assistant] I will see you in the next book. Have a great day. Goodbye!


[User] Please transcribe this text

[Assistant] Hey, what's going on guys? Tanmay here for simple snippets and welcome back to another video tutorial on data structures and algorithms. And we're going to continue with our binary search tree data structure. And today as the title of the video suggests, we're going to take a look at the insertion operation. So if you've missed any of the previous tutorials from this playlist,


[User] Please transcribe this text

[Assistant] In the last two tutorials, we've started with the topic of binary search tree.


[User] Please transcribe this text

[Assistant] We've taken an overview of what is a binary search tree, how is it different from a regular binary tree, and we also started the implementation in the previous video.


[User] Please transcribe this text

[Assistant] Wherein we took a look at the approach that we are gonna take, which is going to be the dynamic node creation in the memory approach.


[User] Please transcribe this text

[Assistant] And we also saw the BST class, we also saw the tree node class.


[User] Please transcribe this text

[Assistant] And we also wrote a little bit of C++ code because we started with the implementation that is the practical side. So if you've missed any of the previous tutorials, please watch those first. This is like the continuation of those videos.


[User] Please transcribe this text

[Assistant] If you have already seen those, you're good to go. Things are gonna be very easy. And without further ado, let's get started.


[User] Please transcribe this text

[Assistant] If you're new to my channel, my name is Tanmay Sakpal and I do a lot of computer science and information technology video tutorials like computer programming, development, technology talks and a lot more on this channel. So if that's something you're interested into, then definitely subscribe and turn on the notifications to get the latest updates and never miss out on such important topics. Okay, so today we're going to talk about insertion.


[User] Please transcribe this text

[Assistant] To convert this pseudo code which you can see on the left into a proper program. Okay, so make sure you watch this video till the end.


[User] Please transcribe this text

[Assistant] If you want to have both theory working as well as the practical knowledge.


[User] Please transcribe this text

[Assistant] So before we dry run the pseudo code, a quick recap of our approach. And on the left hand side, you can see this is a binary tree, which is represented using


[User] Please transcribe this text

[Assistant] Dynamic nodes in the memory. So this is what a particular node or a typical node would look like. So this is the name n1. This is hash 10 which is the memory in which this node is created.


[User] Please transcribe this text

[Assistant] Now of course this memory is just imaginary. It's not actual address, but we are taking it for representation purpose. Now taking a look at the node, it would have the value.


[User] Please transcribe this text

[Assistant] It is also known as data or it is also known as key. Okay.


[User] Please transcribe this text

[Assistant] And then the node will have a left pointer and a right pointer which as the name suggests would point to the left child and the right child.


[User] Please transcribe this text

[Assistant] The data members as you can see are integer value, which is the center part, then


[User] Please transcribe this text

[Assistant] Tree node star left, which means that this is a pointer and we are talking about pointers because we're gonna write a program in C++.


[User] Please transcribe this text

[Assistant] If you're using any other general purpose programming language, the logic is gonna be the same, but of course we do not have pointers in other programming languages. So, the implementation is obviously gonna be different. But yeaah, then we have tree node write.


[User] Please transcribe this text

[Assistant] So these are both pointers which point to the left and right child. And that's how you link up these different nodes. Now let's come back to our insertion part.


[User] Please transcribe this text

[Assistant] Okay, so before we go through this pseudocode step by step, that is the insert function.


[User] Please transcribe this text

[Assistant] How do you insert a new node? Okay, so let's say right now we have nothing on the right hand side. You can see we have a blank space over here. Let's say you want to add a node. So for the first time, let's say you want to add a node over here. Let's give it a name n1. Okay, let's say it is created at a memory location hash 10. All right, let's say it has the value of 20. Okay, so this is n1. When you want to add this into the binary search tree,


[User] Please transcribe this text

[Assistant] For the first node, this will become the root node, right? So this initially will become the root. Alright.


[User] Please transcribe this text

[Assistant] This makes sense. So, we've just added one node into the binary search tree.


[User] Please transcribe this text

[Assistant] When I say we added a new node into the binary search tree, the binary search tree is nothing but going to be a separate class named BST.


[User] Please transcribe this text

[Assistant] Inside which we will have a root data member. So this is also something that we saw in the previous tutorial.


[User] Please transcribe this text

[Assistant] Who's created at an address of hash 7. Okay. And let's say it has the value of 10. Alright. Now, according to the binary search tree principle, we know that in a binary search tree, when you add a new node, it has to have an appropriate place into the tree.


[User] Please transcribe this text

[Assistant] When I say appropriate place, it means that since this is the root node, when you add a new node,


[User] Please transcribe this text

[Assistant] Depending upon what the value is, it will either be attached to the left hand side or to the right hand side. And that is given by the


[User] Please transcribe this text

[Assistant] And 20. And now we know that 10 is obviously less than 20.


[User] Please transcribe this text

[Assistant] Okay, so I just added node n3 with the value of 30. Now of course it got added to the right hand side of n1 because 30 is greater than 20.


[User] Please transcribe this text

[Assistant] So now this is a proper binary search tree because it is following the principle where for every node


[User] Please transcribe this text

[Assistant] The left subtree has lesser values and the right subtree has greater values. Okay.


[User] Please transcribe this text

[Assistant] So, so far manually you've understood how we are adding nodes. Let's add one more node now. Let's say we want to add


[User] Please transcribe this text

[Assistant] So whenever you add a new node, you start from the root node and you go down


[User] Please transcribe this text

[Assistant] In a binary search tree, whenever you are adding nodes, they are always added at the end. That is, they are added at the lower levels, which is the bottom of the tree. Okay? So, n4 is having a value of 15.


[User] Please transcribe this text

[Assistant] So you start from the root node, root node is n1, n1's value is 20. And the node that you want to add is 15. So 15.


[User] Please transcribe this text

[Assistant] So, where should 15 reside? To the left or to the right of N1? Of course to the left, right? So, you will traverse from N1 to the left side of N1 which is N2. So, you will go one level down and you will come to N2. So, you are traversing from N1 to N2.


[User] Please transcribe this text

[Assistant] So where does N4 be attached after N2? Because of course N4 will be attached somewhere below N2, right? And when I say somewhere, there are two possibilities over here. Either it gets attached to the left or it gets attached to the right. Because both of them are blank.


[User] Please transcribe this text

[Assistant] Right now N2 does not have any child, so N2 is gonna get one child, but where it should be attached is the question that we are trying to figure out.


[User] Please transcribe this text

[Assistant] And that is figured out by this simple expression because 15 is greater than 10, N4 will be attached as the right child of N2. So N4 will be attached somewhere over here. Let's create N4. And this is how the attachment would look like.


[User] Please transcribe this text

[Assistant] N2's right pointer will now point to the address of N4 which is hash 1. So hash 1 will be stored over here and now N2 has a right child of N4. Okay.


[User] Please transcribe this text

[Assistant] Okay, so now you've got a basic understanding of how these nodes are inserted into the binary search tree. You simply have to traverse starting from the root till the bottom and you have to keep on checking the new nodes value that you want to insert with the value of the current node and depending upon whether it is greater or smaller, you keep on traversing or you append it. Okay?


[User] Please transcribe this text

[Assistant] So as I mentioned we have to attach nodes at the end.


[User] Please transcribe this text

[Assistant] What I mean is, I could append n4 below n2 because n2 had a blank right pointer.


[User] Please transcribe this text

[Assistant] If in case n2 had something else over here, that is if let's say n2 is pointing to some other value, nphi with some value, then we'll have to traverse till nphi. Right?


[User] Please transcribe this text

[Assistant] So we can attach nodes only when either the left or right is blank and also depending upon the comparison of the values of those different nodes.


[User] Please transcribe this text

[Assistant] Now with that basic understanding, let's see the insertNode pseudo code and try to dry run this step by step and see the different conditions.


[User] Please transcribe this text

[Assistant] Which will mimic this kind of process, this kind of working because of course we need to write a code, right? And in order to write a code, we need some set of instructions which follows this behavior which helps us to traverse to particular different nodes and then append a new node, right? So for that we need step by step process.


[User] Please transcribe this text

[Assistant] And that is what a pseudocode is. So let's see this pseudocode.


[User] Please transcribe this text

[Assistant] So insertNode is the function name and we are passing a new node inside this.


[User] Please transcribe this text

[Assistant] So a new node will be passed in the insert node and it will get inserted at the bottom in the binary search tree. So that's why this is how the function prototype looks like.


[User] Please transcribe this text

[Assistant] Now do note that this is not the exact syntax of any particular programming language.


[User] Please transcribe this text

[Assistant] This is just a pseudo code. Pseudo code is nothing but a part English, part code kind of syntax which does not have any generic, you know, does not have some set of rules. You can have your own different pseudo codes in plain English or you can mix it up. You can find some standards but you don't need to follow them. This is just for understanding purpose.


[User] Please transcribe this text

[Assistant] But then we will take this same pseudocode and convert it into C++ code by following these same steps. So this conversion becomes easier. Okay?


[User] Please transcribe this text

[Assistant] Alright, so when we go inside the pseudocode, the first step is if root equal equal to null, then root equals to new node.


[User] Please transcribe this text

[Assistant] The root is going to be null, right, because the root is going to be pointing to null. Let's say we have something called as the root pointer.


[User] Please transcribe this text

[Assistant] We have the root pointer in the BST class, right? So initially it is going to be pointing to null. But when you add a new node, let's say you add a new node.


[User] Please transcribe this text

[Assistant] Let's say the node is n1 whose value is 22 and it is created at an address of hash 65. So as shown over here in the diagram.


[User] Please transcribe this text

[Assistant] For the first line, that is the first instruction, it says if root equal equals to null, which is true in the first case, then you simply say root equals to new node.


[User] Please transcribe this text

[Assistant] So now our root will start pointing to n1.


[User] Please transcribe this text

[Assistant] Which means the root will have the address of hash 65.


[User] Please transcribe this text

[Assistant] Now do note that when it comes to programming, when we go to the practical implementation, this is going to be a pointer and hence it is going to point to the node.


[User] Please transcribe this text

[Assistant] By storing its address. Okay, so now root will start pointing to.


[User] Please transcribe this text

[Assistant] Okay, makes sense? This is the first condition. And since this if is going to be executed, the entire point number 2, which is basically this entire code,


[User] Please transcribe this text

[Assistant] Will not be executed because if got executed and then we have else.


[User] Please transcribe this text

[Assistant] So, if the if block is executed, the else block will not be executed. We can simply print over your node inserted. Correct? And then you come out of the function. Okay, so the first node got inserted.


[User] Please transcribe this text

[Assistant] Let's insert one more node using this same pseudocode, using this same function. Let's say now the node supposed to be inserted is node n2. It has the value of 10. And let's say it is created at an address of 33. Okay.


[User] Please transcribe this text

[Assistant] So again, starting off with the first instruction which says if root equal equal to null, then root equals to new node.


[User] Please transcribe this text

[Assistant] Hash 65. So this if block will not be executed because it will become false. Then we will move on to the else part.


[User] Please transcribe this text

[Assistant] Okay, so in the else part, what we have to do is we have to do the traversal. When I say traversal, it means that we have to travel from the root node


[User] Please transcribe this text

[Assistant] To the lower end of the tree because we want to append or we want to insert that new node at the very bottom. Okay.


[User] Please transcribe this text

[Assistant] So in the else part, the first step is to set temp equals to root.


[User] Please transcribe this text

[Assistant] So we create a temporary pointer, let's call it temp and we say temp equals to root. What is the value stored inside root? Root is storing hash 65. So temp will also have hash 65.


[User] Please transcribe this text

[Assistant] And hash 65 is the address of n1, so now it will start pointing to n1.


[User] Please transcribe this text

[Assistant] So why are we doing this? We are doing this because we want to use this temp pointer.


[User] Please transcribe this text

[Assistant] To traverse from N1 to N2 to N3 and so on, if there are any other nodes in this entire BST tree, we're gonna use this temp variable to do the traversal. Okay? So that the root value remains intact and we simply keep on changing the temp pointer's value. Alright. Moving on, we have step number 2.2 which is a while loop. So we say while temp not equals to null. So we're gonna use a while loop to do the traversal. So this is a iterative approach.


[User] Please transcribe this text

[Assistant] What do I mean by iterative approach? In iterative approach, we usually use loops and not recursion. So I have seen some functions, that is some insert functions with BST, which also use the recursion, that is the recursive approach. We're gonna keep it simple for this particular function, that is for this particular operation of insertion. And we're gonna use the iterative approach using a while loop.


[User] Please transcribe this text

[Assistant] In other operations, so I hope you know what is recursion. I have a dedicated video on recursion both in C++ and Java.


[User] Please transcribe this text

[Assistant] If you want you can check that out, I'll drop the link in the video description because anyways we're gonna need it in further tutorials. Alright, so moving on.


[User] Please transcribe this text

[Assistant] Temp not equals to null. So, we will traverse the entire binary search tree using this temp pointer and when the temp pointer becomes null, we can safely say that we have reached the end of the tree. So, that's why we are using this condition. So, initially of course, temp is not null, right?


[User] Please transcribe this text

[Assistant] Because temp is having the value of hash 65, which means temp is not null, so this condition becomes true. So now we will go insert the while loop.


[User] Please transcribe this text

[Assistant] checks if the value inside the new node is equal equal to the value which is pointed by the current node. So,


[User] Please transcribe this text

[Assistant] What this if condition does, it takes the new node. The new node over here is n2, which we are trying to insert, right? n2's value is 10. So newNode.value is 10 equal equal to temp.value.


[User] Please transcribe this text

[Assistant] What is temp? temp is hash 65, which is currently pointing to n1. So temp.value is gonna be 22, right? Is 10 equal equal to 22? No.


[User] Please transcribe this text

[Assistant] So that's why this if part will not be executed, that is this entire will not be executed.


[User] Please transcribe this text

[Assistant] So the reason why we have this condition is to check for duplicate values. Now in our implementation, we are keeping it simple.


[User] Please transcribe this text

[Assistant] Which means we don't want user to enter two nodes having the same value. So in case if n2 had the value of 22, we would have matched it over here, that is 22 will be equal equal to 22.