What is Data Structure?
In one word, it is a data organizer.
Just imagine your room as computer memory and the things as data.
You use shelves, cupboards, kitchen organizers etc. to organize different things in your room so that you can access your things easily. Without organization there will be a huge mess of things lying on floor. It's the same thing with a computer and its memory.

Some organizing system (structure) is made for specific data, some of them are multi-functional.
Algorithm
An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain predefined task. As per the above example, to organize things in our house, we have to put them into their place. But with a computer of course we want some logic which works automatically to handle huge sets of data and memory.
Array
- An array is a collection of items stored at contiguous memory locations.
- The idea is to store multiple items of the same type together
That’s it.
These two statements are enough to define any structure as an array.
What is contiguous memory? (Very important concept)
Contiguous memory = sequential memory

Computer memory is divided into chunk of partitions. Whenever you define any object in your program you must remember you are actually allocating memory to store data.
Like you require a home to live, in the same way variables require memory to live
Eg. Int A, Float b It means you register part of memory for your variable ‘A’ and variable ‘B’.
As per the above example, Diagram 1 is Contiguous memory and Diagram 2 is non-Contiguous memory.
If you declare array of size 6, it will search for continuous 6 unit of memory, which it will get in diagram 1. Even though diagram 2 has 6 unit of blocks it will not assigned to array since it is not sequential.
You can’t change the size; i.e. once you have declared the array you can’t change its size because of static memory allocated to it.
Traversing
In a traversing operation of an array, each element of an array is accessed exactly once for processing. This is also called visiting of an array.
Program 1 ( Simple array traverse and print number).
Take a deep breath and now start thinking with me.
I need variable to hold my array with a specific size. Let's declare it first.
- int arr[5]={10, 0, 20, 0, 30}; //creating and initializing array
Now I want to iterate through an array. Of course I need a loop.
- //traversing array
- for (int i = 0; i < 5; i++)
- { .. }
Now I want to access each element of that array.
- arr[i]
Put everything together,


Join the conversation! Your thoughts help the community grow.