top of page

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

A little recap of the previous post

We built a data structure that stores a group of numbers in contiguous memory locations in RAM. We gave it a fancy name called ‘Array’.

Since they are stored in contiguous memory locations, they are positioned sequentially. Such positions are called ‘Array Indices’.

Enough of recap. Let us expand the horizon a little bit

What if we want to store a ‘series of characters’?

Series of characters = ‘String’ in the computer world. Note: Characters include special characters, spaces etc.

Okay, let’s store ‘Finch’…But wait! Computer can understand only in terms of 0 and 1(Binary). I need to find a way to convert the Characters into Binary.

To do this we will map each known character to numbers(See ASCII table) Then numbers can be easily converted into Binaries. What we did above is called ‘Character encoding’(Just jargon).

Time for real action. Let’s store

We have series of characters ‘F’ ‘i’ ’n’ ‘c’ ‘h

Note here:

Each character fits one byte. They are all stored in a contiguous memory location. All are of the same data type.

Therefore, we can comfortably say it is an ‘Array

Simple! Okay then let’s complicate

What if we want to store ‘series of series of characters’

Doesn’t make sense? See, series of characters = ‘String’ Series of series of characters = ‘series of strings’

It’s like storing names like ‘Finch’,’ Patrick’ etc

No of characters in ‘Finch’ = 5 No of characters in ‘Patrick’ = 7

For an array, Do we need to have some type of data? In this case, it is a character →No problem!

We need to allocate an equal number of spaces for both the strings →Problem because(5 != 7). For time being we will allocate the maximum for all(In this case 7). Note: Here for the first index(finch) →2 bytes are wasted

We need continuous memory allocations →If available okay but we need to have another plan to store it. Isn’t it?

What we have faced now is space constraint?

We have 12 bytes but not in a continuous location

So we store the values wherever possible. Then we will form an array that contains the memory locations of these characters.

This array essentially contains memory locations in sequential order. Memory locations are of integer. We have no problem with the type of data, equal space(64 bit), continuous location.

The array we built to overcome the space problem is called ‘Pointer’.

Pointer just points to memory RAM distinguishes pointer from normal integer by identifying star in front of the number

I think we overstuffed today. Let’s finish here

## 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