SlideShare a Scribd company logo
1 of 19
PRESENTED BY :
JUBAYER HASAN & ELEAS KANCHON
DEPT. OF COMPUTER SCIENCE & ENGINEERING
RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY
A presentation on the comparison on
complexity between linear search and
binary search
What will be discussed?
 Necessity of different types searching techniques.
 Types of searching algorithm.
 Analysis of linear search algorithm.
 Analysis of binary search algorithm.
 Comparison between two algorithms.
Comparison between linear search and binary search
2
20-Jan-17
Why different searching techniques???
 To reduce time consumed by the algorithms.
 To minimize space taken by the algorithm to process data.
 To work with greater amount of data.
Comparison between linear search and binary search
3
20-Jan-17
Types of searching techniques
 Linear search : Search linearly through the data set.
 Binary search : Search using divide and conquer technique.
Comparison between linear search and binary search
4
20-Jan-17
Linear search
*Searches data linearly from a
data set. Starting from the
beginning it traverses the whole
data set until it finds the desired
data. If found the algorithm
returns the index.
*If data is absent then it returns
an invalid result as index.
*Easy to understand and
implement.
*Not good for large amount of
data.
Comparison between linear search and binary search
5
20-Jan-17
Complexity analysis of linear search
 In this algorithm, we search our desired data from the beginning of the dataset.
 So the worst case can happen when the desired data lies at the end of the
dataset.
 Hence the complexity is O(n).
Comparison between linear search and binary search
6
20-Jan-17
Binary search
 Search using divide and conquer technique.
 Works only on sorted array or linked list.
 Takes a mid value to compare if the mid value is less than or greater than the
item to be searched.
 Continuously changes searching area based on the value of mid.
 Works until the value is found or the limit of lower bound becomes greater than
the value of upper bound.
Comparison between linear search and binary search
7
20-Jan-17
The algorithm of binary search
BINARYSEARCH(LEFT,RIGHT,DATA, VALUE)[Here DATA is an array with N elements.]
1. IF LEFT>RIGHT THEN :
RETURN -1.
2. MID:=(LEFT+RIGHT)>>2.//FINDING MID USING SHIFT OPERATION.
3. IF DATA[MID]:=VALUE THEN:
RETURN MID.
4. IF DATA[MID]<VALUE THEN:
RETURN BINARYSEARCH(MID+1,RIGHT,DATA,VALUE).
5. IF DATA[MID]<VALUE THEN:
RETURN BINARYSEARCH(LEFT,MID-1,DATA,VALUE).
Comparison between linear search and binary search
8
20-Jan-17
The algorithm
*Lets take an array containing 10
data elements such as :
10,14,19,26,27,31,35,42,44.
Comparison between linear search and binary search
9
20-Jan-17
The algorithm
*Lets take an array containing 10
data elements such as :
10,14,19,26,27,31,35,42,44.
*The value to be searched is 35.
Comparison between linear search and binary search
10
20-Jan-17
The algorithm
*Lets take an array containing 10
data elements such as :
10,14,19,26,27,31,35,42,44.
*The value to be searched is 35.
*Starting with lower bound at
index 0 and upper at index 9,we
can get the mid value at the
index of (0+9)/2=4.
Comparison between linear search and binary search
11
20-Jan-17
The algorithm
(contd.)
*The desired value 35 is greater
than the mid value we got after
getting mid at 4th position.
Comparison between linear search and binary search
12
20-Jan-17
The algorithm
(contd.)
*The desired value 35 is greater
than the mid value we got after
getting mid at 4th position.
*So we shifted the left index to
5th position and calculated mid
position again.
*We got the mid position now
on (5+9)/2=7th position.
Comparison between linear search and binary search
13
20-Jan-17
The algorithm
(contd.)
*The desired value 35 is greater
than the mid value we got after
getting mid at 4th position.
*So we shifted the left index to
5th position and calculated mid
position again.
*We got the mid position now
on (5+9)/2=7th position.
*So we got our desired value
after running the algorithm just
for 2 times.
Comparison between linear search and binary search
14
20-Jan-17
Complexity analysis of binary search
 We can observe that every time the algorithm runs the searching area is getting
divided into two parts. That means if we have 8 elements, after 1st operation we
will have 8/2=4 elements, after 2nd operation we will have 4/2=2 elements and
so on.
 The process will continue until we get our desired element.
 If we need ‘m’ number of comparisons to get this point we can say that:
n/(2m)=1. That means m=log2n.
Comparison between linear search and binary search
15
20-Jan-17
How it works
Comparison between linear search and binary search
16
20-Jan-17
Why binary search is better?
 Binary search reduces the searching complexity to O(log2n) for n elements. It is
a massive reduction in searching time if we compare the complexity with linear
search which has complexity of O(n).
 In case of large amount of data binary search is very much effective than linear
search. It reduces the iteration number.
 Though binary search only works on sorted dataset while in case of linear search
it is not mandatory, the less iteration number gives the binary search algorithm
more efficiency.
Comparison between linear search and binary search
17
20-Jan-17
A statistical overview (For 1000000 items)
Search Item Index No. of iteration for Linear
Search
No. of iteration for Binary
Search
1000 981 75
10000 9970 59
25000 24998 44
50000 49984 29
1000000 999964 15
Comparison between linear search and binary search
18
20-Jan-17
Any questions?
Thank you
Comparison between linear search and binary search
19
20-Jan-17

More Related Content

What's hot

Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm03446940736
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithmmaamir farooq
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear searchmontazur420
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notationMuthiah Abbhirami
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sortingsajinis3
 
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
 
Searching Techniques and Analysis
Searching Techniques and AnalysisSearching Techniques and Analysis
Searching Techniques and AnalysisAkashBorse2
 
spreadsheet program
spreadsheet programspreadsheet program
spreadsheet programsamina khan
 
Binary search python
Binary search pythonBinary search python
Binary search pythonMaryamAnwar10
 
K mer index of dna sequence based on hash
K mer index of dna sequence based on hashK mer index of dna sequence based on hash
K mer index of dna sequence based on hashijcsa
 

What's hot (20)

Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Link list
Link listLink list
Link list
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notation
 
Complexity
ComplexityComplexity
Complexity
 
Linked Lists
Linked ListsLinked Lists
Linked Lists
 
L7
L7L7
L7
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
 
Data structures 1
Data structures 1Data structures 1
Data structures 1
 
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...
 
Searching Techniques and Analysis
Searching Techniques and AnalysisSearching Techniques and Analysis
Searching Techniques and Analysis
 
spreadsheet program
spreadsheet programspreadsheet program
spreadsheet program
 
single linked list
single linked listsingle linked list
single linked list
 
Binary search python
Binary search pythonBinary search python
Binary search python
 
K mer index of dna sequence based on hash
K mer index of dna sequence based on hashK mer index of dna sequence based on hash
K mer index of dna sequence based on hash
 
Lu3520152020
Lu3520152020Lu3520152020
Lu3520152020
 
String Searching and Matching
String Searching and MatchingString Searching and Matching
String Searching and Matching
 

Similar to A presentation on the comparison on complexity between

Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searchingsajinis3
 
ODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCHODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCHIAEME Publication
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdfharamaya university
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET Journal
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptMuhammadTalhaAwan1
 
Algorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary SearchAlgorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary SearchAndiNurkholis1
 
A STUDY ON SIMILARITY MEASURE FUNCTIONS ON ENGINEERING MATERIALS SELECTION
A STUDY ON SIMILARITY MEASURE FUNCTIONS ON ENGINEERING MATERIALS SELECTION A STUDY ON SIMILARITY MEASURE FUNCTIONS ON ENGINEERING MATERIALS SELECTION
A STUDY ON SIMILARITY MEASURE FUNCTIONS ON ENGINEERING MATERIALS SELECTION cscpconf
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptxreddy19841
 
Interpolation search
Interpolation searchInterpolation search
Interpolation searchUsr11011
 
Searching and Sorting Unit II Part I.pptx
Searching and Sorting Unit II Part I.pptxSearching and Sorting Unit II Part I.pptx
Searching and Sorting Unit II Part I.pptxDr. Madhuri Jawale
 
Data Structures Design Notes.pdf
Data Structures Design Notes.pdfData Structures Design Notes.pdf
Data Structures Design Notes.pdfAmuthachenthiruK
 
A Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching AlgorithmsA Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching AlgorithmsIRJET Journal
 
Parallel KNN for Big Data using Adaptive Indexing
Parallel KNN for Big Data using Adaptive IndexingParallel KNN for Big Data using Adaptive Indexing
Parallel KNN for Big Data using Adaptive IndexingIRJET Journal
 
Top-K Dominating Queries on Incomplete Data with Priorities
Top-K Dominating Queries on Incomplete Data with PrioritiesTop-K Dominating Queries on Incomplete Data with Priorities
Top-K Dominating Queries on Incomplete Data with Prioritiesijtsrd
 

Similar to A presentation on the comparison on complexity between (20)

Chapter 11 ds
Chapter 11 dsChapter 11 ds
Chapter 11 ds
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
ODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCHODD EVEN BASED BINARY SEARCH
ODD EVEN BASED 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
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
searching
searchingsearching
searching
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
 
Analysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptxAnalysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).ppt
 
Binary search
Binary search Binary search
Binary search
 
Algorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary SearchAlgorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary Search
 
A STUDY ON SIMILARITY MEASURE FUNCTIONS ON ENGINEERING MATERIALS SELECTION
A STUDY ON SIMILARITY MEASURE FUNCTIONS ON ENGINEERING MATERIALS SELECTION A STUDY ON SIMILARITY MEASURE FUNCTIONS ON ENGINEERING MATERIALS SELECTION
A STUDY ON SIMILARITY MEASURE FUNCTIONS ON ENGINEERING MATERIALS SELECTION
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx
 
Interpolation search
Interpolation searchInterpolation search
Interpolation search
 
Ch05 Black Jack
Ch05  Black  JackCh05  Black  Jack
Ch05 Black Jack
 
Searching and Sorting Unit II Part I.pptx
Searching and Sorting Unit II Part I.pptxSearching and Sorting Unit II Part I.pptx
Searching and Sorting Unit II Part I.pptx
 
Data Structures Design Notes.pdf
Data Structures Design Notes.pdfData Structures Design Notes.pdf
Data Structures Design Notes.pdf
 
A Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching AlgorithmsA Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching Algorithms
 
Parallel KNN for Big Data using Adaptive Indexing
Parallel KNN for Big Data using Adaptive IndexingParallel KNN for Big Data using Adaptive Indexing
Parallel KNN for Big Data using Adaptive Indexing
 
Top-K Dominating Queries on Incomplete Data with Priorities
Top-K Dominating Queries on Incomplete Data with PrioritiesTop-K Dominating Queries on Incomplete Data with Priorities
Top-K Dominating Queries on Incomplete Data with Priorities
 

Recently uploaded

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...Call girls in Ahmedabad High profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 

Recently uploaded (20)

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 

A presentation on the comparison on complexity between

  • 1. PRESENTED BY : JUBAYER HASAN & ELEAS KANCHON DEPT. OF COMPUTER SCIENCE & ENGINEERING RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY A presentation on the comparison on complexity between linear search and binary search
  • 2. What will be discussed?  Necessity of different types searching techniques.  Types of searching algorithm.  Analysis of linear search algorithm.  Analysis of binary search algorithm.  Comparison between two algorithms. Comparison between linear search and binary search 2 20-Jan-17
  • 3. Why different searching techniques???  To reduce time consumed by the algorithms.  To minimize space taken by the algorithm to process data.  To work with greater amount of data. Comparison between linear search and binary search 3 20-Jan-17
  • 4. Types of searching techniques  Linear search : Search linearly through the data set.  Binary search : Search using divide and conquer technique. Comparison between linear search and binary search 4 20-Jan-17
  • 5. Linear search *Searches data linearly from a data set. Starting from the beginning it traverses the whole data set until it finds the desired data. If found the algorithm returns the index. *If data is absent then it returns an invalid result as index. *Easy to understand and implement. *Not good for large amount of data. Comparison between linear search and binary search 5 20-Jan-17
  • 6. Complexity analysis of linear search  In this algorithm, we search our desired data from the beginning of the dataset.  So the worst case can happen when the desired data lies at the end of the dataset.  Hence the complexity is O(n). Comparison between linear search and binary search 6 20-Jan-17
  • 7. Binary search  Search using divide and conquer technique.  Works only on sorted array or linked list.  Takes a mid value to compare if the mid value is less than or greater than the item to be searched.  Continuously changes searching area based on the value of mid.  Works until the value is found or the limit of lower bound becomes greater than the value of upper bound. Comparison between linear search and binary search 7 20-Jan-17
  • 8. The algorithm of binary search BINARYSEARCH(LEFT,RIGHT,DATA, VALUE)[Here DATA is an array with N elements.] 1. IF LEFT>RIGHT THEN : RETURN -1. 2. MID:=(LEFT+RIGHT)>>2.//FINDING MID USING SHIFT OPERATION. 3. IF DATA[MID]:=VALUE THEN: RETURN MID. 4. IF DATA[MID]<VALUE THEN: RETURN BINARYSEARCH(MID+1,RIGHT,DATA,VALUE). 5. IF DATA[MID]<VALUE THEN: RETURN BINARYSEARCH(LEFT,MID-1,DATA,VALUE). Comparison between linear search and binary search 8 20-Jan-17
  • 9. The algorithm *Lets take an array containing 10 data elements such as : 10,14,19,26,27,31,35,42,44. Comparison between linear search and binary search 9 20-Jan-17
  • 10. The algorithm *Lets take an array containing 10 data elements such as : 10,14,19,26,27,31,35,42,44. *The value to be searched is 35. Comparison between linear search and binary search 10 20-Jan-17
  • 11. The algorithm *Lets take an array containing 10 data elements such as : 10,14,19,26,27,31,35,42,44. *The value to be searched is 35. *Starting with lower bound at index 0 and upper at index 9,we can get the mid value at the index of (0+9)/2=4. Comparison between linear search and binary search 11 20-Jan-17
  • 12. The algorithm (contd.) *The desired value 35 is greater than the mid value we got after getting mid at 4th position. Comparison between linear search and binary search 12 20-Jan-17
  • 13. The algorithm (contd.) *The desired value 35 is greater than the mid value we got after getting mid at 4th position. *So we shifted the left index to 5th position and calculated mid position again. *We got the mid position now on (5+9)/2=7th position. Comparison between linear search and binary search 13 20-Jan-17
  • 14. The algorithm (contd.) *The desired value 35 is greater than the mid value we got after getting mid at 4th position. *So we shifted the left index to 5th position and calculated mid position again. *We got the mid position now on (5+9)/2=7th position. *So we got our desired value after running the algorithm just for 2 times. Comparison between linear search and binary search 14 20-Jan-17
  • 15. Complexity analysis of binary search  We can observe that every time the algorithm runs the searching area is getting divided into two parts. That means if we have 8 elements, after 1st operation we will have 8/2=4 elements, after 2nd operation we will have 4/2=2 elements and so on.  The process will continue until we get our desired element.  If we need ‘m’ number of comparisons to get this point we can say that: n/(2m)=1. That means m=log2n. Comparison between linear search and binary search 15 20-Jan-17
  • 16. How it works Comparison between linear search and binary search 16 20-Jan-17
  • 17. Why binary search is better?  Binary search reduces the searching complexity to O(log2n) for n elements. It is a massive reduction in searching time if we compare the complexity with linear search which has complexity of O(n).  In case of large amount of data binary search is very much effective than linear search. It reduces the iteration number.  Though binary search only works on sorted dataset while in case of linear search it is not mandatory, the less iteration number gives the binary search algorithm more efficiency. Comparison between linear search and binary search 17 20-Jan-17
  • 18. A statistical overview (For 1000000 items) Search Item Index No. of iteration for Linear Search No. of iteration for Binary Search 1000 981 75 10000 9970 59 25000 24998 44 50000 49984 29 1000000 999964 15 Comparison between linear search and binary search 18 20-Jan-17
  • 19. Any questions? Thank you Comparison between linear search and binary search 19 20-Jan-17