The Last Algorithms Course You'll Need Arrays Q&A
Transcript from the "Arrays Q&A" Lesson
>> Any questions on what we've covered up to this point on what arrays are.
>> So you're saying there is no insert or push or pop in arrays.
>> The question was, there is no insert or push or pop and an arrays? Technically no, not if it's a static array or a traditional array, there is no methods on it In fact, in some of the older languages, there's not even dot length, right?
[00:00:21] You have to pass the length as well as the pointer to the beginning of the array and just say, hey, here's my type. Here's where it starts. Here's how many I have. That's why when you look at any C program, the entry point is an array of strings.
[00:00:37] And how many strings they are? Right, like it it has to tell you how to interpret these pieces of data.
>> If an array doesn't grow, does its memory and size and memory allocation have to be specified at initialization of the array?
>> Whenever if ,so if you use rust and you try to use an array, you will realize right away that you have to put in a size.
[00:00:57] It has to be a specified size and often you'll see this all over the place that you have to like tell it its size and that's the size that it's created. Now, it can be a variable still, right? You can still create an array with n as its size in a lot of these languages but it still has to be a specified size.
[00:01:13] There are also like compiled time arrays where you actually have to be like this thing is a 3 it's always a 3, it is always going to be a 3, right? There's there's kind of these different styles. But nonetheless, an array has to have its size as part of its allocation.
[00:02:02] Again, there's a bunch of conditions that are a part of your array that make it actually a lot more tricky to simply to. I'm sure they have a turn it into a map once you have too many items or once you have too sparse of an array, I'm sure they have a lot of algorithms that make it 10 times more complicated than this.
[00:02:18] But for the most part it is. It operates like an array. I don't wanna give it away. I don't. 1 more question.
>> I guess how big is the array then that you instantiate? So, that is part of optimizing. So, like in Rust, if I'm not mistaken, if you create a new vector, it's gonna create a effectively a memory buffer with the size 5 underneath.
[00:02:42] And so, as you push and pop, it has 5 units for you to be able to play and now is that efficient? Well, that's the problem. How big do you need to create your underlying buffer to be able to effectively use that space without having to re allocate too much or without not using it?
[00:02:58] Right, cuz we could all create 10,000 units and be like, hey, look, we'll never have to reallocate again. But if 10,000 units are big units, you're gonna use a lot of memory, just to have that in there. So, it's kind of it's a game people play and we'll go over these it'll make a lot more sense once we go over the data structures that are used.