PRESENTATION ON SEARCHING www.ustudy.in. SEARCHING Searching is the method to find element from the list of the elements. If element is found then it.

Slides:



Advertisements
Similar presentations
Algorithm & Flow Charts Decision Making and Looping Presented By Manesh T Course:1090 CS.
Advertisements

ICS103: Programming in C Searching, Sorting, 2D Arrays
Ver. 1.0 Session 5 Data Structures and Algorithms Objectives In this session, you will learn to: Sort data by using quick sort Sort data by using merge.
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
 2003 Prentice Hall, Inc. All rights reserved. 1 Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
 2003 Prentice Hall, Inc. All rights reserved Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
Searching Arrays Linear search Binary search small arrays
UNIT-4. Searching Methods:  Linear Search  Binary Search Sorting Techniques:  Bubble Sort  Selection Sort  Insertion Sort  Quick Sort  Merge Sort.
Chapter 8 ARRAYS Continued
C o n f i d e n t i a l Developed By Nitendra HOME NEXT Subject Name: Data Structure Using C Unit Title: Searching Methods.
1 Searching. 2 Searching Searching refers to the operation of finding an item from a list of items based on some key value. Two Searching Methods (1)
Lecture 12. Searching Algorithms and its analysis 1.
Data Structures & Algorithms CHAPTER 4 Searching Ms. Manal Al-Asmari.
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.
1 Lecture 5: Part 1 Searching Arrays Searching Arrays: Linear Search and Binary Search Search array for a key value Linear search  Compare each.
SEARCHING (Linear/Binary). Searching Algorithms  method of locating a specific item of information in a larger collection of data.  two popular search.
Chapter 2 ARRAYS.
Arrays.
1 2. Program Construction in Java. 2.8 Searching.
Lecture 4 on Data Structure Array. Prepared by, Jesmin Akhter, Lecturer, IIT, JU Searching : Linear search Searching refers to the operation of finding.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
DATA STRUCTURE & ALGORITHMS (BCS 1223) CHAPTER 8 : SEARCHING.
1 Data Structures Searching Techniques Namiq Sultan.
Data Strcutures.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
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. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
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.
SEARCHING.  This is a technique for searching a particular element in sequential manner until the desired element is found.  If an element is found.
L. Grewe.  An array ◦ stores several elements of the same type ◦ can be thought of as a list of elements: int a[8]
CSCI 130 Array Searching. Methods of searching arrays Linear –sequential - one at the time –set does not have to be ordered Binary –continuously cutting.
CSC 211 Data Structures Lecture 13
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
Searching CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
Searching Algorithms Sequential Search – inspects every items in a sequential manner. Example, in an array, all values in the array are checked from index.
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.
IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.
ICS103: Programming in C Searching, Sorting, 2D Arrays Muhamed F. Mudawar.
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Searching When we maintain a collection of data,
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.
Rray Programs. Insert and element in the given position of the Array rray.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
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.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
1. Traversing a linear array Here A is a linear array with lower bound LB and upper bound UB. This algorithm traverses A applying an operation PROCESS.
Arrays Department of Computer Science. C provides a derived data type known as ARRAYS that is used when large amounts of data has to be processed. “ an.
Sorting and Searching Bubble Sort Linear Search Binary Search.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
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.
MAHENDRAN. Session Objectives Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional.
Arrays (Operations on Arrays)
Searching CSCE 121 J. Michael Moore.
Linear and Binary Search
Introduction to Search Algorithms
Visit for more Learning Resources
CSC215 Lecture Algorithms.
Searching: linear & binary
Linear Search Binary Search Tree
ICS103: Programming in C Searching, Sorting, 2D Arrays
Presentation transcript:

PRESENTATION ON SEARCHING

SEARCHING Searching is the method to find element from the list of the elements. If element is found then it will display the location of the elements else it will print element is not found. Searching has two types. These are as follows:- – Binary search – Linear search

BINARY SEARCH It works only on the sorted list. It finds the mid value with the help of formula that is :- (lb+ub)\2 if mid value matched with the element which we want to find then searching is completed else if element is greater then mid then (lb=mid+1) if less then (ub=mid-1) then it take another mid to find the element this process is continued till then element is not found.

EXAMPLE [0][1][2][3][4][5][6][7][8][9] Suppose we want to find 80 then we have to take mid and mid =4 80 is not matched with the mid take another mid that is (5+9)/2=7 Then 80 is found on 7 th position

ALGORITHM Binary(data,lb,ub,item,loc) Here data is a sorted array with lower bound lb and uper bound ub, and item is a given item of information. The variables beg, end and mid denote. Respectiveily, the beginning, end and middle location of a segment of elements of data this algorithm finds the location loc of item in data or sets loc=null

ALGORITHM CONTD… 1.[INTIALIZE SEGMENT VERIABLES] SET BEG:=LB,END:=UB AND MID:=INT((BEG+END)/2). 2.REPEAT STEP 3AND4 WHILE BEG<=END AND DATA[MID]!=ITEM. 3.IF ITEM<DATA[MID],THEN: SET END:=MID-1 ELSE: SET BEG:=MID+1 [END OF IF STRUCTURE] 4.SET MID:=INT((BEG+END)/2) [END OF STEP 2LOOP] 5.IF DATA[MID]=ITEM,THEN: SET LOC:=MID ELSE: SET LOC:=NULL [END OF IF STRUCTURE] 6.EXIT.

#include void bin(int[],int,int,int); int mid; void main() { int a[5],i,item; clrscr(); printf("enter any five no"); for(i=0;i<5;i++) { scanf("%d",&a[i]); } printf("enter item which u want to search"); scanf("%d",&item); bin(a,0,4,item); getch(); } PROGRAM

void bin(int a[],int lb,int ub,int item) { mid=(lb+ub)/2; if(a[mid]==item) { printf("element is found at %d",mid+1 ); return; } else { if(a[mid]<item) { lb=mid+1; } else { ub=mid-1; } CONT..,

if(lb>ub) { printf("element is not found"); return; } bin(a,lb,ub,item); } CONT..,

LINEAR SEARCH linear search or sequential search is a method for finding a particular value in a list, that consists of checking every one of its elements, one at a time and in sequence, until the desired one is found. Linear search is the simplest search algorithm; it is a special case of brute-force search. Its worst case cost is proportional to the number of elements in the list; and so is its expected cost, if all list elements are equally likely to be searched for. Therefore, if the list has more than a few elements, other methods (such as binary search or hashing) will be faster, but they also impose additional requirements.

ALGORITHM LINEAR_SEARCH(ARR, N, FIND) Where ARR is an array of N elements in which the element FIND is to be searched. STEP 1: Repeat For I=0,1,2,…..,N-1 STEP 2: If (ARR[I]=FIND) Then RETURN I [End of If structure] STEP 3: [End of STEP 1 For loop] STEP 4: RETURN-1 END LINEAR_SEARCH()

PROGRAM void main() { int a[10],i,n,m,c=0; clrscr(); printf("Enter the size of an array"); scanf("%d",&n); printf("\nEnter the elements of the array"); for(i=0;i<=n-1;i++){ scanf("%d",&a[i]); } printf("\nThe elements of an array are"); for(i=0;i<=n-1;i++) { printf(" %d",a[i]); } printf("\nEnter the number to be search"); scanf("%d",&m);

CONT.., for(i=0;i<=n-1;i++) { if(a[i]==m) { c=1; break; } if(c==0) printf("\nThe number is not in the list"); else printf("\nThe number is found"); getch(); }

THANK YOU