## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

By Junaid Ali Siddiqui

Searching

Computer systems are often used to store large amounts of data from which individual records are retrieved according to some searching criteria. The process of finding the location of a specific data item or record with a given key value or finding the locations of all records which satisfy one or more conditions in a list is called “Searching”. If the item exists in the given list then search is said to be successful otherwise if the element is not found in the given list then search is said to be unsuccessful. Searching a telephone number in a telephone directory is an example of searching.

**MAIN TYPES OF SEARCHING
**

Internal Search

The search in which the whole list resides in the main memory is called internal search.

External search

The search in which most of the list resides in the secondary memory is called external search.

SOME IMPORTANT POINTS

In Data structures when we use the word searching ,we actually refer to internal searching. The complexity of any searching method is determined from the number of comparisons performed among the elements of the list in order to find the element. The time required for a search operation depends on the complexity of the searching algorithm.

**Basically we have to consider three cases when we search for a particular element in the list.
**

Best case

The best case is that in which the element is found during the first comparison.

Worst case

The worst case is that in which the element is found only at the end i.e. in the last comparison.

Average case

The average case is that in which the element is found in comparisons more than best case but less than worst case.

**Types of searching algorithms
**

There are two types of searching algorithm which are listed below. Sequential search Binary search

Sequential Search

It is also called linear search. It is the simplest way for finding an element in a list. It searches the element sequentially in a list, no matter whether list is sorted or unsorted. In case of sorted list in ascending order, the search is started from 1st element and continued until the desired element is found or the element whose value is greater than the value being searched. In case of sorted list in descending order, the search is started from 1st element and continued until the desired element is found or the element whose value is smaller than the value being searched. If the list is unsorted searching started from 1st location and continued until the element is found or the end of the list is reached.

SOME DRAWBACKS

It is a very slow process. It is used only for small amount of data. It is a very time consuming method.

**Algorithm sequential search
**

This algorithm is used for linear searching. ITEM is to be searched in a linear array DATA having N elements. LOC is variable which store the location in case of successful search and in case of unsuccessful search LOC will contain 0.

**LINEAR SEARCH ALGORITHM
**

Step 1: [Insert ITEM at the end of DATA] SetDATA[N+1]:=ITEM Step 2:[Initialize counter] Set LOC:=1 Step 3:[Search for ITEM] Repeat while DATA[LOC] !=ITEM Set LOC:=LOC+1. [End of loop] Step 4:[Successful?] if LOC=N+1,then Set LOC:=0 Step 5:Exit [Finish].

**Complexity Of Linear search algorithm
**

Linear search provide complexity for finding an element in an array because linear search is a step-by-step process, in which specific element is compared with each element of array. In linear search complexity is due to two cases. It is possible that required element occurs at the end of the array. So linear search consumes more time. It is also possible that required element is not present in the given array, this is the worst case. In this case the algorithm requires f(n)=n+1 comparisons. If the element is at first position in array then only one comparison will be needed.

Suppose pk is the probability that ITEM appears in DATA[K] and suppose q is the probability that ITEM does not appear in DATA. (Then p1+p2+………+pn+q=1.) Since the algorithm uses k comparisons when ITEM appears in DATA[K], the average number of comparisons is given by f(n)=1xp1+2xp2+………+nxpn+(n+1)xq. In particular, suppose q is very small and ITEM appears with equal probability in each element of DATA. Then q is approximately equal to 0 and each pi =1/n. Accordingly, f(n)=1x1/n+2x1/n+……..+nx1/n+(n+1)x0=(1+2+…. +n)x1/n =n(n+1)/2x1/n=(n+1)/2 That is, in this special case, the average number of comparisons required to find the location of ITEM is approximately equal to half the number of elements in the array.

**Message from presenter:
**

“Try to hide bad qualities of others Allah will hide yours in the day of judgment....”

THANK YOU!

- Lecture 19 Part 2.pdf
- C Programming
- sprunt90aperiodic.pdf
- Apcs Notes 7
- Linear Binary Search Seminar
- SCE_EN_031-600 Global Data Blocks S7-1200_R1508
- Algorithms and Complexity I
- LS_conf
- amazon question paper.txt
- zio2011-qpaper
- Constructor Summary
- Arrays
- unit1.pdf
- COMPRO2 Syllabus
- CS198 Programming Assignment 2
- E-Notes_data Srucrure DMIETR
- Insert Update Ordering in a Mappings
- CADKEY Advanced Design Language (CADL) Guide
- datastage basic
- msQuestions
- Toughest Interview Questions
- ++Hardware Interview Question
- mem2
- Ni It c Programming Language
- Microsoft Interview Questions!
- JAVA Mock Test 2
- Chapter_3-1
- Adobe
- m340 Argument a Ire En
- computer components

- Compare "Urdhva Tiryakbhyam Multiplier" and "Hierarchical Array of Array Multiplier"
- UT Dallas Syllabus for cs1336.002 06s taught by Laurie Thompson (lthomp)
- Algorithms and Data Structure
- Algorithm And Programming Language MCQ'S
- Analysis & Design Algorithm MCQ'S
- UT Dallas Syllabus for cs1336.002 05s taught by Laurie Thompson (lthomp)
- UT Dallas Syllabus for cs1336.003 06s taught by Shyam Karrah (skarrah)
- UT Dallas Syllabus for cs1336.003 05s taught by George Steinhorst (csteinh)
- Cross Eye Jamming
- Parallel Networks v. Array Networks
- UT Dallas Syllabus for cs1336.001 05f taught by Laurie Thompson (lthomp)
- Nokia VP8 Infringement Claim Chart for '211 Patent
- UT Dallas Syllabus for cs1336.501.10f taught by Timothy Farage (tfarage)
- Implementation of Digital Beamforming Technique for Linear Antenna Arrays
- Data Structure
- tmp244D.tmp
- UT Dallas Syllabus for cs1336.002 05f taught by Laurie Thompson (lthomp)
- Data Structures and Algorithms MCQ'S
- UT Dallas Syllabus for cs1336.005.09f taught by Timothy Farage (tfarage)
- NIIT Sample Programming Placement Paper Level-1

- Neural Network
- Non Regular Languages 2
- Machine Learning
- Difference Between Oop & Strctr Prgmng
- Difference Bw Databas and Expert System
- MYCIN Expert System
- Prospector Expert System
- Symbol Table
- Puff Expert System
- kleen theorem
- Prospector Expert System
- Transition Graph
- Turing Machine
- Error Handler
- Error Handler
- Bubble sort
- Data Base Models
- Raid
- Inline Function
- FDDI
- Binary search
- index file Organization
- Pre Order Traversal
- Fundamental File Structure Concepts
- Graph Terminology
- Java 2
- Junaid (Quick Sort)
- Dendral Expert System
- Macsyma Expert System

Sign up to vote on this title

UsefulNot usefulClose Dialog## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

Close Dialog## This title now requires a credit

Use one of your book credits to continue reading from where you left off, or restart the preview.

Loading