What if you had to invent a dynamic array?

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ต.ค. 2024
  • In this video, we explore how we might create arguably the most used data structure in the world: the dynamic array (also know as the array list).
    Support: / reducible
    This video wouldn't be possible without the open source manim library created by 3blue1brown: github.com/3b1...
    Here is link to the repository that contains the code used to generate the animations in this video: github.com/nip...
    Music: October by Kai Engel freemusicarchi...

ความคิดเห็น • 165

  • @Gameplayer55055
    @Gameplayer55055 3 ปีที่แล้ว +508

    Choose your weapon:
    std::vector
    VS
    Pointer to pointer that points to array of the pointers

    • @igorswies5913
      @igorswies5913 3 ปีที่แล้ว +63

      No, more like including a library with thousands of lines VS a struct with 3 pointers

    • @srijanpaul
      @srijanpaul 3 ปีที่แล้ว +32

      C macro that declares and defines the array struct and functions using token paste operator.
      VS
      Stretchy buffers

    • @igorswies5913
      @igorswies5913 3 ปีที่แล้ว +4

      @@srijanpaul why a macro if you can make a template or just use void pointers

    • @srijanpaul
      @srijanpaul 3 ปีที่แล้ว +32

      @@igorswies5913 In C macros are the closest thing to templates and that's what people usually do for low budget std::vector

    • @igorswies5913
      @igorswies5913 3 ปีที่แล้ว +2

      @@srijanpaul I dont care about what people usually do and I'm talking about C++

  • @7th_CAV_Trooper
    @7th_CAV_Trooper 3 ปีที่แล้ว +306

    1960's dev: I need a dynamic array - builds linked list
    1980's dev: I need a dynamic array - allocates a ton of memory and hopes he never over runs the buffer
    2020's dev: I need a dynamic array - declares a variable of dynamic array type

    • @captlazerhawk
      @captlazerhawk 2 ปีที่แล้ว +39

      No it's still most efficient if you know how much memory you will use and just allocate upfront.
      Many games and engines still use these types of allocators ALL THE TIME.

    • @nakellold
      @nakellold 2 ปีที่แล้ว +9

      @@captlazerhawk ok buddy

    • @oivinf
      @oivinf 2 ปีที่แล้ว +34

      @@captlazerhawk "if you know how much memory you will use"
      Yes... Exactly

    • @emiliagalotti8617
      @emiliagalotti8617 2 ปีที่แล้ว +6

      @@oivinf thats why you often just limit size and then cleverly reuse

    • @dav356
      @dav356 2 ปีที่แล้ว +4

      @@oivinf Knowing how much memory you will use, as in knowing the max amount of memory. You don't need a dynamic array for some things if you know your memory use won't go over a certain amount. This is everywhere in the lower levels of game engines and rendering apis.

  • @olivierdulac
    @olivierdulac 4 ปีที่แล้ว +65

    Very nice videos. You could add that the constraint of fixed length array is often due to memory allocation : the program asks for "m bytes", and use that for the array. If we end up with needing more space, in general the memory "just after" the one we use for the current array is not available (thus we can not just extend the array). We need to ask for ">m" contiguous memory, and use that for our new array, and we have to copy the elements of the previous array into this new one before we can add the new element into it.

    • @Reducible
      @Reducible  4 ปีที่แล้ว +14

      Hi Oliver, that is a great point and you're right that this is something I should have included in the video. Thanks for sharing!

  • @ryanyanko3547
    @ryanyanko3547 3 ปีที่แล้ว +23

    Great video! The style reminds me a lot of 3 blue 1 brown

    • @jonasdaverio9369
      @jonasdaverio9369 3 ปีที่แล้ว +10

      He's using manim, that's why

    • @ryanyanko3547
      @ryanyanko3547 3 ปีที่แล้ว +1

      @@jonasdaverio9369 oh word that's cool

  • @CalebTerryRED
    @CalebTerryRED 3 ปีที่แล้ว +119

    I've already written my own dynamic array, but I still clicked for some reason. Glad I did though, great video!

    • @rhodexa
      @rhodexa 3 ปีที่แล้ว +9

      Same! haha. I did when i started programming in C++, i didn't know it already had dynamic array libraries. :P
      I think most low-level programmers had, at least once.

    • @Speykious
      @Speykious 2 ปีที่แล้ว +2

      @@rhodexa I did it in C - only after watching this video, based on what it said. It was pretty simple to do actually. :D

    • @styleisaweapon
      @styleisaweapon 2 ปีที่แล้ว

      pretty sure every programmer that was banging keys in the 80s or 90s have written many dynamic array implementations, each having different strengths and weaknesses - hash tables, splay trees, hash tables of splay trees, and so on - the common misunderstanding folk have about all this is that its still fixed size at the end of the day - moving responsibility to a different allocator than your own doesnt change things

  • @RSA_Shock
    @RSA_Shock ปีที่แล้ว +1

    Love the 3blue1Brown style

  • @ImperialFool
    @ImperialFool 2 ปีที่แล้ว +15

    I learned c, literally the first thing I asked myself was how do I make a dynamic array. The answer as always when it comes to c is pointers.

  • @dnagal7816
    @dnagal7816 4 ปีที่แล้ว +24

    Love this! and really appreciate you sharing your github

  • @redhawkneofeatherman261
    @redhawkneofeatherman261 2 ปีที่แล้ว +2

    The fact this video came on my recommended the day after a CS test on linked lists is mysterious timing indeed

  • @vylbird8014
    @vylbird8014 3 ปีที่แล้ว +50

    Reminds me of the time I actually did this - in C, for a two-dimensional array. The purpose of was to reconstruct a continuous image from translating video, for use in restoring scrolling text in old silent movies.

    • @phillipanselmo8540
      @phillipanselmo8540 2 ปีที่แล้ว

      if it's for reconstructing a image then why didn't you just use a regular array?

    • @vylbird8014
      @vylbird8014 2 ปีที่แล้ว

      @@phillipanselmo8540 Because C, and no way to determine the size of the final image ahead of time.

  • @samuelgunter
    @samuelgunter 3 ปีที่แล้ว +40

    If part 2 isn't showing up for y'all like it didn't for me, here's the link th-cam.com/video/Ij7NQ-0mIVA/w-d-xo.html

    • @JP-vg8vl
      @JP-vg8vl 3 ปีที่แล้ว +2

      thank you kind stranger

    • @osaimola
      @osaimola 2 ปีที่แล้ว +2

      You are a hero

    • @samuelgunter
      @samuelgunter ปีที่แล้ว +1

      hajahhrhahsha I had to use my own comment when I came back 2 years later

  • @pedroth3
    @pedroth3 9 หลายเดือนก่อน

    Great video! Such a simple problem, yet it introduces many concepts of computer science. Thanks

  • @mattstockwell921
    @mattstockwell921 2 ปีที่แล้ว

    This type of channel is exactly what I have been working for

  • @lye-o8v
    @lye-o8v 3 ปีที่แล้ว +2

    This is a fantastic video. Thank you for all of your hard work in putting things together so that other people can learn something new.

  • @pro_myth_eus6897
    @pro_myth_eus6897 2 ปีที่แล้ว

    This was an assignment I had to do back in my intro to programming class, this video would have helped back then

  • @cameronball3998
    @cameronball3998 3 ปีที่แล้ว +2

    Gotta be honest, I did not expect this to end up going into big O notation 😂. Awesome video

  • @sathishraj1
    @sathishraj1 4 ปีที่แล้ว +20

    Never utilized my time better than this.. Loved this video...Pls share more videos...deepest gratitude to you

  • @cineblazer
    @cineblazer 2 ปีที่แล้ว +1

    The 3Blue1Brown of computer science

  • @akshitmahaur591
    @akshitmahaur591 2 ปีที่แล้ว +1

    Great content and amazing animation!

  • @s1lentssh
    @s1lentssh 3 ปีที่แล้ว +22

    Hey, why video so short? :)
    I have expected speech about multiplying array by 2 or exponent. Or about linked lists. Or about trees and hash tables.
    In hash table you have O(1) write and access time.
    It would be amazing to cover this subject completely

  • @PearangeProductions
    @PearangeProductions 2 ปีที่แล้ว

    I have no idea why I was reccomended this, but I clicked anyways.
    I hate math lessons, but those little illustrations you used made this too adorable to hate.
    Congratulations, sir, you made me watch a math lesson out of my own volition.

  • @kenzostaelens1688
    @kenzostaelens1688 3 ปีที่แล้ว +5

    yup, i've done the create new array version, next time i'll use stackoverflow and don't write it myself

  • @AkiratheWhite
    @AkiratheWhite 3 ปีที่แล้ว

    This deserves way more views. Explains the concept of an array and gives an example of what Big O for runtime is like! ✌

  • @starcubey
    @starcubey 2 ปีที่แล้ว

    pannenkoek2012: _builds up speed for 12 hours_
    Reductible (6:40): _copies elements from one array to another while adding new elements for 12 hours_

  • @Starwort
    @Starwort 2 ปีที่แล้ว +2

    Very nice video, but I feel like a better space metric would be maximum concurrent usage; i.e. the first scheme has a max concurrent space of 2n-1 (the second scheme has a maximum concurrent space averaging 2n)

  • @javipy2731
    @javipy2731 2 ปีที่แล้ว +7

    array list are good to search elements, but not efficient to restructure them. Linked list (or doubly linked list are better so as to add (append) new elements, but not so good to find elements. Every structure has its advantages and disadvantages.

    • @seubmarine5347
      @seubmarine5347 2 ปีที่แล้ว

      Linked list as also the disadvantage of memory not being like an array and take a lot of time in that case

    • @cmyk8964
      @cmyk8964 2 ปีที่แล้ว

      Linked lists can be kept in sorted order by using insertion sort when appending elements. Insertion sort is great for doubly linked lists because you can eliminate the bother of swapping each element between the unsorted element and its sorted place, just by rewiring some pointers.

    • @flatfingertuning727
      @flatfingertuning727 2 ปีที่แล้ว +2

      On many computers, accessing many areas of memory that are close together can be much faster than accessing areas that are widely scattered. In the 1990s random accesses would often take between 100% and 300% as long as sequential accesses, but today that ratio has gone up by more than an order of magnitude. Even in cases where a linked-list approach would only use half as many total accesses as an array-list approach, performance may still be massively worse because all of its accesses would hit different rows of DRAM.

    • @TheFlynCow
      @TheFlynCow 2 ปีที่แล้ว

      linked lists are horrible. period. doesnt matter wether they're forward linked, doubly linked or quadruple linked.

    • @flatfingertuning727
      @flatfingertuning727 2 ปีที่แล้ว +1

      @@TheFlynCow Linked array-lists are useful for chain bucket hashing; I'm not sure what data structure would really be better for that purpose. Linear-probe hashing might offer better cache coherency, but at the expense of very bad behavior if hash table entries get clumped.

  • @iamjimgroth
    @iamjimgroth 2 ปีที่แล้ว

    I feel so old. To me it feels like yesterday when you had to roll your own dynamic arrays.

  • @CorbinSimpson
    @CorbinSimpson 3 ปีที่แล้ว

    Computer scientists sometimes care about exact formulas. Given your experiments, we could conjecture that a resize of r elements has polynomial formula starting (1/2r)*N**2 + ... If we insist on a linear-cost behavior, and try to cancel a power of N, then this suggests r=N/2 without actually working a recurrence relation.

  • @SinanAkkoyun
    @SinanAkkoyun 2 ปีที่แล้ว

    Oh I love this channel

  • @_lapys
    @_lapys 3 ปีที่แล้ว +7

    Very 3Blue1Brown inspired?

    • @timkluge426
      @timkluge426 3 ปีที่แล้ว

      @@ishdx9374 what library is this?

    • @vandelayindustries2971
      @vandelayindustries2971 3 ปีที่แล้ว +5

      @@timkluge426 It's called Manim. It's on GitHub.

    • @xynyde0
      @xynyde0 3 ปีที่แล้ว

      @@timkluge426 check description

  • @АртемКрючков-ц2г
    @АртемКрючков-ц2г 3 ปีที่แล้ว +97

    С: Am I joke to u?

    • @magnusanderson6681
      @magnusanderson6681 3 ปีที่แล้ว +28

      Assembly: you guys are able to declare variables?

    • @samuelgunter
      @samuelgunter 3 ปีที่แล้ว +13

      Brainfuck: wtf

    • @srijanpaul
      @srijanpaul 3 ปีที่แล้ว +1

      Stretchy buffers.

    • @igorswies5913
      @igorswies5913 3 ปีที่แล้ว +3

      ever heard of malloc/realloc/free?

    • @peplegal8253
      @peplegal8253 3 ปีที่แล้ว +1

      @@igorswies5913 : have you heard about efficiency ? have you needed to process 1 million operations in few milliseconds ?

  • @shinda1020
    @shinda1020 3 ปีที่แล้ว +7

    Why do we need to resize by fixed size? I thought it’s always by doubling the previous size if needed, and then memcpy instead of doing elementwise assignment

    • @mettaursp309
      @mettaursp309 2 ปีที่แล้ว +2

      Different use cases can benefit from different strategies for growing depending on factors such as:
      - how constrained system/program memory is
      - how often arrays are expected to grow
      - how much arrays are expected to grow by
      The exponential growth strategy also doesn't always need to be strictly double. Sometimes growing by only a factor of 1.2, 1.5, 3, 4, etc.
      As for the memcpy point, not all data types are safe to straight up memcpy, at least in C++. memcpy also wouldn't really fit into the video, because the video is more about the conceptual idea behind dynamic arrays rather than implementation details.

    • @Yotanido
      @Yotanido 2 ปีที่แล้ว

      @@mettaursp309 Extending by a fixed size, while I can probably come up with uses, is still SUPER niche. Doubling is indeed what is usually done.
      And as explained in the video, using a fixed size doesn't help the scaling any. I suspect the follow-up video that was mentioned at the end, is going to explain how doubling is used.
      As for memcpy and elementwise assignment... memcpy does nothing different. It's still just a loop copying over each word. That is assuming the assignment operator doesn't do anything crazy. I don't use C++, so it might well do that.

    • @mettaursp309
      @mettaursp309 2 ปีที่แล้ว

      @@Yotanido I agree that the fixed amount increments has pretty limited use cases. I don't think I've ever personally run into a case where it would be the best option, but I've also only programmed for consumer grade PCs, not smaller devices like microprocessors.
      For C++'s std::vector growth factor, it seems to not be defined in the standard so it's implementation dependent. A lot of the compilers do a factor of 2, but Microsoft being Microsoft chose 1.5 for at least one of their versions.
      As for memcpy, yeah the relevant functions like assignment operator overload, copy constructor, move constructor, and so on can be changed to perform nontrivial operations.
      I believe that std::vector will use the move constructor if available and compatible, otherwise it will use the copy constructor. I'm not sure if it falls back on memcpy if the class is a plain old data type though.

  • @aminabdolkhani2238
    @aminabdolkhani2238 3 ปีที่แล้ว

    your videos are fantastic dude!

  • @erikm8373
    @erikm8373 2 ปีที่แล้ว +6

    to be honest, I can't imagine putting myself into a situation where I'd have to invent a dynamic array, but if I ever find myself there, I'll be returning to this video

  • @JoseTorresCardenas
    @JoseTorresCardenas 3 ปีที่แล้ว

    Nice video and beautifully explained.

  • @joelflanagan7132
    @joelflanagan7132 2 ปีที่แล้ว

    Nice work!

  • @MikkMakk90
    @MikkMakk90 3 ปีที่แล้ว

    Awesome video!! Keep it up :)) I'm certain you're gonna grow

  • @joshelguapo5563
    @joshelguapo5563 2 ปีที่แล้ว

    Okay pausing the video after the intro and taking a guess: using a hash table where each of the elements is stored at the hash of the index

  • @parasjain9416
    @parasjain9416 3 ปีที่แล้ว +1

    Dhanyawad

  • @fireboss05
    @fireboss05 3 ปีที่แล้ว +3

    Don't you dare make me curious about langages that don't automatically store data

  • @Spiderboydk
    @Spiderboydk 2 ปีที่แล้ว +10

    If one needs huge array (i.e. large N), grow the array size with an exponentially increasing amount.

  • @LUMEN_science
    @LUMEN_science 2 ปีที่แล้ว

    Um dos melhores do youtube

  • @bluesillybeard
    @bluesillybeard 2 ปีที่แล้ว +12

    "There's a lot of thought put into making this really efficient"
    Java ArrayList: uses the solution around 4 minutes
    (If you look at the actual code, you can see that's what it does. Who knows what kind of crazy optimization the JVM does, but the code itself is written that way)
    EDIT: read the first reply, that's more accurate

    • @DOOT_II
      @DOOT_II 2 ปีที่แล้ว

      can't say I'm surprised

    • @ishid_anfarded_king
      @ishid_anfarded_king 2 ปีที่แล้ว

      i mean its using code from other classes

    • @maruseron
      @maruseron 2 ปีที่แล้ว +4

      No. Java does not do this. The ArrayList.add method checks if there's enough capacity, and if not, it calls the ArrayList.grow method by indicating a MINIMUM GROWTH of 1 element. The call to grow will then delegate the calculation of the new size to the internal JDK method ArraysSupport.newLength with a preferred size of twice the length of the backing array. Then, the backing array is expanded with whatever newLength returns. This means that, most of the time, Java ArrayLists will grow by a factor of two once there's no more space.
      Please don't spread this kind of rumor about Java. They're part of the reason it has an undeserved bad reputation.

    • @bluesillybeard
      @bluesillybeard 2 ปีที่แล้ว

      @@maruseron Good to know, last time I read through the code was a looong time ago, so I probably forgot this part

  • @ndyah7836
    @ndyah7836 2 ปีที่แล้ว

    you deserve so many more subs than this.

  • @lashankuanetteshesothicc4242
    @lashankuanetteshesothicc4242 2 ปีที่แล้ว

    3:35 First thing I do when I get a 5th Element is fast-forward to a scene with the pink-haired manic pixie dream girl, get the conditioner out of the shower and grab a few tissues.

  • @but9l471
    @but9l471 2 ปีที่แล้ว

    So you can create array of pointers, each one points at different places of memory and each one contains address to array of 4 elements, and when you want some more space you just recreate array of pointers with one more cell, create new array for this pointer, and instead of copying each one number, you copy addresses to new array, and for arrays of 4 elements its 4 times faster, but you, at worst, dont use 3 elements

  • @nidaljaafar5825
    @nidaljaafar5825 2 ปีที่แล้ว

    3b1b of computer science

  • @Illumina_Blade
    @Illumina_Blade 2 ปีที่แล้ว

    If we get a 5th element we're Bruce Willis and we have to save the universe

  • @CompactStar
    @CompactStar 3 ปีที่แล้ว +1

    Aren't fixed length array tuples?

    • @terradoom8503
      @terradoom8503 3 ปีที่แล้ว +1

      Only in non-strictly typed languages. In strict languages such as Haskell or Rust, a tuple is a fixed length sequence that can contain mixed data types, i.e., you can do (i32, String) to have a two element tuple with a number and a string.
      Arrays on the other hand must contain elements of the same type, mainly due to the fact that the size of each element must remain the same to be able to find elements. Also, it makes it really difficult to remember what is what in the array if you mix types.

  • @albertmashy8590
    @albertmashy8590 2 ปีที่แล้ว +1

    How do you make these videos. They are amazing and I want to teach people in a similar way

    • @thelaagernation9532
      @thelaagernation9532 2 ปีที่แล้ว

      It looks like it was made using 3Blue1Brown's manim library

  • @lenargilmanov7893
    @lenargilmanov7893 2 ปีที่แล้ว

    And I thought that dynamic arrays were trees under the hood.

  • @abhijithmuthyala8838
    @abhijithmuthyala8838 5 ปีที่แล้ว +3

    Loved the video ! Can you please share the code ?

    • @Reducible
      @Reducible  5 ปีที่แล้ว +5

      Thanks for the comment! And yes, this is a great point. I added the a link to the code used to generate the animations in this video in the description.

    • @abhijithmuthyala8838
      @abhijithmuthyala8838 5 ปีที่แล้ว

      Thank you and good luck.

  • @kipchickensout
    @kipchickensout 2 ปีที่แล้ว

    I came here for the thing that he teased at the end wtf

  • @moregirl4585
    @moregirl4585 2 ปีที่แล้ว

    Just allocate lots of memory and assume unused part isn't actually allocated (Linux's victory, Windows always need pagefile)

  • @mathmachine4266
    @mathmachine4266 2 ปีที่แล้ว

    Dammit, I thought you were gonna explain why dynamic arrays are pointers. Or at the very least why we double array lengths instead of just adding k elements.

  • @DFPercush
    @DFPercush 2 ปีที่แล้ว +1

    In my implementation I just scale the size by a growth factor every time it grows past capacity. By default the factor is 1.5 because having twice the space as is used seems wasteful. Would that be O(n log n) for the time? Anyway, another approach, if it's not required for the memory to be natively contiguous and your indexing operator can handle accessing an element, would be to use blocks, where you just allocate new blocks of a fixed size, and use the upper bits of the array index to select the block. This would also have to be scaled up at some point, and it might not be as cache friendly, but you avoid a lot of copying that way. Interested to hear there's a O(n) way of doing it. I think I'll look for that other video now. Good channel btw. :)

    • @DFPercush
      @DFPercush 2 ปีที่แล้ว +1

      Oh, that is O(N), you put it nicely in the next one about dividing N into half repeatedly and adding. Technically 2N but we don't care about silly constants.

    • @TheScabbage
      @TheScabbage 2 ปีที่แล้ว +1

      @@DFPercush Your growth factor is a common one. ArrayLists in Java and std::vector in C++ both use 1.5. Other languages like C# and Rust use a factor of 2.
      They have the same time complexity, but the rationale behind using larger growth factors is that memory is usually pretty cheap, so it's better to reduce the amount of resize operations.
      Going even deeper, a growth factor lower than 2 can be beneficial in languages that don't have managed memory. When a factor of 1.5 is used, the new larger array can fit into previously used blocks of memory. With a factor of 2, it will never fit. This is assuming that the previously used blocks are contiguous, which is often not the case in real world applications. Aforementioned managed languages complicate this even further, because they can shift things around in memory under the hood to reduce fragmentation.

    • @hellocanyouhearme
      @hellocanyouhearme 2 ปีที่แล้ว

      @@DFPercush well technically it is O(N) big O notation just says it is something within a constant factor, so saying O(2N) is not technically correct:

  • @reverseila
    @reverseila 2 ปีที่แล้ว

    Is manim shiped with this kinds of background song?

  • @TheBookDoctor
    @TheBookDoctor 3 ปีที่แล้ว +6

    I'm not gonna hate on anyone whose first programming languages have built-in memory management and garbage collection. These are wonderful things! But it *is* really interesting to watch how these deep computer fundamentals are now getting taught to the generation who cut their teeth on python.

  • @sergeboisse
    @sergeboisse 2 ปีที่แล้ว +1

    Next video is here ; th-cam.com/video/Ij7NQ-0mIVA/w-d-xo.html&ab_channel=Reducible

  • @haleysettembre
    @haleysettembre 2 ปีที่แล้ว

    int V[n]; goes brrrrr

  • @tusharchilling6886
    @tusharchilling6886 2 ปีที่แล้ว

    But there are many loopholes in this explanation like why is it important for us to consider very large cases.

  • @ns4235
    @ns4235 2 ปีที่แล้ว

    if (allocated == length) {
    allocated *= 2
    data = malloc( allocated );
    }

  • @medwards1086
    @medwards1086 3 ปีที่แล้ว

    Should the formula for the number of elements be N-4 rather than N+4 in the denominator?

  • @mzayan100
    @mzayan100 ปีที่แล้ว

    where can I find the next video please?

  • @thedudeguy242
    @thedudeguy242 2 ปีที่แล้ว

    Why not allocate for n+1 elements but leave the last element to point to a memory address when you expand the array?

    • @c0smo709
      @c0smo709 2 ปีที่แล้ว +1

      Why would you do that?
      Arrays can be of different types (char, int , short or anything else), each lf those different types has a different size (1, 2, 4 or anything else) a pointer is always 4 or 8 bytes (depending on if youre running on 32 or 64 bit).
      Not to mention it makes array access harder. Lets say i have an array of 3 items then append 3 more to it. Now lets say i want to get the 4th element of the array. With the standard implementation i can just array[3]. With ur implementation u fitst have to check if the element is in the original array, if not, do math and check if its in the next array, and so on. Also theres a 4/8 byte overhead for each time you append something. Also removing items becomes even trickier

    • @thedudeguy242
      @thedudeguy242 2 ปีที่แล้ว

      @@c0smo709 on the first part you're right, but at least in c++ you can overload the [] operator for easy access. I made an implementation of it after I made this comment just to see how difficult it is. I'm pretty bad at c++ but I had pretty decent results (around a million appends + a collapse took 2.5 seconds iirc. It can definitely be optimized though.
      It does make insert operations quite a bit faster though.

    • @c0smo709
      @c0smo709 2 ปีที่แล้ว

      @@thedudeguy242 post the code and i will benchmark it with mine

  • @dasmaffin1633
    @dasmaffin1633 2 ปีที่แล้ว

    I would import system collections

  • @mrosskne
    @mrosskne 2 ปีที่แล้ว

    link to the next vid?

  • @computernerd8157
    @computernerd8157 2 ปีที่แล้ว

    You would not create an array with just one space. You might use pointers to achive the same thing. Intead of a next pointer you gave a privous pointer. That way you can go through the list O n. On the other hand a linkedlist seems more efficent but you do not get O 1 access to a linkedlist unlike any array. In genral if you want quick access arrays better then list.

  • @shriharisambath3831
    @shriharisambath3831 2 ปีที่แล้ว

    go Lang gives the same with name of Slice

  • @JivanPal
    @JivanPal 2 ปีที่แล้ว

    Did somebody say "page tables"?

  • @otesunki
    @otesunki 3 ปีที่แล้ว

    9:05 in asm this feels very "rep movsd"-ey

  • @benji9107
    @benji9107 2 ปีที่แล้ว

    I’ve written a linked list before and I think the solution is similar right?

    • @somebodyelse9130
      @somebodyelse9130 2 ปีที่แล้ว +1

      For a linked list, insertions are more efficient, because you don't have to copy every element to a new list like you do with an array. You just point the pointer of the tail of the list to your new element. They're particularly efficient for inserting elements in the middle of your list. With an array, you'd have to make your new sized array, copy all elements above that index but moved over by one, then copy the insertion, then copy the rest. With a linked list, you just have to reassign some values to some pointers.
      The problem with linked lists is that to access any given element, you need to go through each element and follow the trail of pointers to get it, whereas for arrays, you can access any given element with no loss in efficiency; because array elements are stored contiguously in memory, the computer just has to add to a pointer to access them, as opposed to dereferencing a pointer, assigning it to the current node, then repeating until you find your element.

  • @jensBendig
    @jensBendig 2 ปีที่แล้ว

    Long ago, I was young and we didn‘t have dynamic arrays. I coded my own ones in C. And they sucked.

  • @tamermedhat7550
    @tamermedhat7550 ปีที่แล้ว

    i slept from video music 😑

  • @sgt-Badger
    @sgt-Badger 2 ปีที่แล้ว

    Array == Stack in cpu?

  • @javipy2731
    @javipy2731 2 ปีที่แล้ว

    conclusion: use a balanced binary tree

  • @YanYanicantbelievethistakenffs
    @YanYanicantbelievethistakenffs 2 ปีที่แล้ว

    When you said dynamic array i was hoping for my beloved array Placeholder.'variable'. =[]
    And make a dynamic array, aka.
    PlaceholderStore[], PlaceholderGarage[] and so on.

  • @tomoki-v6o
    @tomoki-v6o 2 ปีที่แล้ว

    How lisp works ?

  • @paul8683
    @paul8683 3 ปีที่แล้ว +1

    Why is the music so sad. It's like you are telling us about the array that died before it could hold any data.

  • @ar_xiv
    @ar_xiv 2 ปีที่แล้ว

    Why not just allocate a really big one and have a separate variable for the actual length

    • @c0smo709
      @c0smo709 2 ปีที่แล้ว

      Because then youre wasting memory. Also whay if even the really big one is too small?

  • @SomeRandomDude821
    @SomeRandomDude821 2 ปีที่แล้ว

    EDIT: just noticed this is a year old lol. It popped up in my recommended.
    Are you using 3blue1brown's python library? I don't remember if he made it public. Not calling you a copycat, but I do get a similar vibe from your channels. Complex/stereotypically "nerdy" topics explained over calming music, with topic-relevant creatures discussing the material and thoughts viewers may have over a full black background where simple illustrations help work through the complexity.

  • @peterwhitey4992
    @peterwhitey4992 2 ปีที่แล้ว +1

    Array indexes usually start at zero.

  • @JoseTorresCardenas
    @JoseTorresCardenas 3 ปีที่แล้ว

    Link to next video: th-cam.com/video/Ij7NQ-0mIVA/w-d-xo.html

  • @matthewrease2376
    @matthewrease2376 2 ปีที่แล้ว

    Why would you copy when you increase size though? From my time in C, I know you can request the system to resize an allocated block of memory (realloc and reallocarray).

    • @API-Beast
      @API-Beast 2 ปีที่แล้ว +3

      realloc is just alloc + copy + dealloc, it just does the copy step for you.

    • @matthewrease2376
      @matthewrease2376 2 ปีที่แล้ว

      @@API-Beast oh damn really? I guess that explains the performance... I might have to implement my own version now lol

    • @flatfingertuning727
      @flatfingertuning727 2 ปีที่แล้ว +1

      @@matthewrease2376 The Standard would allow realloc() to, at its leisure, either adjust the size in place or create a new allocation and copy the data, but provides no means of distinguishing which of those an implementation actually did. It would be useful if there were a variation of realloc() which would ask to make an allocation as large as possible, up to a specified limit, without moving it or affecting the validity of pointers to it (the function would need to be passed the address of a size_t to receive the new size), but as it is the Standard doesn't even provide a means of knowing whether pointers to a re-allocated region would need to be recomputed.

  • @aminforoutan6065
    @aminforoutan6065 3 ปีที่แล้ว

    if you double or triple the previous array the time becomes O(n) amortized!

  • @wiczus6102
    @wiczus6102 2 ปีที่แล้ว

    The video doesn't awnser the question set in the title. It's was a complete waste of time for me.

  • @JoannaHammond
    @JoannaHammond 2 ปีที่แล้ว +1

    Try doing it in BASIC, that was fun... not.

  • @lowlevelcodingch
    @lowlevelcodingch 5 หลายเดือนก่อน

    char* ptr0 = {'h', 'i'};
    char* ptr1 = {' ', 'm'};
    char* ptr2 = {'a', 'n'};
    char** aptr = {*ptr0, *ptr1, *ptr2};
    char** ptptptaotp = ***aptr;

  • @jacobkreifels7690
    @jacobkreifels7690 2 ปีที่แล้ว +1

    You talk incredibly slow. I had to play this in 2x to hear normal speed

  • @ezee3468
    @ezee3468 2 ปีที่แล้ว

    Java lol

  • @mamertvonn
    @mamertvonn 3 ปีที่แล้ว

    I learned it as any good programmer would do. Copy paste from the internet lol
    th-cam.com/video/ryRf4Jh_YC0/w-d-xo.html
    Or
    Just use python, or whatever language with a built-in dynamic array