Download presentation

Presentation is loading. Please wait.

Published byKya Bline Modified about 1 year ago

1
WELCOME TO ARRAY By Vinay Alexander PGT(CS) Kendriya vidyalaya jhagrakhand

2
Data Structure A Data Structure is a named group of different data types which can be processed as a single unit. A data structure has well-defined operations, behaviour and properties. That is it deal with the study of how data is organized in the memory,how efficiently the data can be retrieved and manipulated and possible ways in which different data items are logically related. It has three prospective: Application (or user) level: A way of modeling real-life data in a specific context. Abstract (or logical) level: An abstract collection of elements and its corresponding set of accessing operations. Implementation Level: A specific representation of the structure and its accessing operations in a programming language.

3
Types of Data Structure Simple Data Structure : These are normally built from primitive data types. Array and Structure Compound Data Structure: Simple data Structure can be combined in various ways to form more complex structure called compound data structure classified it two types: Linear: single level data structure. Elements form a sequence i.e. Stack, Queue and Linked List Non-Linear: multilevel i.e. Tree

4
Stack Stack refer to the lists stored and accessed in a special way i.e. LIFO technique. In stack, insertion and deletions take place only at one end called the top.

5
Queues Queues are FIFO lists, where insertions take place at the “rear” end of the queue and deletions take place at the “front” end of the queues.

6
Stack and Queue Operations

7
Link Lists Linked lists are special lists of some data elements linked to on another. The logical ordering is represented by having each element pointing to the next element. Each element is called node, which has two parts. The INFO part which stores the information and the POINTER part, which points to the next element.

8
Tree Tree are multilevel data structures having a hierarchical relationship among its elements called nodes. Topmost node is called root of the tree and bottommost nodes are called leaves of the tree.

9
Operation on Data Structures 1.Insertion 2.Deletion 3.Searching 4.Traversal 5.Sorting 6.Merging

10
Array The starting address of the very first element of the array is called Base Address of the array. The starting address of the very first element of the array is called Base Address of the array. ARRAY SIZE(LENGTH)=Upper Bound(UB)-Lower(LB)+1 => Address of element with subscript I=Base Address+ES(I-L).where ES is size of an array element.

11
Array Operations Searching: Linear Search: Each element of the array is compared with the given item to be searched for, one by one. This method, which traverses the array sequentially to locate the given item, is called linear search or sequential search. Binary Search: This search technique searches the given item in minimum possible comparisons. Array must be sorted in any order.

12
Searching : Linear Search #include int Lsearch(int [ ], int, int); void main( ) { int ar[50], item, n,index; cout<<“Enter desired array size (max 50) ”; cin>>n; cout<<“Enter array elements”; for(int i=0; i

13
Searching : Binary Search #include int Bsearch(int [ ], int, int); void main( ) { int ar[50], item, n,index; cout<<“Enter desired array size (max 50) ”; cin>>n; cout<<“Enter array elements (sorted in asc order)”; for(int i=0; i

14
Insertion in array: Insertion of new element in array can done in two ways (i). If the array is unordered,the new element is inserted at the end of array. (ii). If the array is sorted then new element is added at appropriate position without altering the order and to achieve this, rest of the elements are shifted

15
Insertion in array #include int FindPos(int [ ], int, int); void main( ) { int ar[50], item, n,index; cout<<“Enter desired array size (max 50) ”; cin>>n; cout<<“Enter array elements (sorted in asc order)”; for(int i=0; i

16
DELETION: The element to be deleted is first searched for in the array using one of the search techniques that is either linear search or binary search. if the search is successful, the element is removed and rest of the elements are shifted so as to keep the order of array undisturbed.

17
Deletion in array #include int Lsearch (int [ ], int, int); void main( ) { int ar[50], item, n,index; cout<<“Enter desired array size (max 50) ”; cin>>n; cout<<“Enter array elements (sorted in asc order)”; for(int i=0; i

18
Traversal in array #include void main( ) { int ar[50], item, n,index; cout<<“Enter desired array size (max 50) ”; cin>>n; cout<<“Enter array elements (sorted in asc order)”; for(int i=0; i

19
SELECTION SORT: The basic idea of a selection sort is to repeatedly selection the smallest key in the remaining unsorted array.

20
Selection Sorting in array #include int SelectionSort(int [], int); int main() { const int NUMEL = 10; int nums[NUMEL] = {22,5,67,98,45,32,101,99,73,10}; int i, moves; moves = SelectionSort(nums, NUMEL); cout << "The sorted list, in ascending order, is:\n"; for (i = 0; i < NUMEL; i++) cout << " " << nums[i]; cout << '\n' << moves << " moves were made to sort this list\n"; return 0; }

21
Selection Sorting in array int SelectionSort(int num[], int numel) { int i, j, min, minidx, grade, moves = 0; for ( i = 0; i < (numel - 1); i++) { min = num[i]; // assume minimum is the first array element minidx = i; // index of minimum element for(j = i + 1; j < numel; j++) { if (num[j] < min)// if we've located a lower value { // capture it min = num[j]; minidx = j;} } if (min < num[i])// check if we have a new minimum { // and if we do, swap values grade = num[i]; num[i] = min; num[minidx] = grade; moves++;} } return moves;}

22
Bubble Sorting in array: The basic idea of bubble sort is to compare two adjoining values and exchange them if they are not in proper order. that is unsorted array is to be sorted in ascending order using bubble sort.

23
Bubble Sorting in array #include int BubbleSort(int [], int); int main() { const int NUMEL = 10; int nums[NUMEL] = {22,5,67,98,45,32,101,99,73,10}; int i, moves; moves = BubbleSort(nums, NUMEL); cout << "The sorted list, in ascending order, is:\n"; for (i = 0; i < NUMEL; ++i) cout << " " <

24
Bubble Sorting in array int BubbleSort(int num[], int numel) { int i, j, grade, moves = 0; for ( i = 0; i < (numel - 1); i++) { for(j = 1; j < numel; j++) { if (num[j] < num[j-1]) { grade = num[j]; num[j] = num[j-1]; num[j-1] = grade; moves++; } } } return moves; }

25
Insertion Sorting in array void InSort ( int ar[], int size) { int tmp, j; ar[0]=INT_MIN; for(int i=1; i <=size ; i++) { tmp=ar[i]; j=i+1; while(tmp

26
Merge Sorting in array void MergeSort ( int A[ ], int M, int B[ ], int N, int C[ ]) { int a,b,c; for(a=0,b=N-1, c=-1; a =0;) { if (A[a]<=B[b]) C[c++] = A[a++]; else C[c++] = B [b--]; } if(a

27
TWO-Dimensional Arrays:

28

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google