top of page

Data structures from scratch- Bot-up series #8[Dynamic Arrays]

In the last post, we realized the importance and need for ‘Dynamic Array’

Dynamic = No need to specify no of words in advance. To reiterate, when you type a document, you do not know how much memory is needed in advance. This makes us difficult to use ‘Static Array’

Static means ‘rest’ and dynamic means opposite of static which is ‘movement’. We can comfortably say something is Moving in ‘Dynamic Array’. Array store values and hence values are moving

Have this in your head.

Illustration-1


We are going to type ‘How are you?’ simultaneous without announcing how much space is needed priorly!

When using a dynamic array, the system allocates initially some slots

Initial allotment depends on programming languages(I guess)

For time bring we allot 5 slots

After ‘a’, we ran out of space

Then it has been allotted 11 slots(Usually double)


But wait, we can’t straight away use that 11 slots

We need to copy the elements we typed so far into the 11 slots

Why? This ensures what you have typed ‘remains’ in the continuous slot which makes them easily accessible. Still, we need Array, right?

It is this movement that makes it ‘Dynamic’.

If 11 slots are not sufficient, it will allocate more and copy the elements over there

This process is repeated till we finish typing.

Note: It is not ‘copied’ but ‘cut’ because it frees up the previous space

Whatever slots are allocated every time is called capacity.

If no of elements > capacityMovement takes place

I hope you understand the basic idea of static and dynamic arrays so far

In the next post, we will see alternatives to dynamic arrays!

Recent Posts

See All

As there are many programming languages, there are many programming paradigms. Programming paradigm = style of programming = set of guidelines to solve the problem. So, many programming languages evol

bottom of page