Array Data structure, Types of Array, 1D, 2D, MultiD, nD, Array and Need of Array

Array(अरे):-
           An array is a collection of similar data elements,which are stored at continuous bytes in computer memory. Array name is shared between data elements and each data element has an index between 0 to arraysize-1. Here arraysize shows maximum number of data elements stored in that array.Address of first element of an array is called base address of array. Array is also called scripted element.
               एक अरे एक ही प्रकार के डाटा एलेमेंट्स का समूह होता है जिन्हें कंप्यूटर मेमोरी में क्रमागत बाइटस पर रखा जाता है। अरे का नाम सभी एलिमेंट द्वारा प्रयुक्त किया जाता है एवं साथ में इंडेक्स सम्बंधित होता है जो 0 से arraysize-1 तक होता है, यहाँ arraysize , उस अरे द्वारा रखे जाने वाले अधिकतम एलेमेंट्स की संख्या है। अरे का नाम ही अरे के प्रथम एलिमेंट का एड्रेस या अरे का बेस एड्रेस होता है। अरे को स्क्रिप्टेड [] एलिमेंट भी कहा जाता है।      

Array is mainly of 2 types :-
अरे निम्न दो प्रकार का होता है:-
 
1.) One Dimensional array एकविमीय अरे :-
1D array is used to store data elements of list. It is a collection of similar data elements,which are stored at continues bytes in computer memory. This type of array uses a single script [ ], so it is called 1D array. Index of data elements of 1D array is from 0 to arraysize-1, 1D array is capable for storing characters, integers and real numbers etc.

1D अरे का प्रयोग लिस्ट के डाटा एलेमेंट्स को रखने के लिए किया जाता है। यह एक ही प्रकार के डाटा एलेमेंट्स का समूह होता है जिन्हें कंप्यूटर मेमोरी में क्रमागत बाइटस पर रखा जाता है। 1D अरे एक सिंगल सबस्क्रिप्ट [] प्रयुक्त करता है इसीलिए इसे 1D अरे कहा जाता है, इसका नाम सभी एलिमेंट द्वारा प्रयुक्त किया जाता है एवं साथ में इंडेक्स सम्बंधित होता है जो 0 से arraysize-1 तक होता है यह अरे करैक्टर, पूर्णांक एवं वास्तविक संख्याओ इत्यादि को संग्रहित कर सकता है  

Declaration of 1D array- 
Syntax :- 
datatype array_name[size];
datatype  array_name1[size], array_name2[size],.......array_namen[size];

Example:-
char name[20];
int list[100];
float marks[50];

Initialization of array- 
Syntax:- 
datatype array_name[size] = {value1, value2,...... valuen};

Example:- 
char name[20] = {'D','i','v','y','a','\0'};

int list[100] = {101, 102, 103, 104, 117, 128,....};

float marks[50] = {67.5, 48.2, 89.9, 56.3,.....};

2.) Multi-Dimensional array बहुविमीय अरे:- 

In 'c' language we can use 2 or more subscripts [ ] to create 2D , 3D, 4D,..... nD array. This array is collectively called nD or multi dimensional array. Number of subscripts are used to refer dimension of an array.
सी लैंग्वेज में हम 2 या अधिक सबस्क्रिप्ट [] का प्रयोग कर 2D , 3D, 4D,..... nD अरे तैयार कर सकते है  इन सभी अरे को सम्मिलित रूप से nD या मल्टी डायमेंशनल अरे कहा जाता है।यहाँ [] की संख्या उसके डायमेंशन विमाओ को व्यक्त करती है  
Syntax:-
datatype array_name[D1][D2].....[Dn];

Example :- 
int mat [3][3];
float pixel [5][5][5];

Two Dimensional Array, द्विविमीय अरे :- 

2D array is used to store tabular data or information. It means information which is present in rows and columns like tables, records, determinant and matrix information etc. 2D array uses two subscripts [ ][ ].Let A[m][n] is a 2D array of integer type then its row index is from 0 to m-1 and column index is used from 0 to n-1. Here m and n are used to represent row size and column size respectively, so the total number of elements stored in a 2D array is m×n. 
2D अरे का प्रयोग सारणी के डाटा एलेमेंट्स को रखने के लिए किया जाता है। अर्थात जिसमे जानकारी पंक्ति  एवं स्तम्भ के रूप में राखी गयी हो जैसे तालिका, रिकॉर्ड , सारणिक एवं आव्यूह इत्यादि। 2D अरे में दो सबस्क्रिप्ट [][] प्रयुक्त की जाती है जो क्रमश पंक्ति एवं स्तम्भ को दर्शाती है। माना कि A[m][n] एक 2D अरे है जो पूर्णांको को रखता है तब इसका rowindex 0 से m-1 तक एवं columnindex 0 से n-1 तक होगा, यहाँ m  रो साइज़ तथा न कॉलम साइज़ है। 2D अरे में रखे जाने वाले कुल एलिमेंट की संख्या m x n होती है  

Declaration of 2D array :-

data_type array_name [row_size], [column_size];
Example :- 
int mat [3][3];

Initialization of 2D array :-
data_type array_name[row size] [column size]= {value1, value2,.... value m×n};
Example :- 
int mat [3][3] = {1, 0,1, 2, 1, 2, 3, 3, 3};
int  mat [3][3] = {{1, 0, 1}, {2, 1, 2}, {3, 3, 3}};


Need of an Array:-
अरे की आवश्यकता:- 
we know that, In 'C' language user will need to create different variables for different values.These variables are stored at different memory addresses in computer memory and CPU spends so much time to access and store value of these variables so an array is used to store variables at continues memory bytes,where CPU can process them very fast together and also Programmer can not able to remember different names of all variables used in a program. Hence an array is used to resolve this problem because all variables will share same array name,only their indices are different.

हमें ज्ञात है की सी लैंग्वेज में भिन्न-भिन्न वेरिएबल द्वारा भिन्न-भिन्न वैल्यू को रखा जाता है जो मेमोरी में अलग-अलग स्थान ग्रहण करते है तथा सी.पी.यू. को इन वेरिएबल को एक्सेस एवं स्टोर करने में अधिक समय लगता है।इसीलिए अरे का प्रयोग किया जाता है जिससे एक ही प्रकार के वेरिएबल्स को एकसाथ रखा जा सके और सी.पी.यू. को अरे के एलेमेंट्स एक्सेस एवं स्टोर करने में कम समय लगे। साथ ही प्रोग्रामर द्वारा सभी वेरिएबल्स के नाम याद रख पाना भी कठिन होता है परन्तु एक अरे का नाम याद रखना आसान होता है।  
Example Programs :-

1D Array-
1.)C++ or C Program for Linear Search
2.)C++ or C Program for Bubble Sort

1 comment:

  1. This blog omg thank you so much for your amazing collection really ,i m student msc cs and your all collection is my totaly syllabus wonderful again thank you so much ....keep it up

    ReplyDelete

Stack Data Structure, Push, Pop and Peek Operations , Applications of Stack

Stack is a linear data structure. It is collection of ordered data elements. It is also known as LIFO system (last in first out). It means i...