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:

https://www.studytonight.com/data-structures/introduction-to-data-structures.php

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
https://www.google.com/url?sa=i&url=https%3A%2F%2Fheartbeat.fritz.ai%2Fmemory-management-in-swift-heaps-stacks-baa755abe16a&psig=AOvVaw09z84jBhCkG022US9YaSHx&ust=1585236147374000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCOjProb3tegCFQAAAAAdAAAAABAD

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.
https://qphs.fs.quoracdn.net/main-qimg-817056e5f19496800b99feded66ddb95

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
https://programmerprodigycode.files.wordpress.com/2020/04/65228-0tdrt1runaaf2jrd8.jpg
Image result for array contiguous memory
https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.slideshare.net%2FAdilAslam4%2Farrays-in-c-75597670&psig=AOvVaw0AfWTQp8J3kIG6zH2UZI1L&ust=1585236828203000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIiLksz5tegCFQAAAAAdAAAAABAL

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

The follow up post is https://programmerprodigy.code.blog/2020/04/25/linked-list/

Advertisement

One thought on “Data Structures

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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