Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer DATA STRUCTURE SIMPLE ARRAYS COMPOUND LINEAR NON-LINEAR LINKED LIST TREES STACKS GRAPHS QUEUES DATA STRUCTURE The logical and mathematical model of particular organization of data is called DATA STRUCTURE. Data Structures are containers for data. The simplest of them are called “atomic” because they hold only a single value and cannot be subdivided into lower-level components. Other “compound” data structures may hold multiple pieces of data, and are constructed from atomic types. SIMPLE DATA STRUCTURE Arrays The group of linked similar type of elements by one common name then it is called as array . Its is the simplest type of data structure. Array it is a container that holds a fixed length . 0 1 2 3 4 5 6 7 8 9 20 Array length is 10 o It is start at 0 ARRAY .. CONT • Array Definition: int x[100]; char text[80]; • Array Initialization: int digits[5]={1,2,3,4,5}; char color[3]={‘R’, ‘E’, ‘D’}; • Multidimensional Arrays: int values[3][4]= { {1,2,3,4}, {5,6,7,8}, {9,10,11,12} } String: In C Strings are defined as arrays of characters.There are special string handling library routines like strcmp(s1,s2), strcpy(s1,s2),strlen(s) REPRESENTATION OF ARRAY One IN MEMORY Dimensional array Location(X[I])=Base Address+(I-1) E.g : Find X[4] , Base Address=500 Location(X[I])=Base Address+(I-1) Location(X[4])=500 +(4 -1) =503 REPRESENT TWO DIMENSIONAL ARRAY 1- Row – wise Method Location ( A[ i , j] )= base address +N *( i-1 )+( j-1 ) E.G :- A[5,7], M=5, N=7, Base Address=900 Find A[ 4 , 6 ] Location(A [I,J])=Base Address +N*(I-1)+(J-1) Location(A [4,6])=Base Address+7 *(4 -1)+(6 -1) =900+21+5 =926 2- COLUMN – WISE METHOD Location(A [I,J])=Base Address + M *(J -1)+(I -1) E.g. A[5,7], M=5, N=7, Base Address=900 Find A[ 4 , 6 ] Location(A [4,6])=900 +5 *(6 -1)+(4 -1) =900+25+3 =928 #include<iostream.h> int sort[5]; int item,i,j; void main() { cout<<"enter elements of array "<<endl; for(i=0;i<5;i++) { cin>>sort[i]; } item=0; for(i=0;i<5;i++) for(j=i+1;j<5;j++) { if(sort[j]<sort[i]) item=sort[i]; sort[i]=sort[j]; sort[j]=item; } //output sorting array cout<<"output sorrting array"<<endl; for(i=0;i<5;i++) cout<<sort[i]<<endl; getch(); } ASSIGNMENT -21- find the large number and small number in array ? 2- find an element in array where K any element ?