Arrays. Elementary Data Representation Different Data Structure Operation on Data Structure Arrays

Size: px
Start display at page:

Download "Arrays. Elementary Data Representation Different Data Structure Operation on Data Structure Arrays"

Transcription

1 Arrays Elementary Data Representation Different Data Structure Operation on Data Structure Arrays

2 Elementary Data Representation Data can be in the form of raw data, data items and data structure. Raw Data Raw data are the facts or they are simply values or set of values Data Item Data items represents single unit of values of certain types. Data Structure A Data Structure is a named group of data of different data types which can be processed as a single unit. A data structure has well-defined operation behavior and properties. Record and Array is the example of the data structure.

3 Primitive and Non Primitive Data Types Data type can be either primitive or non primitive type Primitive This data type are those which are not composed of other data types. C++ named primitive data type as standard or fundamental data types which are int, float, long int, double long double and char. Non Primitive This data type are those which are composed by the primitive data types. Usually class, structure or union are the non primitive data types. Pointer These data types enables the storage the pointers (address) of some data location.

4 Different Data Structures Data Structure is very important in Computer System. As these not only allow the user to combine various data types in a group but also allow processing of the group as a single unit. Data structure be in two types. Simple Data Structure These data structure are normally built from primitive data types like integer, real char, Boolean etc These are ARRAY STRUCUTRE

5 Compound Data Structure Simple data structure can be combined in various ways to form more complex structure called Compound Data Structure. These are also classified into two ways. Linear Data Structure These data structure are single level data structure. A Data Structure is said to be linear if its elements form a sequence. Following are the linear data structures. Stack Queue Linked List Non Linear Data Structure These are the multilevel data structure. TREE is the example of Non linear data structure.

6 Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Ch 9 Data Structure - Architecture

7 Array Array refers to a named list of a finite number n of similar data elements. Each of the data elements can be referenced respectively by a set of consecutive numbers usually 0,1,2,3,.n-1 if total element is n. Array can be one dimensional, two dimensional and multidimensional. One Dimensional Array of 10 elements

8 Structure Structure refers to named collection of variables of different data types. A structure stores the different types of data items. The elements of the structure is refers with (.) dot operators. If the structure name is STRUC contains (Roll no, name, Marks, Grade) then individual field will be referenced as STRUC filed name.

9 Stack Stack is a Linear Data Structure, in which elements are processed in the LAST IN FIRST OUT (LIFO) fashion. In other words Stack is a linear list in which elements are add and removed at single end. The process of add element into stack is called PUSH. The process of delete element from stack is called POP The Recently added and that element which will remove first is called TOP element

10 Queue Queue is a Linear Data Structure, in which elements are processed in the FIRST IN FIRST OUT (FIFO) fashion. In other words Queue is a linear list in which elements are add and removed at different end. The recent added element is called REAR and that next removing element are called FRONT.

11 Linked List Linked lists are special lists of some data elements linked to one another. The logical ordering is represented by having each element pointing to the next element. Each element is called NODE, which have two or more parts, in which one of them is pointer part for next node and rest of all parts are data parts. Linked list may be single linked list or doubly linked list.

12 Tree Tree is a multilevel non linear data structure having a hierarchical relationship among its elements called nodes. Top most node is called the root of the tree and bottom most nodes are called the leaves of the tree. Root Node Leaf node

13 Operation on Data Structure The basic operation that has performed on the data structure are as follows Insertion It means addition of a new data element in a data structure. Deletion It means removal of a data element from the data structure. This element is searched for before its removal. Searching It involves searching for the specified data element in a data structure. Traversal Traversal of the data structure means processing all the data elements of it. Sorting Arranging data elements of a data structure in a specified order is called sorting. Merging Combining elements of two similar data structure to form a new data structure of same type

14 What is Array A Linear data structure is that whose elements form a sequence. When elements of linear data structure are represent in memory by means of sequential memory location, these linear data structure is called Array. Array is a simplest data structure and are easy to traverse, sort and search etc. Array is a list of finite number of homogeneous data elements. The number n is called length or size or range of an array. In C++ the lower bound is always 0 and the upper bound is size-1.

15 Need For Array Let us consider a situation, where we have to write a program which can accept marks of 50 students of a class, calculate average marks and difference of each student s marks with their average marks. If solve this problems by marking the variables, we need 50 variables for marks of students and 1 variable for average and 50 variables for their marks difference, overall 101 variables is needed for handles this situation, which is not an easy tasks. Due to this situation, we need a Data Structure which can hold multiple elements within a single variable called array.

16 Types of Array Array are of different types. First is One-Dimensional array in which finite homogeneous elements. Second is - Multi-Dimensional array in which each element are itself is an array. Here in multidimensional array means only two dimensional array.

17 Implementation of One Dim Array In memory, one dimensional arrays are implemented by allocating a sequence of addressed location. The address of starting element or address of 0 th element of array is called base address, which can never changes during program execution. Address of the i th element of array = base address + ES(i L), where ES is the size of element and l is the lower bound of array. int a[25], what is the address of a[17] where the base address is 1000? Ans = (17-0) = = 1034

18 Searching The are two searching algorithm Linear Search or sequential search In this type of search, We read a number for search and Compare with each element of array, wherever is found, then search successful and return otherwise search unsuccessful. Complexity of Linear search is O(n). Binary Search It is Mid point subdivision method, entire array is divided into two parts and compare the searching element with mid element, if found search successful otherwise the check the mid number is less or greater than searching. In that base the half list is ignored and again repeat this process until solution is found or search become unsuccessful. It complexity is O(log n)

19 Algorithm of Linear Search of n elements Let the Array of n elements is ARR and n is the size of array. 1. Set i = 0 2. Read the size of Array 3 Read (n); 4 Set i = 0 ; 5. Repeat step 6 & 7 n times 6 Set i = i Read (ARR(i)); 8 Print "Read a number of search "; 9 Read(s); 10 Set i = 0 10.Repeat step 12 & 13 n times 11 Set i = i If (ARR(i) = s) Print "Search Successful " & Return 13 Print "Search Unsuffessful "; 14 End.

20 Program for Linear Search for n elements #include<iostream.h> #include<conio.h> int main() { int n,arr[100],i,s; clrscr(); cout<<endl<<"enter the size of Array "; cin>>n; cout<<endl<<"enter"<<n<<" Elements of Array\n"; for(i-0;i<n;i++) cin>>arr[i]; cout<<endl<<"enter no to search "; cin>>s; for(i=0;i<n;i++) if (ARR[i]==s) {c cout<<endl<<"search is successful at "<<i+1<<"position"; return 0; } cout<<endl<<"search is unsuccessful "; return 0; }

21 Algorithm of Binary Search of n elements Let the Array of n elements is ARR and n is the size of array. 1. Set i = 0 2. Read the size of Array 3 Read (n); 4. Repeat step 5 & 6 n times 5 Set i = i Read (ARR(i)); 7. Sort the ARR elements by any sorting algorithm 8 Set beg = 1 and end = n; 9 Repeat the steps 10 to 13 until (beg >end) 10. Set mid = (beg + end) / 2 11 if (ARR[mid] = S) then Print "Search Successful at " Mid "Position" & return 12 if (ARR[mid] > s) then end = mid if (Arr[mid] < s) then beg = mid Print "Search Unsuffessful "; 15 End.

22 Program for Binary Search for n elements #include<iostream.h> #include<conio.h> int main() { int arr[100],n,beg,end,mid,s,i,j,t; clrscr(); //Read the size of Array cout<<endl<<"enter Size of Array "; cin>>n; //Read An Array cout<<endl<<"enter Array elements \n"; for(i=0;i<n;i++) cin>>arr[i]; //Sorting of Array for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(arr[i]>arr[j]) { t=arr[i]; arr[i]=arr[j]; arr[j]=t; } cout<<endl<<"enter No. to search "; cin>>s; // Searching beg=1; end=n; while(beg<=end) { mid=(beg+end)/2; if (arr[mid]==s) { cout<<"\n Search successful at postion "; getch(); return 0; } if (arr[mid]>s) end = mid - 1; if (arr[mid]<s) beg = mid + 1; } cout<<"\n Search Unsuccessful "; getch(); return 0; }

23

24 Insertion into Array Insertion of new element in array can be done in two ways. If the array is unordered, the new element is inserted at the end of the array. If the array is sorted then new element is added at their appropriate position without altering the order and to achieve this. Rest of elements are shifted.

25 Write a program to insert an element at end of array for unsorted array #include<iostream.h> #include<conio.h> void main() { int ar[100],i,n,s; clrscr(); // Read the size of array cout<<endl<<"enter Size of Array "; cin>>n; //Read the Array cout<<endl<<"enter Array Elements \n"; for(i=0;i<n;i++) cin>>ar[i]; //Read Inserting Elements cout<<endl<<"enter Element to Insert "; cin>>s; //Insert Element at end of array " ar[n]=s; //Print New Array cout<<endl<<"array Elements are \n"; for(i=0;i<=n;i++) cout<<ar[i]<<" "; getch(); }

26 Write an algo. to insert an element at end of array for unsorted array Let AR is the array of unsorted n elements and s is the element to insert at end of array AR. 1. Read(n) // size of array 2. Set I = 0 3. Repeat Step 4 and 5 n times 4. Set I = I Read AR[i]; 6. Read (s) // New Element 7. Set AR[n+1] = s; 8. Set I = 0 9. Repeat Step 10 and 11 n+1 times 10.Set I = I Print AR[i]; 12.Exit

27 Write a program to insert an element into sorted array. #include<iostream.h> #include<conio.h> void main() { int ar[100],i,n,s; clrscr(); // Read the size of array cout<<endl<<"enter Size of Array "; cin>>n; //Read the Sorted Array cout<<endl<<"enter Array Elements \n"; for(i=0;i<n;i++) cin>>ar[i]; //Read Inserting Elements cout<<endl<<"enter Element to Insert "; cin>>s; //Insert Element at their position " for(i=n-1;i>=0;i--) if (ar[i]>s) ar[i+1]=ar[i]; else break; ar[i+1]=s; //Print New Array cout<<endl<<"array Elements are \n"; for(i=0;i<=n;i++) cout<<ar[i]<<" "; getch(); }

28 Write an algorithm to insert an element into sorted array. Let AR is the array of unsorted n elements and s is the element to insert at end of array AR. 1. Read(n) // size of array 2. Set I = 0 3. Repeat Step 4 and 5 n times 4. Set I = I Read AR[i]; 6. Read (s) // New Element 7. Set I = n 8. Repeat Step 9 and 10 n times 9. If (AR[i]>s) then Set AR[i+1]=AR[i] else break; 10.Set I = I 1 11.Set I = 0 12.Repeat step 13 & 14 n+1 times 13.Set I = I Print AR[i] 15.Exit

29 Deleting an Element from Array The element to be deleted is first searched for in the array using one the search techniques either linear or binary. If search successful then delete the element rest are shifted. If the elements are shifted downward or towards right side, then unused elements are available in the beginning of the array.

30 Write a program to delete an element from unsorted array. #include<iostream.h> #include<conio.h> int main() { int arr[100],n,i,d,p=0; clrscr(); // Clear Screen //Read the size of array cout<<endl<<"enter size of Array "; cin>>n; //Read Array elements cout<<endl<<"enter Array elements "; for(i=0;i<n;i++) cin>>arr[i]; //Read the element to delete cout<<endl<<"enter element to delete "; cin>>d; //Find the element Location for(i=0;i<n;i++) if(arr[i]==d) p=i+1; // Check Un availability if (p==0) { cout<<endl<<"element Not Found Deletion Not Possible"; getch(); return 0; } else { // Deleting for(i=p-1;i<n;i++) arr[i]=arr[i+1]; // Print New Array cout<<endl<<"new Array "; for(i=0;i<n-1;i++) cout<<arr[i]<<" "; } getch(); return 0; }

31 Write a program to delete an element from sorted array. #include<iostream.h> #include<conio.h> int main() { int arr[100],n,i,d,j; clrscr(); // Clear Screen //Read the size of array cout<<endl<<"enter size of Array "; cin>>n; //Read Array elements cout<<endl<<"enter Array elements "; for(i=0;i<n;i++) cin>>arr[i]; i=0; //Read the element to delete cout<<endl<<"enter element to delete "; cin>>d; //Find the element Location while(arr[i]<d) i++; // Check Un availability if (arr[i]!=d) { cout<<endl<<"element Not Found Deletion Not Possible"; getch(); return 0; } Else { // Deleting for(j=i;j<n;j++) arr[j]=arr[j+1]; // Print New Array cout<<endl<<"new Array "; for(i=0;i<n-1;i++) cout<<arr[i]<<" "; } getch(); return 0; }

32 Sorting Array Elements Sorting of an array means arranging the array elements in a specified order. Either Ascending or Descending There are various SORTING mechanisms are available like Selection, Bubble, Insertion, Quick, Merge, Heap. The target of all mechanisms are same to sort the array, but the complexity and techniques are different. Ex - Oiginal Array Sorted Array

33 Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Ch 9 Selection Sort - Methodology

34 Write a program to sort array element by Selection Sort #include<iostream.h> #include<conio.h> void main() { int oa[100],sa[100],i,j,n,se,p; clrscr(); //Read the size of Array cout<<"\n Enter Array Size "; cin>>n; //Read Array Elements for(i=0;i<n;i++) cin>>oa[i]; //Print Original Array cout<<endl<<"original Array \n "; for(i=0;i<n;i++) cout<<oa[i]<<" "; //Sorting Logic j=-1; while(j<n) { se=32000; for(i=0;i<n;i++) if (oa[i]<se) {se=oa[i];p=i;} oa[p]=32500; j++; sa[j]=se; } //Print Sorted Array cout<<endl<<"sorted Array \n "; for(i=0;i<n;i++) cout<<sa[i]<<" "; getch(); }

35 Write a algo. to sort array element by Selection Sort 1 small = AR[L]; 2 For I = l to u { 3 small = AR[I]; 4 For J = I to U { 5 If AR[J] < small then { 6 small = AR[J] ; 7 pos = J; } // swap the smallest elements 8 temp = AR[I]; 9 AR[i] = small 10 AR[pos] = temp; 11 Exit

36 Bubble Sort It is to Compare two adjoining values and exchange them

37 Algorithm for Bubble Sort LOGIC 1. For I = L to U 2. { For J = L to (U - I - 1) 3. { if AR[J] > AR[J+1] then { 4. temp = AR[J]; 5. AR[J] = AR[J+1]; 6. AR[J+1] = temp; } } } 7. Exit

38 Write a program to sort array element by Bubble Sort #include<iostream.h> #include<conio.h> void main() { int ar[100],n,i,j,t; clrscr(); //Read the size of Array cout<<endl<<"emter Size of Array "; cin>>n; //Read the Array Elements; cout<<endl<<"enter Array elements :"; for(i=0;i<n;i++) cin>>ar[i]; //Print Original Array clrscr(); cout<<endl<<"original Array \n "; for(i=0;i<n;i++) cout<<ar[i]<<" "; //Bubble Sort Logic for(i=0;i< n-1;i++) for(j=0;j<(n-i-1);j++) if(ar[j]>ar[j+1]) { t=ar[j]; ar[j]=ar[j+1]; ar[j+1]=t; } //Print Original Array cout<<endl<<"sorted Array \n "; for(i=0;i<n;i++) cout<<ar[i]<<" "; getch(); }

39 Insertion Sort In this we insert a minimum possible value at 0 th Index This sorting algorithm is frequently used when n is small. For Ex This algorithm is very popular with bridge players when they are first sorting their cards.

40 Algorithm for Insertion Sort LOGIC 1. A[0]= Minimum Integer Value 2. Repeat step 3 through 8 for k = 1,2,.. N-1 { 3. temp = A 4. ptr = k-1 5. Repeat steps 6 to 7 while temp < A[ptr] { 6. A[ptr+1] = a[ptr]; 7. ptr = ptr 1; } 8. A[ptr + 1 ] = temp; 9. Exit

41 Write a program to sort array element by Insertion Sort #include<iostream.h> #include<conio.h> void main() { int ar[100],n,i,j,t; clrscr(); //Read the size of Array cout<<endl<<"emter Size of Array "; cin>>n; //Insert Minimum possible value at index 0 ar[0]=-32000; //Read the Array Elements; cout<<endl<<"enter Array elements :"; for(i=1;i<=n;i++) cin>>ar[i]; //Print Original Array clrscr(); cout<<endl<<"original Array \n "; for(i=0;i<n;i++) cout<<ar[i]<<" "; //Insertion Sort Logic for(i=1;i<=n;i++) for(j=0;j<=i;j++) if (ar[j]>ar[i]) { t=ar[j]; ar[j]=ar[i]; ar[i]=t; } //Print Sorted Array cout<<endl<<"sorted Array \n "; for(i=1;i<=n;i++) cout<<ar[i]<<" "; getch(); }

42 Merging of Arrays Merging means combining elements of two arrays to form a new array. Simplest way of merging two arrays is that first copy all the elements of first array into new arrays and then copy all the elements of second arrays at the end of new array and then sort new arrays if needed. Another popular technique to have a sorted resultant array is sorting while merging using merge sort. This technique of merge sort is more efficient than others techniques needs sorting of resultant array.

43 Algorithm - Merging of two unsorted arrays Resultant array is also unsorted Let A is the first array of size n and B is the second array of size m and C is the new array of size n+m elements. 1. Read(n) // size of array A 2. Read(m) // size of Array B 3. Set I = 0; 4. Repeat Step 5 and 6 n times 5. Set I = I Read A[i]; 7. Set I = 0; 8. Repeat Step 9 and 10 n times 9. Set I = I Read B[i]; 11.Set I = 0; 12.Repeat Step 13 and 14 n times 13.Set I = I C[I]=A[I]; 15.Set I = 0 16.Repeat step 17 & 18 m times 17.Set I = I C[n+I]= B[I]; 19.Set I = 0; 20.Repeat Step 21 and 22 n+m times 21.Set I = I Print C[I]; 23.Exit

44 Program - Merging of two unsorted arrays Resultant array is also unsorted #include<iostream.h> #include<conio.h> void main() { int a[100],b[100],c[100],m,n,i; clrscr(); //Read the size of Array A cout<<endl<<"emter Size of Array "; cin>>n; //Read the Array A Elements ; cout<<endl<<"enter Array elements :"; for(i=0;i<n;i++) cin>>a[i]; //Read the size of Array B cout<<endl<<"emter Size of Array "; cin>>m; //Read the Array B Elements ; cout<<endl<<"enter Array elements :"; for(i=0;i<m;i++) cin>>b[i]; //Merge Logic for(i=0;i<n;i++) c[i]=a[i]; for(i=0;i<m;i++) c[i+n]=b[i]; //Print Original Array A cout<<endl<<"array A elements \n "; for(i=0;i<n;i++) cout<<a[i]<<" "; //Print Original Array B cout<<endl<<"array B elements \n "; for(i=0;i<m;i++) cout<<b[i]<<" "; //Print Merged Array C cout<<endl<<"array Merged elements \n "; for(i=0;i<n+m;i++) cout<<c[i]<<" "; getch(); }

45 Algorithm - Merging of two Sorted arrays Resultant array is also Sorted 1.ctrA = L1 ; ctrb = l2 ; ctrc = L3 2.While ctra <= U1 and ctrb <= U2 perform steps 3 through 10 3.{ if A[ctrA] <= B[ctrB] then 4. { C[ctrC] = A[ctrA] 5. ctrc = ctrc ctra = ctra + 1 } 7. else 8. { C[ctrC] = B[ctrB] 9. ctrc = ctrc ctrb =ctrb + 1 } }/* End of while loop */ 11. if ctra > U1 then 12.{ while ctrb <= U2 perform steps 13 through { C[ctrC] = B[ctrB] 14. ctrc = ctrc ctrb = ctrb + 1 } } 16.if ctrb >U2 then 17.{ while ctra <= U1 perform steps 18 trough { C[ctrC] = A[ctrA] 19. ctrc = ctrc ctra = ctra + 1 } }

46 Program - Merging of two Sorted arrays Resultant array is also Sorted #include<iostream.h> #include<conio.h> void main() { int a[100],b[100],c[100],m,n,i,j,k; clrscr(); //Read the size of Array A cout<<endl<<"emter Size of Array "; cin>>n; //Read the Array A Elements ; cout<<endl<<"enter Array elements :"; for(i=0;i<n;i++) cin>>a[i]; //Read the size of Array B cout<<endl<<"emter Size of Array "; cin>>m; //Read the Array B Elements ; cout<<endl<<"enter Array elements :"; for(i=0;i<m;i++) cin>>b[i]; //Merge Logic i=j=k=0; while(i<=n && j<=m) if (a[i]<=b[j]) c[k++]=a[i++]; else c[k++]=b[j++]; if (i>n) while(j<=m) c[k++]=b[j++]; else while(i<=n) c[k++]=a[i++]; //Print Original Array A cout<<endl<<"array A elements \n "; for(i=0;i<n;i++) cout<<a[i]<<" "; //Print Original Array B cout<<endl<<"array B elements \n "; for(i=0;i<m;i++) cout<<b[i]<<" "; //Print Merged Array C cout<<endl<<"array Merged elements \n "; for(i=0;i<n+m;i++) cout<<c[i]<<" "; getch(); }

47 Implementation of 2D array in Memory While storing the element of 2D array in memory, these are needed contiguous locations. They are two alternative to achieve either Row Wise or Column Wise. The number of elements in 2-D array can be determined by Calculating number of rows and number of columns and then multiplying number of rows and columns.

48 Row Major Implementation In this technique stores firstly the first row of the array, then the second row of the array and so on. The computer does not keep trace of the address of all the elements of the array, but keep track the Base Address (Address of first element) and calculate the addresses of the element when required. The formula as follows. Address of in Row Major Order [I,J] = B + W [n(i-1) + (J - 1)] Where m are the number of rows and n are number of columns and W is the size of data type. And I & J are the Element subscript number

49 1. A 2-D array defined as A[4.. 7, ] requires 2 words of storage space for each element if the array is stored in row-major form calculate the address of A[6,2] given the base address as 100(one hundred). sol: Base address B = 100 Element size W = 2 bytes Lr = 4; Lc=-1; i =6; j=2 n,number of rows =Ur - Lr + 1 = = 4 c,number of columns =Uc - Lc + 1 = 3-(-1)+1 = 5 Address[I,J] =B+w(c(i-Lr) + (j -Lc)) =100+2(5(6-4)+2-(-1)) =100+2(5*2+3)=100+2*(13) =100+26= X is 2-D array [10*5].Each element of the array is stored in 2 memory location.if X[1,1] begins at address 150,find the location of X[3,4].use the formula for calculation (The arrangement is in row major). sol: Base address B=150 Element size W=2 number of columns n=5 Lr = Lc =1 Location X[3,4] = (5(3-1)+(4-1)) = (10+3) = = 176.

50 Column Major Implementation In this technique stores firstly the first column of the array, then the second column of the array and so on. The computer does not keep trace of the address of all the elements of the array, but keep track the Base Address (Address of first element) and calculate the addresses of the element when required. The formula as follows. Address of in Column Major Order [I,J] = B + W [m(j-1) + (I - 1)] Where m are the number of rows and n are number of columns and W is the size of data type. And I & J are the Element subscript number

51 1. Each element of an array A[ , ] requires one byte of storage. if the array is stored in column major order beginning location 500,determine the location of A[0,30]. sol: Base address B =500 Element size W = 1byte r (number of rows) are 20 - (-20)+1=41 1r = -20; 1c =10 Address of A[0,30] = [(0-(-20) +41(30-10))] = (20+41*20) = [20+820]= = Each element of an array A[ , ] requires one byte of storage.if the array is stored in column major order begining location 1000, determine the location of A[0,40]. sol: Base address B = 1000 Element size W = 1 byte Number of rows = 20-(-15)+1=36 1r=-15, 1c=20 Address of A[0,40] = [0-(-15))+36(40-20)] = [ * 20] = [15+720] = = 1735.

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning. Chapter4: s Data: It is a collection of raw facts that has implicit meaning. Data may be single valued like ID, or multi valued like address. Information: It is the processed data having explicit meaning.

More information

Downloaded from

Downloaded from Unit-II Data Structure Arrays, Stacks, Queues And Linked List Chapter: 06 In Computer Science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

More information

CSE202- Lec#6. (Operations on CSE202 C++ Programming

CSE202- Lec#6. (Operations on CSE202 C++ Programming Arrays CSE202- Lec#6 (Operations on Arrays) Outline To declare an array To initialize an array Operations on array Introduction Arrays Collection of related data items of same data type. Static entity

More information

Introduction to Arrays

Introduction to Arrays Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

Types of Data Structures

Types of Data Structures DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

Classification s of Data Structures

Classification s of Data Structures Linear Data Structures using Sequential organization Classification s of Data Structures Types of Data Structures Arrays Declaration of arrays type arrayname [ arraysize ]; Ex-double balance[10]; Arrays

More information

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data Structure. IBPS SO (IT- Officer) Exam 2017 Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 17 EXAMINATION Subject Name: Data Structure Using C Model Answer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as

More information

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012 Data Abstractions National Chiao Tung University Chun-Jen Tsai 05/23/2012 Concept of Data Structures How do we store some conceptual structure in a linear memory? For example, an organization chart: 2/32

More information

// array initialization. void main() { cout<<b[4]<<endl; cout<<b[5]<<endl; } Output is 9

// array initialization. void main() { cout<<b[4]<<endl; cout<<b[5]<<endl; } Output is 9 UNIT-2 DATA STRUCTURES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. The data structure can be classified into following two types:

More information

An array is a collection of similar elements that is all the elements in an array should have same data type. This means that an array can store

An array is a collection of similar elements that is all the elements in an array should have same data type. This means that an array can store An array is a collection of similar elements that is all the elements in an array should have same data type. This means that an array can store either all integers, all floating point numbers, all characters,

More information

The time and space are the two measure for efficiency of an algorithm.

The time and space are the two measure for efficiency of an algorithm. There are basically six operations: 5. Sorting: Arranging the elements of list in an order (either ascending or descending). 6. Merging: combining the two list into one list. Algorithm: The time and space

More information

Lecture 6 Sorting and Searching

Lecture 6 Sorting and Searching Lecture 6 Sorting and Searching Sorting takes an unordered collection and makes it an ordered one. 1 2 3 4 5 6 77 42 35 12 101 5 1 2 3 4 5 6 5 12 35 42 77 101 There are many algorithms for sorting a list

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

Sorting is ordering a list of objects. Here are some sorting algorithms

Sorting is ordering a list of objects. Here are some sorting algorithms Sorting Sorting is ordering a list of objects. Here are some sorting algorithms Bubble sort Insertion sort Selection sort Mergesort Question: What is the lower bound for all sorting algorithms? Algorithms

More information

Answers. 1. (A) Attempt any five : 20 Marks

Answers. 1. (A) Attempt any five : 20 Marks Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS 1. Define global declaration? The variables that are used in more

More information

[ DATA STRUCTURES] to Data Structures

[ DATA STRUCTURES] to Data Structures [ DATA STRUCTURES] Chapter - 01 : Introduction to Data Structures INTRODUCTION TO DATA STRUCTURES A Data type refers to a named group of data which share similar properties or characteristics and which

More information

Higher National Diploma in Information Technology. First Year Second Semester Examination IT 2003-Data Structure and Algorithm.

Higher National Diploma in Information Technology. First Year Second Semester Examination IT 2003-Data Structure and Algorithm. Higher National Diploma in Information Technology First Year Second Semester Examination-2013 IT 2003-Data Structure and Algorithm Answer Guide (01) I)What is Data structure A data structure is an arrangement

More information

AE52/AC52/AT52 C & Data Structures JUNE 2014

AE52/AC52/AT52 C & Data Structures JUNE 2014 Q.2 a. Write a program to add two numbers using a temporary variable. #include #include int main () int num1, num2; clrscr (); printf( \n Enter the first number : ); scanf ( %d, &num1);

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure using C Model wer Subject Code: 22317 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given

More information

1. INTRODUCTION TO DATA STRUCTURE

1. INTRODUCTION TO DATA STRUCTURE 1. INTRODUCTION TO DATA STRUCTURE 1.1 What is Data Structure? Data Structure: Data structure is a way to storing and organizing data in a computer so that it can be used efficiently. Data structure is

More information

:: Computer Science C++ Important Questions ::

:: Computer Science C++ Important Questions :: :: Computer Science C++ Important Questions :: 1 Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in descending order. Example: If an array of

More information

ARRAY FUNCTIONS (1D ARRAY)

ARRAY FUNCTIONS (1D ARRAY) ARRAY FUNCTIONS (1D ARRAY) EACH QUESTIONS CARRY 2 OR 3 MARKS Q.1 Write a function void ChangeOver(int P[ ], int N) in C++, which re-positions all the elements of the array by shifting each of them to the

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

LECTURE NOTES ON DATA STRUCTURES THROUGH C

LECTURE NOTES ON DATA STRUCTURES THROUGH C LECTURE NOTES ON DATA STRUCTURES THROUGH C Revision 4 July 2013 L. V. NARASIMHA PRASAD Professor and Head E. KRISHNARAO PATRO Associate Professor Department of Computer Science and Engineering Shamshabad,Hyderabad

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

To store the total marks of 100 students an array will be declared as follows,

To store the total marks of 100 students an array will be declared as follows, Chapter 4 ARRAYS LEARNING OBJECTIVES After going through this chapter the reader will be able to declare and use one-dimensional and two-dimensional arrays initialize arrays use subscripts to access individual

More information

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon Data Structures &Al Algorithms Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon What is Data Structure Data Structure is a logical relationship existing between individual elements

More information

Sorting & Searching. Hours: 10. Marks: 16

Sorting & Searching. Hours: 10. Marks: 16 Sorting & Searching CONTENTS 2.1 Sorting Techniques 1. Introduction 2. Selection sort 3. Insertion sort 4. Bubble sort 5. Merge sort 6. Radix sort ( Only algorithm ) 7. Shell sort ( Only algorithm ) 8.

More information

Q2: Write an algorithm to merge two sorted arrays into a third array? (10 Marks) Ans Q4:

Q2: Write an algorithm to merge two sorted arrays into a third array? (10 Marks) Ans Q4: Model Answer Benha University 1 st Term (2013/2014) Final Exam Class: 2 nd Year Students Subject: Data Structures Faculty of Computers & Informatics Date: 26/12/2013 Time: 3 hours Examiner: Dr. Essam Halim

More information

a) State the need of data structure. Write the operations performed using data structures.

a) State the need of data structure. Write the operations performed using data structures. Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link

More information

Q (Quaternary) Search Algorithm

Q (Quaternary) Search Algorithm Q (Quaternary) Search Algorithm Taranjit Khokhar Abstract In computer science, there are many ways to search the position of the required input value in an array. There are algorithms such as binary search

More information

DC54 DATA STRUCTURES DEC 2014

DC54 DATA STRUCTURES DEC 2014 Q.2 a. Write a function that computes x^y using Recursion. The property that x^y is simply a product of x and x^(y-1 ). For example, 5^4= 5 * 5^3. The recursive definition of x^y can be represented as

More information

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging. Priority Queue, Heap and Heap Sort In this time, we will study Priority queue, heap and heap sort. Heap is a data structure, which permits one to insert elements into a set and also to find the largest

More information

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the

More information

UNIT-I Fundamental Notations

UNIT-I Fundamental Notations UNIT-I Fundamental Notations Introduction to Data Structure We know that data are simply values or set of values and information is the processed data. And actually the concept of data structure is much

More information

Data Structures. Chapter 04. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

Data Structures. Chapter 04. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU Data Structures Chapter 04 1 Linear Array A linear array is a list of finite number N of homogeneous data elements such that: The elements of the array are referenced respectively by an index set consisting

More information

Programming in C++ (Educational Support)

Programming in C++ (Educational Support) Programming in C++ (Educational Support) http:// 1. WRITE A PROGRAM TO TRAVERSING OF AN ARRAY. #include # include void main () int a [10], lb = 1, ub, k, I; cout

More information

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency Introduction Fundamentals Declaring arrays Indexing arrays Initializing arrays Arrays and functions Multidimensional arrays Sorting and algorithm efficiency An array is a sequence of values of the same

More information

2. ARRAYS What is an Array? index number subscrip 2. Write array declarations for the following: 3. What is array initialization?

2. ARRAYS What is an Array? index number subscrip 2. Write array declarations for the following: 3. What is array initialization? 1 2. ARRAYS 1. What is an Array? Arrays are used to store a set of values of the same type under a single variable name. It is a collection of same type elements placed in contiguous memory locations.

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search

More information

Maltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers

Maltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers Maltepe University Computer Engineering Department BİL 133 Algoritma ve Programlama Chapter 8: Arrays and pointers Basics int * ptr1, * ptr2; int a[10]; ptr1 = &a[2]; ptr2 = a; // equivalent to ptr2 =

More information

Unit 2: Data Structures

Unit 2: Data Structures Unit 2: Data Structures 2.1: Arrays ARRAYS Introduction to data structure, Arrays, One Dimensional Array, Basic operations on 1-D array: traversal, Searching- linear, binary search, insertion, deletion,

More information

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer: Chapter-11 POINTERS Introduction: Pointers are a powerful concept in C++ and have the following advantages. i. It is possible to write efficient programs. ii. Memory is utilized properly. iii. Dynamically

More information

Abstract Data Type: Stack

Abstract Data Type: Stack Abstract Data Type: Stack Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations

More information

Data Structures and Algorithms in Java. Second Year Software Engineering

Data Structures and Algorithms in Java. Second Year Software Engineering Data Structures and Algorithms in Java Second Year Software Engineering Introduction Computer: is a programmable machine that can store, retrieve and process data. Data: The representation of information

More information

NCS 301 DATA STRUCTURE USING C

NCS 301 DATA STRUCTURE USING C NCS 301 DATA STRUCTURE USING C Unit-1 Part-3 Arrays Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncs301ds.wordpress.com Introduction Array is a contiguous memory of homogeneous

More information

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Chapter 6 Inheritance Extending a Class

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Chapter 6 Inheritance Extending a Class Chapter 6 Inheritance Extending a Class Introduction; Need for Inheritance; Different form of Inheritance; Derived and Base Classes; Inheritance and Access control; Multiple Inheritance Revisited; Multilevel

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

1. Write step by step code to delete element from existing Doubly Linked List. Suppose that all declarations are done

1. Write step by step code to delete element from existing Doubly Linked List. Suppose that all declarations are done 1. Write step by step code to delete element from existing Doubly Linked List. Suppose that all declarations are done. first NULL 42 A A 13 A A 6 NULL Write code here first NULL 42 A A 13 A A 6 NULL p

More information

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US02CBCA01 (Advanced C Programming and Introduction to Data Structures) *UNIT 3 (Introduction to Data

More information

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \ BSc IT C Programming (2013-2017) Unit I Q1. What do you understand by type conversion? (2013) Q2. Why we need different data types? (2013) Q3 What is the output of the following (2013) main() Printf( %d,

More information

[ DATA STRUCTURES ] Fig. (1) : A Tree

[ DATA STRUCTURES ] Fig. (1) : A Tree [ DATA STRUCTURES ] Chapter - 07 : Trees A Tree is a non-linear data structure in which items are arranged in a sorted sequence. It is used to represent hierarchical relationship existing amongst several

More information

Arrays and Strings. Arash Rafiey. September 12, 2017

Arrays and Strings. Arash Rafiey. September 12, 2017 September 12, 2017 Arrays Array is a collection of variables with the same data type. Arrays Array is a collection of variables with the same data type. Instead of declaring individual variables, such

More information

Solution for Data Structure

Solution for Data Structure Solution for Data Structure May 2016 INDEX Q1 a 2-3 b 4 c. 4-6 d 7 Q2- a 8-12 b 12-14 Q3 a 15-18 b 18-22 Q4- a 22-35 B..N.A Q5 a 36-38 b N.A Q6- a 39-42 b 43 1 www.brainheaters.in Q1) Ans: (a) Define ADT

More information

Chapter 8: Data Abstractions

Chapter 8: Data Abstractions Chapter 8: Data Abstractions Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Copyright 2012 Pearson Education, Inc. Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2

More information

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Code: 17330 Model Answer Page 1/ 22 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model

More information

Arrays. Dr. Madhumita Sengupta. Assistant Professor IIIT Kalyani

Arrays. Dr. Madhumita Sengupta. Assistant Professor IIIT Kalyani Arrays Dr. Madhumita Sengupta Assistant Professor IIIT Kalyani INTRODUCTION An array is a collection of similar data s / data types. The s of the array are stored in consecutive memory locations and are

More information

1. Two main measures for the efficiency of an algorithm are a. Processor and memory b. Complexity and capacity c. Time and space d.

1. Two main measures for the efficiency of an algorithm are a. Processor and memory b. Complexity and capacity c. Time and space d. 1. Two main measures for the efficiency of an algorithm are a. Processor and memory b. Complexity and capacity c. Time and space d. Data and space 2. The time factor when determining the efficiency of

More information

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1 (a) List any four relational operators.

More information

3. Fundamental Data Structures

3. Fundamental Data Structures 3. Fundamental Data Structures CH08-320201: Algorithms and Data Structures 233 Data Structures Definition (recall): A data structure is a way to store and organize data in order to facilitate access and

More information

MODULE 5: Pointers, Preprocessor Directives and Data Structures

MODULE 5: Pointers, Preprocessor Directives and Data Structures MODULE 5: Pointers, Preprocessor Directives and Data Structures 1. What is pointer? Explain with an example program. Solution: Pointer is a variable which contains the address of another variable. Two

More information

CMSC Introduction to Algorithms Spring 2012 Lecture 7

CMSC Introduction to Algorithms Spring 2012 Lecture 7 CMSC 351 - Introduction to Algorithms Spring 2012 Lecture 7 Instructor: MohammadTaghi Hajiaghayi Scribe: Rajesh Chitnis 1 Introduction In this lecture we give an introduction to Data Structures like arrays,

More information

Binary Trees. Height 1

Binary Trees. Height 1 Binary Trees Definitions A tree is a finite set of one or more nodes that shows parent-child relationship such that There is a special node called root Remaining nodes are portioned into subsets T1,T2,T3.

More information

Columns A[0] A[0][0] = 20 A[0][1] = 30

Columns A[0] A[0][0] = 20 A[0][1] = 30 UNIT Arrays and Strings Part A (mark questions). What is an array? (or) Define array. An array is a collection of same data type elements All elements are stored in continuous locations Array index always

More information

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT III LINEAR DATA STRUCTURES PART A 1. What is meant by data

More information

Subject: Fundamental of Computer Programming 2068

Subject: Fundamental of Computer Programming 2068 Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find

More information

Pointers. Introduction

Pointers. Introduction Pointers Spring Semester 2007 Programming and Data Structure 1 Introduction A pointer is a variable that represents the location (rather than the value) of a data item. They have a number of useful applications.

More information

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size]; Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data

More information

KENDRIYA VIDYALYA CLRI CHENNAI AUTUMN BREAK HOLIDAY HW MARKS QUESTIONS : DATA STRUCTURE

KENDRIYA VIDYALYA CLRI CHENNAI AUTUMN BREAK HOLIDAY HW MARKS QUESTIONS : DATA STRUCTURE KENDRIYA VIDYALYA CLRI CHENNAI AUTUMN BREAK HOLIDAY HW 8 MARKS QUESTIONS : DATA STRUCTURE. Write a function in C++ which accepts an integer array and its size as arguments and change all the even number

More information

LECTURE 17. Array Searching and Sorting

LECTURE 17. Array Searching and Sorting LECTURE 17 Array Searching and Sorting ARRAY SEARCHING AND SORTING Today we ll be covering some of the more common ways for searching through an array to find an item, as well as some common ways to sort

More information

Programming and Data Structure Solved. MCQs- Part 2

Programming and Data Structure Solved. MCQs- Part 2 Programming and Data Structure Solved MCQs- Part 2 Programming and Data Structure Solved MCQs- Part 2 Unsigned integers occupies Two bytes Four bytes One byte Eight byte A weather forecasting computation

More information

Linear Data Structure

Linear Data Structure Linear Data Structure Definition A data structure is said to be linear if its elements form a sequence or a linear list. Examples: Array Linked List Stacks Queues Operations on linear Data Structures Traversal

More information

Basic Data Structures (Version 7) Name:

Basic Data Structures (Version 7) Name: Prerequisite Concepts for Analysis of Algorithms Basic Data Structures (Version 7) Name: Email: Concept: mathematics notation 1. log 2 n is: Code: 21481 (A) o(log 10 n) (B) ω(log 10 n) (C) Θ(log 10 n)

More information

Data Structure & Algorithms Laboratory Manual (CS 392)

Data Structure & Algorithms Laboratory Manual (CS 392) Institute of Engineering & Management Department of Computer Science & Engineering Data Structure Laboratory for 2 nd year 3 rd semester Code: CS 392 Data Structure & Algorithms Laboratory Manual (CS 392)

More information

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

CSCE 2014 Final Exam Spring Version A

CSCE 2014 Final Exam Spring Version A CSCE 2014 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers

More information

DEEPIKA KAMBOJ UNIT 2. What is Stack?

DEEPIKA KAMBOJ UNIT 2. What is Stack? What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you

More information

O(n): printing a list of n items to the screen, looking at each item once.

O(n): printing a list of n items to the screen, looking at each item once. UNIT IV Sorting: O notation efficiency of sorting bubble sort quick sort selection sort heap sort insertion sort shell sort merge sort radix sort. O NOTATION BIG OH (O) NOTATION Big oh : the function f(n)=o(g(n))

More information

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues By: Pramod Parajuli, Department of Computer Science, St. Xavier

More information

MODULE V: POINTERS & PREPROCESSORS

MODULE V: POINTERS & PREPROCESSORS MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which

More information

Review of Important Topics in CS1600. Functions Arrays C-strings

Review of Important Topics in CS1600. Functions Arrays C-strings Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

More information

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of

More information

CHAPTER 9 FLOW OF CONTROL

CHAPTER 9 FLOW OF CONTROL CHAPTER 9 FLOW OF CONTROL FLOW CONTROL In a program statement may be executed sequentially, selectively or iteratively. Every program language provides constructs to support sequence, selection or iteration.

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures

More information

Guide for The C Programming Language Chapter 5

Guide for The C Programming Language Chapter 5 1. Differentiate between primitive data type and non-primitive data type. Primitive data types are the basic data types. These data types are used to represent single values. For example: Character, Integer,

More information

MTH 307/417/515 Final Exam Solutions

MTH 307/417/515 Final Exam Solutions MTH 307/417/515 Final Exam Solutions 1. Write the output for the following programs. Explain the reasoning behind your answer. (a) #include int main() int n; for(n = 7; n!= 0; n--) printf("n =

More information

Principles of Programming. Chapter 6: Arrays

Principles of Programming. Chapter 6: Arrays Chapter 6: Arrays In this chapter, you will learn about Introduction to Array Array declaration Array initialization Assigning values to array elements Reading values from array elements Simple Searching

More information

C++ PROGRAMMING SKILLS Part 4: Arrays

C++ PROGRAMMING SKILLS Part 4: Arrays C++ PROGRAMMING SKILLS Part 4: Arrays Outline Introduction to Arrays Declaring and Initializing Arrays Examples Using Arrays Sorting Arrays: Bubble Sort Passing Arrays to Functions Computing Mean, Median

More information

POINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory

More information

Data Structure for Language Processing. Bhargavi H. Goswami Assistant Professor Sunshine Group of Institutions

Data Structure for Language Processing. Bhargavi H. Goswami Assistant Professor Sunshine Group of Institutions Data Structure for Language Processing Bhargavi H. Goswami Assistant Professor Sunshine Group of Institutions INTRODUCTION: Which operation is frequently used by a Language Processor? Ans: Search. This

More information

Linked List. April 2, 2007 Programming and Data Structure 1

Linked List. April 2, 2007 Programming and Data Structure 1 Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element

More information

Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection

Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection Morteza Noferesti Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful

More information

Problems with simple variables

Problems with simple variables Problems with simple variables Hard to give up values high number of variables. Complex to sort a high number of variables by value. Impossible to use loops. Example problem: Read one hundred numbers,

More information