SlideShare a Scribd company logo
1 of 13
Data Structure - 1
Now as most of you must be knowing a major drawback of
the linear search that it is extremely time consuming for large
data sets .
Consider for Example we have an array with only five numbers
[1,3,0,8,5] and we want to search the number 5 in the array.
Then the maximum time taken to search the array would be
basically five iterations.
However , consider a case where you have say 10,000
numbers in an array [i.e. numbers from 1 to 10000 in any
random fashion] and we want to search an element which is
the last number in the array.
Now as you can see here this is extremely time consuming as
it would take 10000 iterations to search the number.
This Is where we use binary search to speed up the operation
significantly.
The pre requirement for binary search is that the array should
be in a sorted order.
The following example will give you a better understanding of
the working of the binary search algorithm.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Suppose the user wants to find the number 7 in the array of 20 numbers
given below. To find 7, the number would be initially compared with middle
element of the array say 10.
Iteration no - 01
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Now as we see the array is sorted and the number 7 is less than 10 the array
after the number 10 is totally discarded thus reducing the array to be
searched by half.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Now similar process is done on the rest of the array. Now the array to be
searched is between the numbers 1 to 10. Again in a similar fashion the
middle element of the array is searched and compared with the number 7.
Again since 5 is the middle element it is not the number to be searched.
Iteration no - 02
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Now here as we see the number 7 is greater than 5 the array numbers 1 to 4
are discarded and the array to be searched is now from 5 to 10.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Again the same thing is done . The middle element of the array is found out
i.e. the middle element of the array between 5 to 10 which turns out to be 7
the number to be found out.
Iteration no - 03
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Thus using binary search we found out the number 7 from an array of 20
numbers in 3 iterations which would have taken 7 iterations using linear
search thus reducing the work by half.
Thus we see that binary search is a much more efficient
algorithm for searching in a large list then the linear search
algorithm.
The only drawback of the algorithm being the array on which
the search is being performed should be COMPULSORILY in
the sorted order.
Binary search
Binary search

More Related Content

What's hot

What's hot (20)

B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
Short Division: 4digit by 2digit (No Remainder)
Short Division: 4digit by 2digit (No Remainder)Short Division: 4digit by 2digit (No Remainder)
Short Division: 4digit by 2digit (No Remainder)
 
Lesson 1.10 square roots
Lesson 1.10   square rootsLesson 1.10   square roots
Lesson 1.10 square roots
 
Watermelon problem
Watermelon problemWatermelon problem
Watermelon problem
 
Day 2 irrational numbers
Day 2 irrational numbersDay 2 irrational numbers
Day 2 irrational numbers
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
b+ tree
b+ treeb+ tree
b+ tree
 
Tic Tac Toe Factoring
Tic Tac Toe FactoringTic Tac Toe Factoring
Tic Tac Toe Factoring
 
Lesson 4 square numbers
Lesson 4   square numbersLesson 4   square numbers
Lesson 4 square numbers
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
 
Short Division Of Decimals
Short Division Of DecimalsShort Division Of Decimals
Short Division Of Decimals
 
Squares cubes and roots edmodo 2013 14
Squares cubes and roots edmodo 2013 14Squares cubes and roots edmodo 2013 14
Squares cubes and roots edmodo 2013 14
 
Section 9 3
Section 9 3Section 9 3
Section 9 3
 
Section 2.7 square roots (algebra)
Section 2.7 square roots (algebra)Section 2.7 square roots (algebra)
Section 2.7 square roots (algebra)
 
B-Tree
B-TreeB-Tree
B-Tree
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
M14 T1
M14 T1M14 T1
M14 T1
 
B+tree Data structures presentation
B+tree Data structures presentationB+tree Data structures presentation
B+tree Data structures presentation
 
Power Laws
Power LawsPower Laws
Power Laws
 

Viewers also liked

Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithmNeoClassical
 
Data structure
Data structureData structure
Data structureM Ramya
 
Searching linear & binary search
Searching linear & binary searchSearching linear & binary search
Searching linear & binary searchnikunjandy
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...widespreadpromotion
 
Library Automation A - Z Guide: A Hands on Module
Library Automation A - Z Guide: A Hands on ModuleLibrary Automation A - Z Guide: A Hands on Module
Library Automation A - Z Guide: A Hands on ModuleAshok Kumar Satapathy
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data StructureTalha Shaikh
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary SearchReem Alattas
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sortingKaushal Shah
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingEduardo Bergavera
 
Quick sort and binary search PDF
Quick sort and binary search PDFQuick sort and binary search PDF
Quick sort and binary search PDFDivya modi
 

Viewers also liked (17)

Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Data structure
Data structureData structure
Data structure
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
 
Linear and binary search
Linear and binary searchLinear and binary search
Linear and binary search
 
Searching linear & binary search
Searching linear & binary searchSearching linear & binary search
Searching linear & binary search
 
Linear and Bianry search
Linear and Bianry searchLinear and Bianry search
Linear and Bianry search
 
Binary search
Binary searchBinary search
Binary search
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
 
Binary Search Algorithm
Binary Search Algorithm Binary Search Algorithm
Binary Search Algorithm
 
Library Automation A - Z Guide: A Hands on Module
Library Automation A - Z Guide: A Hands on ModuleLibrary Automation A - Z Guide: A Hands on Module
Library Automation A - Z Guide: A Hands on Module
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary Search
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 
Quick sort and binary search PDF
Quick sort and binary search PDFQuick sort and binary search PDF
Quick sort and binary search PDF
 

Similar to Binary search

PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search AlgorithmFazalRehman79
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdfharamaya university
 
addition of integers.ppt
addition of integers.pptaddition of integers.ppt
addition of integers.pptGianaIbaez
 
From Square Numbers to Square Roots (Lesson 2)
From Square Numbers to Square Roots (Lesson 2) From Square Numbers to Square Roots (Lesson 2)
From Square Numbers to Square Roots (Lesson 2) jacob_lingley
 
Introduction to Prime Numbers
Introduction to Prime NumbersIntroduction to Prime Numbers
Introduction to Prime NumbersLuke Dunn
 
Math journal chapters 1 3
Math journal chapters 1 3Math journal chapters 1 3
Math journal chapters 1 3Ernie777
 
Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptxAlgorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptxAftabali702240
 
Interpolation search
Interpolation searchInterpolation search
Interpolation searchUsr11011
 
1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).pptKanchanRaut13
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithmsZaid Hameed
 
Convert Numbers to Words with Visual Basic.NET
Convert Numbers to Words with Visual Basic.NETConvert Numbers to Words with Visual Basic.NET
Convert Numbers to Words with Visual Basic.NETDaniel DotNet
 
Optimal Implementation of Watched Literals and More General Techniques
Optimal Implementation of  Watched Literals and More General TechniquesOptimal Implementation of  Watched Literals and More General Techniques
Optimal Implementation of Watched Literals and More General Techniquesturingfan
 
Absolute Value and the Fundamental Operations on Integers.pptx
Absolute Value and the Fundamental Operations on Integers.pptxAbsolute Value and the Fundamental Operations on Integers.pptx
Absolute Value and the Fundamental Operations on Integers.pptxHazelCola1
 
Section 3.3 the real number system (math)
Section 3.3 the real number system (math)Section 3.3 the real number system (math)
Section 3.3 the real number system (math)Algebra / Mathematics
 
computer notes - Binary search tree
computer notes - Binary search treecomputer notes - Binary search tree
computer notes - Binary search treeecomputernotes
 

Similar to Binary search (20)

PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
addition of integers.ppt
addition of integers.pptaddition of integers.ppt
addition of integers.ppt
 
From Square Numbers to Square Roots (Lesson 2)
From Square Numbers to Square Roots (Lesson 2) From Square Numbers to Square Roots (Lesson 2)
From Square Numbers to Square Roots (Lesson 2)
 
Introduction to Prime Numbers
Introduction to Prime NumbersIntroduction to Prime Numbers
Introduction to Prime Numbers
 
Math journal chapters 1 3
Math journal chapters 1 3Math journal chapters 1 3
Math journal chapters 1 3
 
Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptxAlgorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptx
 
Interpolation search
Interpolation searchInterpolation search
Interpolation search
 
1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Convert Numbers to Words with Visual Basic.NET
Convert Numbers to Words with Visual Basic.NETConvert Numbers to Words with Visual Basic.NET
Convert Numbers to Words with Visual Basic.NET
 
Optimal Implementation of Watched Literals and More General Techniques
Optimal Implementation of  Watched Literals and More General TechniquesOptimal Implementation of  Watched Literals and More General Techniques
Optimal Implementation of Watched Literals and More General Techniques
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and Algorithms
 
Sorting
SortingSorting
Sorting
 
Algorithm and Programming (Searching)
Algorithm and Programming (Searching)Algorithm and Programming (Searching)
Algorithm and Programming (Searching)
 
Sortsearch
SortsearchSortsearch
Sortsearch
 
Absolute Value and the Fundamental Operations on Integers.pptx
Absolute Value and the Fundamental Operations on Integers.pptxAbsolute Value and the Fundamental Operations on Integers.pptx
Absolute Value and the Fundamental Operations on Integers.pptx
 
Section 3.3 the real number system (math)
Section 3.3 the real number system (math)Section 3.3 the real number system (math)
Section 3.3 the real number system (math)
 
computer notes - Binary search tree
computer notes - Binary search treecomputer notes - Binary search tree
computer notes - Binary search tree
 

Recently uploaded

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 

Binary search

  • 2. Now as most of you must be knowing a major drawback of the linear search that it is extremely time consuming for large data sets . Consider for Example we have an array with only five numbers [1,3,0,8,5] and we want to search the number 5 in the array. Then the maximum time taken to search the array would be basically five iterations.
  • 3. However , consider a case where you have say 10,000 numbers in an array [i.e. numbers from 1 to 10000 in any random fashion] and we want to search an element which is the last number in the array. Now as you can see here this is extremely time consuming as it would take 10000 iterations to search the number. This Is where we use binary search to speed up the operation significantly.
  • 4. The pre requirement for binary search is that the array should be in a sorted order. The following example will give you a better understanding of the working of the binary search algorithm.
  • 5. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Suppose the user wants to find the number 7 in the array of 20 numbers given below. To find 7, the number would be initially compared with middle element of the array say 10. Iteration no - 01
  • 6. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Now as we see the array is sorted and the number 7 is less than 10 the array after the number 10 is totally discarded thus reducing the array to be searched by half.
  • 7. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Now similar process is done on the rest of the array. Now the array to be searched is between the numbers 1 to 10. Again in a similar fashion the middle element of the array is searched and compared with the number 7. Again since 5 is the middle element it is not the number to be searched. Iteration no - 02
  • 8. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Now here as we see the number 7 is greater than 5 the array numbers 1 to 4 are discarded and the array to be searched is now from 5 to 10.
  • 9. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Again the same thing is done . The middle element of the array is found out i.e. the middle element of the array between 5 to 10 which turns out to be 7 the number to be found out. Iteration no - 03
  • 10. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Thus using binary search we found out the number 7 from an array of 20 numbers in 3 iterations which would have taken 7 iterations using linear search thus reducing the work by half.
  • 11. Thus we see that binary search is a much more efficient algorithm for searching in a large list then the linear search algorithm. The only drawback of the algorithm being the array on which the search is being performed should be COMPULSORILY in the sorted order.