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

Searching Techniques

Searching refers to the operation of finding the location of a given item in a collection of data. The search is said to be successful if the item appears in the data and unsuccessful otherwise. The algorithm chosen for searching depends on the way information is organized. The two simple searching algorithm s are:

± Linear Search ± Binary Search

Linear search

In computer science, linear search is a search algorithm, also known as sequential search, that is suitable for searching a list of data for a particular value. It operates by checking every element of a list one at a time in sequence until a match is found.

**Linear Search Algorithm
**

DATA is the linear array with N elements and ITEM is a given item of information. This algorithm finds the location LOC of ITEM, or sets LOC=0 if the search is unsuccessful. 1. [Initialize counter] Set K=1 and LOC = 0 2. Repeat steps 3 while K< N and DATA[K] != ITEM 3. [Increment counter]Set K=K+1 4. [End of step 2 loop] 5. [Successful] 6. If LOC = 0 then:

Write: ITEM is not in the array DATA Else: Write: LOC is the location of ITEM

7. 8.

[End of If structure] Exit.

**Complexity/Efficiency of Linear Search
**

The complexity of search algorithms is measured by the number f(n) of comparisons required to find item in data consisting of n elements. The algorithm is called linear search because its complexity/efficiency can be expressed as a linear function: the number of comparisons to find a target increases linearly as the size of the data.

**Complexity/Efficiency of Linear Search
**

For search algorithms, the main steps are the comparisons of items with the target value. Counting these for data models representing the best case, the worst case, and the average case produces the following table. For each case, the number of steps is expressed in terms of n, the number of items in the data.

Model Best Case (fewest comparisons) Worst Case (most comparisons) Average Case (average number of comparisons) Number of Comparisons (for n = 100000) 1 (target is first item) 100000 (target is last item) 50000 (target is middle item) Comparisons as a function of n 1 n

n/2

Binary Search

A binary search, also called a dichotomizing search, is a more efficient algorithm if the data is sorted, in increasing order. The strategy of binary search is to check the middle (approximately) item in the list. If it is not the target and the target is smaller than the middle item, the target must be in the first half of the list. If the target is larger than the middle item, the target must be in the last half of the list. Thus, one unsuccessful comparison reduces the number of items left to check by half! The search continues by checking the middle item in the remaining half of the list. If it's not the target, the search narrows to the half of the remaining part of the list that the target could be in. The splitting process continues until the target is located or the remaining list consists of only one item. If that item is not the target, then it's not in the list.

**Binary Search Algorithm
**

DATA is the sorted array with lower bound LB and upper bound UB and ITEM is a given item of information. This algorithm finds the location LOC of ITEM, or sets LOC=0 if the search is unsuccessful. The variables BEG,END and MID denotes respectively the beginning, end and middle location. [Initialize variables] Set BEG=LB, END=UB and MID = INT((BEG+END)/2) Repeat steps 3 and 4 while BEG< END and DATA[MID] != ITEM If ITEM < DATA[MID], then: Set END=MID-1 Else: Set BEG=MID+1 [End of If structure] Set MID=INT((BEG+END)/2 [End of step 2 loop] If DATA[MID]=ITEM, then Set LOC=MID Else: Set LOC=NULL [End of If structure] Exit. 1. 2. 3.

4. 5.

6.

**Complexity/Efficiency of Binary Search
**

To evaluate binary search, the number of comparisons in the best case and worst case are compared. The best case occurs if the middle item happens to be the target. Then only one comparison is needed to find it. As before, the best case analysis does not reveal much. If the target is not in the array then the process of dividing the list in half continues until there is only one item left to check.

**Complexity/Efficiency of Binary Search
**

The pattern of the number of comparisons after each division are showed in the following Items Left to Comparisons So table: Search Far 1024 0 Binary search efficiency 512 1 for the worst case is a 256 2 128 3 logarithmic function of 64 4 data size. 32 5 16 6 C = log2n. 8 7

4 2 1 8 9 10

**Complexity/Efficiency of Binary Search
**

The following table summarizes the analysis for binary search.

Model Number of Comparisons (for n = 100000) Comparisons as a function of n

Best Case (fewest comparisons) Worst Case (most comparisons)

1 (target is middle item) 16 (target not in array)

1

log2n

Efficiency Comparison

The following table shows how the maximum number of comparisons increases for binary search and linear search.

Worst Case Comparisons Array Size Linear Search 100,000 200,000 400,000 800,000 1,600,000 100,000 200,000 400,000 800,000 1,600,000 Binary Search 16 17 18 19 20

- TASPW1 Installation Log
- Assignment#4
- HHS_en01_Being_a_Hacker
- 1 - Intro to SW Engg.
- Readme
- class exercise session 1,2
- Software Testing
- Software Quality Assurance
- Project Planning
- Project Management
- Lec 6-String Processing
- Lec 5-Stacks and Queues
- Lec 4-Sorting Techniques
- Lec 2-Arrays and String Processing
- Lec1-Introduction to Data Structure and Algorithms
- Muslim 3
- Srs Template
- Softcell Example Srs
- Req. Engg. Spec. Analysis. Model.
- Introduction to UML
- Happy Holiday Homes
- 2 - Software Process and Life Cycles
- 1 - Intro to SW Engg.
- Uml Sequence Diagrams

- Invoice Tolerance Limits an Insight Part 1
- Publishing Search Logs – A Comparative Study
- M.Phil Computer Science Machine Language and Pattern Analysis Projects
- Noise Removal Efficient Web Data Mining
- Multi Strategy
- Binary Search Doc
- Article
- proposed-approach-for-web-page-access-prediction-using-populartiy-and-similarity-based-page-rank-algorithm
- ch5
- MAT135,EXCEL,ProjectHandout,Scatterplot
- UnsupervisedDM Workshop
- SPSS 19 Manual
- Privacy Preserving Association Rule Mining Distributed Genetic Alg for Ppdm
- 5.Environment Variables
- Data Cleaning and Data Pre Processing
- 06449328
- Time Serious and Sequential
- Satellite m500
- Intersection Point of Two Lines in 3D
- AEEE-2006-5-3-35-ivaniga
- A Review Paper on Video Compression Using Motion Compensation and SPIHT
- 1530 6 Probability Distributions
- IJETTCS-2012-12-22-052
- Assignment on Data Mining
- Invoice Verification_Tolerance Limits
- Program Description
- A Template for Scatter Search and Path Relinking
- 2347973
- Social Networks and Marketing
- 00268976%2E2013%2E813594
- Lec 3-Searching Techniques

Are you sure?

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

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd