Operations on Arrays. Operation on Array Data Structures  Traversal  Selection  Searching  Insertion  Deletion  Sorting.

Slides:



Advertisements
Similar presentations
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
Advertisements

Sort the given string, without using string handling functions.
Dynamic Memory Allocation
ICS103: Programming in C Searching, Sorting, 2D Arrays
Introduction to C Programming CE Lecture 11 Sorting and Searching using Arrays.
1 Array Knowledge Understand the execute technique of array Skill Can write application program using one and two dimensional array.
1 Passing Array Array’s element can be passed individually to a function; copying value exist during passing process. An entire array can be passed to.
Guidelines for working with Microsoft Visual Studio.Net.
Array Must declare a variable to reference the array double [] mylist; // cannot double list[20]; Or double mylist[]; The declaration doesn’t allocate.
Guidelines for working with Microsoft Visual Studio 6.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
If () else statement, switch statement, while () loop, do…while() loop and for( ; ; ) loop 1.
Value Iteration 0: step 0. Insertion Sort Array index67 Iteration i. Repeatedly swap element i with.
More Questions 1) Write a C program to read a matrix A of size nXn and two arrays X and Y of size n and calculate XA-Y?
Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Data Structure: List.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
Part 2. Searching Arrays Looking for a specific element in an array E.g., whether a certain score (85) is in a list of scores Linear search Binary search.
CPT: Search/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to discuss searching: its implementation,
EENG212 Algorithms and Data Structures
Array.
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 8: Arrays.
UNIT 1 Data Structures Using C Linked List By Rohit Khokher Department of Computer Science, Vidya College of Engineering, Meerut, India.
SEARCHING UNIT II. Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances.
Write a C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function.
Arrays.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
PRESENTATION ON SEARCHING SEARCHING Searching is the method to find element from the list of the elements. If element is found then it.
CS 162 Intro to Programming II Searching 1. Data is stored in various structures – Typically it is organized on the type of data – Optimized for retrieval.
Searching and Sorting Techniques 1. To learn and appreciate the following concepts Searching Technique  Linear Search Sorting Technique  Bubble Sort.
Searching. Linear (Sequential) Search Search an array or list by checking items one at a time. Linear search is usually very simple to implement, and.
ARRAY Prepared by MMD, Edited by MSY1.  Introduction to arrays  Declaring arrays  Initializing arrays  Examples using arrays  Relationship with pointers.
Computer Science 210 Computer Organization Arrays.
Chapter 6: Control Structures Computer Programming Skills Second Term Department of Computer Science Foundation Year Program Umm Alqura.
Chapter 8: Arrays Introduction to arrays Declaring arrays Initializing arrays Examples using arrays Relationship with pointers Array passing to a function.
1 Traversal algorithms. 2 Array traversal traversal: An examination of each element of an array. Traversal algorithms often takes the following form:
Queues EENG212 Algorithm And Data Structures. DEFINITION OF QUEUE A Queue is an ordered collection of items from which items may be deleted at one end.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 3.
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
Sorting & Searching Review. Selection Sort 1. Find the smallest element 2. Move to the front of the array (swap with front) 3. Repeat Steps 1&2, but ignoring.
Introduction Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Bit Manipulation. Get Bit from the particular Position Suppose you want to get a bit from the 4 th position. You can call int get_bit_val(int number_send,int.
ICS103: Programming in C Searching, Sorting, 2D Arrays Muhamed F. Mudawar.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Prepared by MMD, Edited by MSY1 CHAPTER 4 ARRAY. Prepared by MMD, Edited by MSY2 Arrays  Introduction to arrays  Declaring arrays  Initializing arrays.
Rray Programs. Insert and element in the given position of the Array rray.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
Selection Sort main( ) { int a[ ] = { 17, 6, 13,12, 2 } ; int i, j, t ; for ( i = 0 ; i
Write a C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function.
Computer Programming for Engineers
C A RRAY Continue one dimensional array 1. Assume we have define this array: int hourlyTemp[ 24 ]; And we need to insert this array as parameter into.
Linked List. LINKED LIST Link is collection of similar type of elements. There are two ways of maintaining a list in memory. The first way is store the.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
Computer Science Department Data Structure and Algorithms Lecture 3 Stacks.
Dr. Sajib Datta CSE 1320 Arrays, Search and Sort.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
2 - Arrays Introducing Arrays Declaring Array Variables, Creating Arrays, and Initializing Arrays Ordered and Unordered Arrays Common Operations: Insertion,
Arrays Name, Index, Address. Arrays – Declaration and Initialization int x; y[0] y[1] y[2]
1 compares each element of the array with the search key. works well for small arrays or for unsorted arrays works for any table slow can put more commonly.
Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional Array Explain Arrays.
MAHENDRAN. Session Objectives Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional.
Chapter 5 Ordered List.
CHP-2 ARRAYS.
Arrays (Operations on Arrays)
Array 9/8/2018.
Chapter 5 Ordered List.
ICS103: Programming in C Searching, Sorting, 2D Arrays
Presentation transcript:

Operations on Arrays

Operation on Array Data Structures  Traversal  Selection  Searching  Insertion  Deletion  Sorting

Traversal Traversal is an operation in which each element of a list, stored in an array, is visited. The travel proceeds from the zero th element to the last element of the list.

WAP that travels on list and determine no of elements are 0 #include void main() { int list[10]; int n; Int i, neg=0, zero=0, pos=0; printf(“\n enter the size of the list\n”); scanf(“%d”,&n); printf(“Enter the elements one by one”); for(i=0;i<n;i++) { printf(“\n Enter number %d number”,i); scanf(“%d”, &list[i]); } for(i=0;i<n;i++) { if(list[i]<0) neg=neg+1; else if(list[i]==0) zero=zero+1; else pos=pos+1; } Printf(“No of Negative numbers in given list are %d”, neg); Printf(“No of Zeros in given list are %d”, zero); Printf(“No of Positive numbers in given list are %d”, pos); }

Selection An array allows selection of an element for given index. Array is called as random access data structure.

#include void main() { float merit[10]; int size,i,pos,choice; float percentage; printf(“\n Enter the size of the list”); scanf(“%d”, &size); printf(“\n Enter the merit list one by one”); for(i=0; i < size; i++) { printf(“\n Enter Data:”); scanf(“%f”, &merit[i]); } do { clrscr(); printf(“\n menu”); printf(“\n Querry…….1”); printf(“\n Quit…………2”); printf(“\n Enter your choice”); scanf(“%d”,&choice); switch(choice) { case 1: printf(“\n Enter position”); scanf(“%d”, &pos); percentage=merit[pos]; printf(“\n percentage=%4.2f”, percentage); break; case 2: printf(“\n Quitting”); } printf(“”\n press a key to continue…:); getch(); } while(choice!=2); }

Searching Search is an operation in which a given list is searched for a particular value. A list can be searched sequentially wherein the search for the data item starts from the beginning and continues till the end of the list. This method is called linear Search.

#include void main() { int numlist[20]; int n,pos, val,i; printf(“\n enter the size of the list”); scanf(“%d”, &n); printf(“\n Enter the elements one by one”); for(i=0;i<n;i++) { scanf(“%d”, &numlist[i]); } Printf(“\n Enter the value to be searched”); Scanf(“%d”, &val); Pos=-1; for(i=0;i<n;i++) { if(val== numlist[i]) { pos=I; break } If(pos!=-1) printf(“\n The element found at %d location”, pos); else printf(“\n Search Failed”); }

DELETION Deletion is the operation that removes an element from a given location of the list. To delete an element from the ith location of the list, then all elements from the right of i+ 1th location have to be shifted one step towards left to preserve contiguous locations in the array.

#include int main() { int array[100], position, i, n; printf("Enter number of elements in array\n"); scanf("%d", &n); printf("Enter %d elements\n", n); for ( i = 0 ; i< n ; i++ ) scanf("%d", &array[i]); printf("Enter the location where you wish to delete element\n"); scanf("%d", &position); if ( position >= n+1 ) printf("Deletion not possible.\n"); else { for ( i= position - 1 ; i < n - 1 ; i++ ) Array[i] = array[i+1]; printf("Resultant array is\n"); for( i = 0 ; i < n - 1 ; i++ ) printf("%d\n", array[i]); } return 0; }

INSERTION Insertion is the operation that inserts an element at a given location of the list. To insert an element at i th location of the list, then all elements from the right of i+ 1 th location have to be shifted one step towards right.

#include int main() { int array[100], position, i, n, value; printf("Enter number of elements in array\n"); scanf("%d", &n); printf("Enter %d elements\n", n); for (i = 0; i < n; i++) scanf("%d", &array[i]); printf("Enter the location where you wish to insert an element\n"); scanf("%d", &position); printf("Enter the value to insert\n"); scanf("%d", &value); for (i = n - 1; i >= position - 1; i--) Array[i+1] = array[i]; array[position-1] = value; printf("Resultant array is\n"); for (i = 0; i <= n; i++) printf("%d\n", array[i]); return 0; }

SORTING