# QR/ACA 6.

0-03

Toc H Institute of Science & Technology
Arakkunnam - 682 313.

FORMAT FOR CLASS ROOM TEACHING (FCT)

(Based on Bloom’s Taxonomy)
Code: IT 405 Name of faculty: Time: 1 Hrs

Subject Title : Data Structures & Algorithms Dept : I.T. Topic General Objectives Module : I : :

Semester: IV Ajeesh G Krishnan

Array Operations – Binary Search Understand the methods for searching the elements in an array Array, Working of looping statements.

Prerequisite Knowledge :

Specific Objectives : After this discourse, the students will have the following cognitive inputs

1. Understand the concepts of binary search.

2. Prepare an algorithm for binary search 3. Find out the difference between binary search and linear search
Key words introduced during the lecture:

 
Key points:

Binary search. Divide and conquer algorithm Median element.

 Binary search algorithm (or binary chop) is a technique for finding a particular value in a sorted list.  It makes progressively better guesses, by examining the value of the list member exactly halfway between what it determined to be an element too low in the list and one too high in the list.  A binary search finds the median element in a list, compares its value to the one you are searching for, and determines if it’s greater than, less than, or equal to the one you want  A guess that turns out to be too high becomes the new top of the list, and one too low the new bottom of the list.  The binary search's next guess is halfway between the new list's top and bottom  Repeating this strategy iteratively, it very quickly reduce the list, narrows the search, and finds the value.

After the second decision you've eliminated 3n/4 of them. which however can only be used to search a Sorted array. you eliminate half of the data with each decision. . then after the first decision you eliminate n/2 of them. So after k key comparisons the file remaining to be examined is of size at most n/2k.0-03  A binary search is an example of a divide and conquer algorithm (decrease and conquer algorithm) Prepare an algorithm for binary search: In this method the search begins by examining the record in the middle of the file rather than the one at one of the ends as in sequential search.  If K=Km then the middle record is the one being searched for  If K>Km then if the record being searched for is in the file.  Binary search is much faster than linear search for most data sets. Km one can draw one of the following conclusions:  If K<Km then if the record being searched for is in the file. binary search would be much better than linear search. Now repeat the process on the half you retained. Summary:  Binary search is a much better algorithm. we can determine whether our target is in the first half or the second half. and thus we can throw away half the array. Let us assume that the file being searched is ordered by non decreasing values of the key. Compare binary search with linear search  Binary search begins by examining the record in the middle of the file rather than the one at one of the ends as in sequential search. it must be in the higher numbered half of the file. By comparing the target to the item at the midpoint.  For a large data set. Then based on the results of comparison with the middle key. it must be in the lower numbered half of the file. Etc. After the third decision you've eliminated 7n/8 of them.  With binary search. And so on. It begins by breaking the sorted array into two half arrays. If there are n items. After each search either the search terminates successfully or the size of the file remaining to be searched is about one half of the original size.QR/ACA 6.

0-03  Binary search algorithm is the foundation of all database programs.  Is the number greater than 12? (No)  Is the number greater than 10? (Yes)  Is the number greater than 11? (No) Therefore. At each step. once we know the number is greater than 8. For example. 12] (in this case 10 is optimal).  Is the number greater than 8? (Yes). using only questions answered with yes or no. Stimulating Questions: • Find the best and worst cases of finding a match in the binary searching algorithms? New Ideas or Concepts: . the number must be 11. we choose a number right in the middle of the range of possible values for the number. but less than or equal to 12. we know to choose a number in the middle of the range [9.QR/ACA 6. the game might proceed as follows. Key Diagrams: Key: 10 0 2 1 4 2 8=10 ? 3 10 10 10=10? (Match Found) 4 12 12=10? 5 13 13 Analogies: An analogy of binary search in action is a simple guessing game in which a player has to guess a positive integer. between 1 and N. Supposing N is 16 and the number 11 is selected. selected by another player.

QR/ACA 6.0-03 .