SlideShare a Scribd company logo
OBJECT- ORIENTED PROGRAMING
Name: Zohaib Arif
Roll no.: 6823
Semester: 2nd
Department of Information & Technology
SEARCHING IN ARRAY
Searching in array
 Sequential search
 Binary search
CONTENTS:
• Introduction
• Sequential search
• Binary search
• Compression
• Efficiency
• Conclusion
INTRODUCTION:
• Array
• Search
• Search in array
i. Sequential search
ii. Binary search
SEQUENTIAL SEARCH:
Algorithm involves checking all the element of array(or any structure) one
by one and in sequence until the desired result is found.
This algorithm follows the following steps to
search a value in array.
• Visit the first element of the array and
compare its value with required value.
• If the value of array matches with the desired
value, the search is complete.
• If the value of array doesn`t match, move to
next element and repeat same process.
Algorithm:
for(i=0; i<n; i++)
if(arr[i]==n)
return (i);
else
return (-1);
BINARY SEARCH:
The binary search algorithm begins by
comparing the target value to value of the
middle element of the sorted array and
then move upper or lower half. This
process repeated until the required
number is not found.
This algorithm follows the following steps to search a
value in array.
• It locates the middle element of array and compares
with the search number.
• If they are equal, search is successful and the index
of middle element is returned.
• If they are not equal, it reduces the search to half of
the array.
• If the search number is less than the middle
element, it searches the first half of array.
Otherwise it searches the second half of the array.
Algorithm:
low =0;
hi=n-1;
while(low<=hi)2
{ mid =(low +hi)
if (arr[mid]==n)
return(mid);
if(n<arr[mid])
hi=mid-1;
else
low=mid-1; }
return(-1);
Linear search
• Sorted array is not necessary.
• It is not quicker method.
• Average speed of linear search is
very slow then binary search.
• Programing code make short when
linear search is use.
Binary search
• Sorted array is necessary.
• It is quicker method.
• Average speed of binary search is
very fast then linear search.
• Programing code make big when
linear search is use.
COMPARISON:
EFFICIENCY:
Both search has its won benefit but each comparison in binary reduces the number of
possible candidates by a factor of 2. thus maximum number of key comparison is
approximately long with bases 2.
CONCLUSION:
• Searching is an important function in computer science. When data set become
larger and larger good search algorithms will become more important. Linear
search is not more efficient then binary search because we want our work do
rapidly and average comparison of linear search make more efficient then binary
search.
Presentation

More Related Content

PPT
Linear search in ds
PPTX
Rahat &amp; juhith
PDF
Search Algprithms
DOCX
MODULE 5-Searching and-sorting
PPTX
Searching linear &amp; binary search
PDF
Algorithms Lecture 6: Searching Algorithms
PDF
Object oriented programming15 control structures relational operators
Linear search in ds
Rahat &amp; juhith
Search Algprithms
MODULE 5-Searching and-sorting
Searching linear &amp; binary search
Algorithms Lecture 6: Searching Algorithms
Object oriented programming15 control structures relational operators

What's hot (20)

PPTX
Analysis of algorithm
PDF
Algorithms Lecture 8: Pattern Algorithms
PPTX
My presentation
PPT
SEARCHING AND SORTING ALGORITHMS
PPTX
Binary search
PDF
Exploiting the query structure for efficient join ordering in SPARQL queries
PPTX
Quick Sort
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
PDF
Sorting Algorithms
PPTX
Merge sort
PPTX
Sorting
PPTX
Searching techniques
PPTX
Test 3 exam review guide
PPTX
Sorting algorithms
PPTX
Array ADT(Abstract Data Type)|Data Structure
PPT
Priority Queue
PPT
Chapter 14 quick_sort
PDF
Algorithms Lecture 4: Sorting Algorithms I
PPTX
K neareast neighbor algorithm presentation
Analysis of algorithm
Algorithms Lecture 8: Pattern Algorithms
My presentation
SEARCHING AND SORTING ALGORITHMS
Binary search
Exploiting the query structure for efficient join ordering in SPARQL queries
Quick Sort
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sorting Algorithms
Merge sort
Sorting
Searching techniques
Test 3 exam review guide
Sorting algorithms
Array ADT(Abstract Data Type)|Data Structure
Priority Queue
Chapter 14 quick_sort
Algorithms Lecture 4: Sorting Algorithms I
K neareast neighbor algorithm presentation
Ad

Similar to Presentation (20)

PPTX
Lecture_Oct26.pptx
PPTX
Algorithm 8th lecture linear & binary search(2).pptx
PDF
BINARY SEARCH - A - DATA STRUCTURE AND ALGORITHM.pdf
PDF
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
ODP
Data operatons & searching and sorting algorithms
PPTX
unit II_2_i.pptx
PPTX
Analysis of Algorithm - Binary Search.pptx
PPTX
Data Structures Unit 2 FINAL presentation.pptx
PPTX
Searching techniques in Data Structure And Algorithm
PPTX
Searching searching in in arrays arrays.pptx
PDF
linear search and binary search
PPTX
an Introduction to binary search algorithm
PPTX
linear-search-and-binary-search-170418023907.pptx
PDF
IRJET- A Survey on Different Searching Algorithms
PPTX
Linear search-and-binary-search
PDF
Searching Algorithms for students of CS and IT using C++
PPTX
Binary search Algorithm
PDF
PPTX
Dsa – data structure and algorithms searching
PPTX
Binary search algorithm.pptx
Lecture_Oct26.pptx
Algorithm 8th lecture linear & binary search(2).pptx
BINARY SEARCH - A - DATA STRUCTURE AND ALGORITHM.pdf
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Data operatons & searching and sorting algorithms
unit II_2_i.pptx
Analysis of Algorithm - Binary Search.pptx
Data Structures Unit 2 FINAL presentation.pptx
Searching techniques in Data Structure And Algorithm
Searching searching in in arrays arrays.pptx
linear search and binary search
an Introduction to binary search algorithm
linear-search-and-binary-search-170418023907.pptx
IRJET- A Survey on Different Searching Algorithms
Linear search-and-binary-search
Searching Algorithms for students of CS and IT using C++
Binary search Algorithm
Dsa – data structure and algorithms searching
Binary search algorithm.pptx
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
Teaching material agriculture food technology
PPTX
A Presentation on Artificial Intelligence
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Machine Learning_overview_presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Approach and Philosophy of On baking technology
PPTX
Tartificialntelligence_presentation.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology
A Presentation on Artificial Intelligence
Digital-Transformation-Roadmap-for-Companies.pptx
Assigned Numbers - 2025 - Bluetooth® Document
Machine Learning_overview_presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
SOPHOS-XG Firewall Administrator PPT.pptx
Spectral efficient network and resource selection model in 5G networks
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
Getting Started with Data Integration: FME Form 101
Approach and Philosophy of On baking technology
Tartificialntelligence_presentation.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing

Presentation

  • 1. OBJECT- ORIENTED PROGRAMING Name: Zohaib Arif Roll no.: 6823 Semester: 2nd Department of Information & Technology
  • 3. Searching in array  Sequential search  Binary search
  • 4. CONTENTS: • Introduction • Sequential search • Binary search • Compression • Efficiency • Conclusion
  • 5. INTRODUCTION: • Array • Search • Search in array i. Sequential search ii. Binary search
  • 6. SEQUENTIAL SEARCH: Algorithm involves checking all the element of array(or any structure) one by one and in sequence until the desired result is found.
  • 7. This algorithm follows the following steps to search a value in array. • Visit the first element of the array and compare its value with required value. • If the value of array matches with the desired value, the search is complete. • If the value of array doesn`t match, move to next element and repeat same process. Algorithm: for(i=0; i<n; i++) if(arr[i]==n) return (i); else return (-1);
  • 8. BINARY SEARCH: The binary search algorithm begins by comparing the target value to value of the middle element of the sorted array and then move upper or lower half. This process repeated until the required number is not found.
  • 9. This algorithm follows the following steps to search a value in array. • It locates the middle element of array and compares with the search number. • If they are equal, search is successful and the index of middle element is returned. • If they are not equal, it reduces the search to half of the array. • If the search number is less than the middle element, it searches the first half of array. Otherwise it searches the second half of the array. Algorithm: low =0; hi=n-1; while(low<=hi)2 { mid =(low +hi) if (arr[mid]==n) return(mid); if(n<arr[mid]) hi=mid-1; else low=mid-1; } return(-1);
  • 10. Linear search • Sorted array is not necessary. • It is not quicker method. • Average speed of linear search is very slow then binary search. • Programing code make short when linear search is use. Binary search • Sorted array is necessary. • It is quicker method. • Average speed of binary search is very fast then linear search. • Programing code make big when linear search is use. COMPARISON:
  • 11. EFFICIENCY: Both search has its won benefit but each comparison in binary reduces the number of possible candidates by a factor of 2. thus maximum number of key comparison is approximately long with bases 2.
  • 12. CONCLUSION: • Searching is an important function in computer science. When data set become larger and larger good search algorithms will become more important. Linear search is not more efficient then binary search because we want our work do rapidly and average comparison of linear search make more efficient then binary search.