Data Structures

Data Structure is a way of collecting and organizing data ,such that we can optimize our code .

For example 
1.You can either Store data in tuple or list , depending on operations you want to perform.
2. You can either use yield function use in python or declare data type to store temporary data.As you can see below ,

A real life example of data structure might be , your grocery list ,there are various ways you might write stuff on your list:

  1. random groceries coming to your mind.
  2. groceries based on priority levels .
  3. groceries based alphabetically .

Various classification of Data Structures:

Memory :

There are two mechanism for storing data on your computer:

  1. Memory (RAM) – volatile memory
  2. Storage (ROM) – non volatile memory

memory is like a temporary storage option , as it is faster and efficient to access data from memory.

You can see how much memory used.

Memory is divided into multiple segments , two of important ones are stack and heap

1.Stack : it's where some of your processor's information gets saved , for ex : functions ,variables , etc .This memory is managed by program.
It works on LIFO principle .
2. Heap : Used to allocate big data of memory ,this is what we call Dynamic Memory .This memory is managed by programmer .
Image result for stack memory

How are variable stored in memory :

You can think ram as a box ,divided into smaller cells ,each cell holds equal data . When you store data in a variable it gets converted into byte's , and each byte =8 bits , each block can hold 4 bits . 

For example : When you write int a =2 , a gets stored with binary value of 2 =0000 0010 , first four bits are stored in one cell and other four bits in  next  adjacent cell.

Array :

It is a collection of same data types ,it is stored continuously in memory.

for example : int a[10]  //declares an array of size 10 .
a[postion_you_want_to_access] can be used to access a particular location of an array ,
Image result for array
Image result for array contiguous memory

Here in Diagram 2 , There is an array from 0 to 1 and 7 to 8 of size 2.

The follow up post is


One thought on “Data Structures

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s