SlideShare a Scribd company logo
Chapter 6Chapter 6
searChingsearChing
01/31/18 BY MS. SHAISTA QADIR 1
PRESENTED BY
Shaista Qadir
Lecturer king khalid university
COntentsCOntents
 searChing
 seQUentiaL searCh
 exampLe
 aLgOrithm
 prOgram LOgiC
 BinarY searCh
 exampLe
 aLgOrithm
 prOgram LOgiC
01/31/18 BY MS. SHAISTA QADIR 2
searChingsearChing
01/31/18 BY MS. SHAISTA QADIR 3
 Computer systems are often used to store large amounts of
data.
 Sometimes data must be retrieved from storage based on a
searching criteria.
 Efficient storage of data to facilitate fast searching.
seQUentiaL searChseQUentiaL searCh
01/31/18 BY MS. SHAISTA QADIR 4
 The sequential search (also called the Linear Search) is the
simplest search algorithm.
 It is also the least efficient.
 It simply examines each element sequentially, starting with
the first element, until it finds the
 key element or it reaches the end of the array.
 Application: To search a person in the train
SEQUENTIAL SEARCH ExAmpLESEQUENTIAL SEARCH ExAmpLE
01/31/18 BY MS. SHAISTA QADIR 5
 Example:
 Consider an array with the following numbers:
SEQUENTIAL SEARCHSEQUENTIAL SEARCH
ALGORITHmALGORITHm
01/31/18 BY MS. SHAISTA QADIR 6
 ALGORITHM:
(Postcondition: either the index i is returned where si = x,
or –1 is returned.)
1. Repeat steps 2–3, for i = 0 to n – 1.
2. If si = x, return i .
3. Return –1.
SEQUENTIAL SEARCH pROGRAmSEQUENTIAL SEARCH pROGRAm
LOGICLOGIC
01/31/18 BY MS. SHAISTA QADIR 7
 PROGRAM LOGIC:
public int seqsearch(int [ ]arr, int x)
{
for(int i=0; i< arr.length; i++)
if(arr [ i ] == x)
return i;
return -1;
}
 Time Complexity of Sequential search algorithm is: O(n)3.
BINARY SEARCHBINARY SEARCH
01/31/18 BY MS. SHAISTA QADIR 8
 The binary search is the standard algorithm for searching
through a sorted sequence.
 It is much more efficient than the sequential search.
 It repeatedly divides the sequence in two, each time
restricting the search to the half that would contain the
element
 Application: Binary search is used to search a word in a
dictionary.
BINARY SEARCH ExAmplEBINARY SEARCH ExAmplE
01/31/18 BY MS. SHAISTA QADIR 9
 Example: Condition : The array must be sorted.
 Consider an array with the following numbers:
 Divide-and-Conquer Strategy
 Search for the number 16.
 Calculate: mid=(First + last)/2
BINARY SEARCH ExAmplEBINARY SEARCH ExAmplE
01/31/18 BY MS. SHAISTA QADIR 10
 Example: Condition : The array must be sorted.
 Return the position of 16 which is 3
BINARY SEARCH AlGORITHmBINARY SEARCH AlGORITHm
01/31/18 BY MS. SHAISTA QADIR 11
 ALGORITHM:
 (Precondition:1. s={s0, s1, . . ., sn–1} is a sorted sequence of
n values of the same type as x.either the index i is returned
where si = x, or –1 is returned.)
1. Let ss be a subsequence of the sequence s, initially set
equal to s.
2. If the subsequence ss is empty, return –1.
3. Let si be the middle element of ss.
4. If si = x, return its index i .
5. If si < x, repeat steps 2–6on the subsequence that lies
above si.
6. Repeat st
BINARY SEARCH pROGRAmBINARY SEARCH pROGRAm
lOGIClOGIC
01/31/18 BY MS. SHAISTA QADIR 12
 PROGRAM LOGIC:
public static int binarysearch(int[ ] a, int x) {
int lo = 0; int hi = a.length;
while (lo < hi) {
int i = (lo + hi) / 2;
if (a[i] == x)
return i;
else if (a[i] < x)
lo = i+1;
else hi = I; }
return -1; }
 Time Complexity of binary search algorithm is: O(logn)
01/31/18 BY MS. SHAISTA QADIR 13
THANK YOUTHANK YOU

More Related Content

Similar to Searching

A novel algorithm for mining closed sequential patterns
A novel algorithm for mining closed sequential patternsA novel algorithm for mining closed sequential patterns
A novel algorithm for mining closed sequential patterns
IJDKP
 
Fast Sequential Rule Mining
Fast Sequential Rule MiningFast Sequential Rule Mining
Fast Sequential Rule Mining
ijsrd.com
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic 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 Algorithms
IRJET Journal
 
Graph based Approach and Clustering of Patterns (GACP) for Sequential Pattern...
Graph based Approach and Clustering of Patterns (GACP) for Sequential Pattern...Graph based Approach and Clustering of Patterns (GACP) for Sequential Pattern...
Graph based Approach and Clustering of Patterns (GACP) for Sequential Pattern...
AshishDPatel1
 
Mining Top-k Closed Sequential Patterns in Sequential Databases
Mining Top-k Closed Sequential Patterns in Sequential Databases Mining Top-k Closed Sequential Patterns in Sequential Databases
Mining Top-k Closed Sequential Patterns in Sequential Databases
IOSR Journals
 
Mining closed sequential patterns in large sequence databases
Mining closed sequential patterns in large sequence databasesMining closed sequential patterns in large sequence databases
Mining closed sequential patterns in large sequence databases
ijdms
 
Aslam
AslamAslam
A New Extraction Optimization Approach to Frequent 2 Item sets
A New Extraction Optimization Approach to Frequent 2 Item setsA New Extraction Optimization Approach to Frequent 2 Item sets
A New Extraction Optimization Approach to Frequent 2 Item sets
ijcsa
 
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETSA NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
ijcsa
 
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETSA NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
ijcsa
 
Review Over Sequential Rule Mining
Review Over Sequential Rule MiningReview Over Sequential Rule Mining
Review Over Sequential Rule Mining
ijsrd.com
 
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
Aftabali702240
 
Sequential Pattern Mining Methods: A Snap Shot
Sequential Pattern Mining Methods: A Snap ShotSequential Pattern Mining Methods: A Snap Shot
Sequential Pattern Mining Methods: A Snap Shot
IOSR Journals
 
Clustering and Visualisation using R programming
Clustering and Visualisation using R programmingClustering and Visualisation using R programming
Clustering and Visualisation using R programming
Nixon Mendez
 
Sequential Pattern Tree Mining
Sequential Pattern Tree MiningSequential Pattern Tree Mining
Sequential Pattern Tree Mining
IOSR Journals
 
Algorithm - Mergesort & Quicksort
Algorithm - Mergesort & Quicksort Algorithm - Mergesort & Quicksort
Algorithm - Mergesort & Quicksort
Varendra University Rajshahi-bangladesh
 
A survey paper on sequence pattern mining with incremental
A survey paper on sequence pattern mining with incrementalA survey paper on sequence pattern mining with incremental
A survey paper on sequence pattern mining with incremental
Alexander Decker
 
A survey paper on sequence pattern mining with incremental
A survey paper on sequence pattern mining with incrementalA survey paper on sequence pattern mining with incremental
A survey paper on sequence pattern mining with incremental
Alexander Decker
 
MMseqs NGS 2014
MMseqs NGS 2014MMseqs NGS 2014
MMseqs NGS 2014
Martin Steinegger
 

Similar to Searching (20)

A novel algorithm for mining closed sequential patterns
A novel algorithm for mining closed sequential patternsA novel algorithm for mining closed sequential patterns
A novel algorithm for mining closed sequential patterns
 
Fast Sequential Rule Mining
Fast Sequential Rule MiningFast Sequential Rule Mining
Fast Sequential Rule Mining
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
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
 
Graph based Approach and Clustering of Patterns (GACP) for Sequential Pattern...
Graph based Approach and Clustering of Patterns (GACP) for Sequential Pattern...Graph based Approach and Clustering of Patterns (GACP) for Sequential Pattern...
Graph based Approach and Clustering of Patterns (GACP) for Sequential Pattern...
 
Mining Top-k Closed Sequential Patterns in Sequential Databases
Mining Top-k Closed Sequential Patterns in Sequential Databases Mining Top-k Closed Sequential Patterns in Sequential Databases
Mining Top-k Closed Sequential Patterns in Sequential Databases
 
Mining closed sequential patterns in large sequence databases
Mining closed sequential patterns in large sequence databasesMining closed sequential patterns in large sequence databases
Mining closed sequential patterns in large sequence databases
 
Aslam
AslamAslam
Aslam
 
A New Extraction Optimization Approach to Frequent 2 Item sets
A New Extraction Optimization Approach to Frequent 2 Item setsA New Extraction Optimization Approach to Frequent 2 Item sets
A New Extraction Optimization Approach to Frequent 2 Item sets
 
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETSA NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
 
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETSA NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
A NEW EXTRACTION OPTIMIZATION APPROACH TO FREQUENT 2 ITEMSETS
 
Review Over Sequential Rule Mining
Review Over Sequential Rule MiningReview Over Sequential Rule Mining
Review Over Sequential Rule Mining
 
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
 
Sequential Pattern Mining Methods: A Snap Shot
Sequential Pattern Mining Methods: A Snap ShotSequential Pattern Mining Methods: A Snap Shot
Sequential Pattern Mining Methods: A Snap Shot
 
Clustering and Visualisation using R programming
Clustering and Visualisation using R programmingClustering and Visualisation using R programming
Clustering and Visualisation using R programming
 
Sequential Pattern Tree Mining
Sequential Pattern Tree MiningSequential Pattern Tree Mining
Sequential Pattern Tree Mining
 
Algorithm - Mergesort & Quicksort
Algorithm - Mergesort & Quicksort Algorithm - Mergesort & Quicksort
Algorithm - Mergesort & Quicksort
 
A survey paper on sequence pattern mining with incremental
A survey paper on sequence pattern mining with incrementalA survey paper on sequence pattern mining with incremental
A survey paper on sequence pattern mining with incremental
 
A survey paper on sequence pattern mining with incremental
A survey paper on sequence pattern mining with incrementalA survey paper on sequence pattern mining with incremental
A survey paper on sequence pattern mining with incremental
 
MMseqs NGS 2014
MMseqs NGS 2014MMseqs NGS 2014
MMseqs NGS 2014
 

More from Shaista Qadir

Lecture 4
Lecture 4Lecture 4
Lecture 4
Shaista Qadir
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
Shaista Qadir
 
Sorting
SortingSorting
Sorting
Shaista Qadir
 
Queue
QueueQueue
linked list
linked listlinked list
linked list
Shaista Qadir
 
Complexity Analysis
Complexity Analysis Complexity Analysis
Complexity Analysis
Shaista Qadir
 

More from Shaista Qadir (6)

Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Sorting
SortingSorting
Sorting
 
Queue
QueueQueue
Queue
 
linked list
linked listlinked list
linked list
 
Complexity Analysis
Complexity Analysis Complexity Analysis
Complexity Analysis
 

Recently uploaded

Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
FODUU
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
Claudio Di Ciccio
 

Recently uploaded (20)

Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
 

Searching

  • 1. Chapter 6Chapter 6 searChingsearChing 01/31/18 BY MS. SHAISTA QADIR 1 PRESENTED BY Shaista Qadir Lecturer king khalid university
  • 2. COntentsCOntents  searChing  seQUentiaL searCh  exampLe  aLgOrithm  prOgram LOgiC  BinarY searCh  exampLe  aLgOrithm  prOgram LOgiC 01/31/18 BY MS. SHAISTA QADIR 2
  • 3. searChingsearChing 01/31/18 BY MS. SHAISTA QADIR 3  Computer systems are often used to store large amounts of data.  Sometimes data must be retrieved from storage based on a searching criteria.  Efficient storage of data to facilitate fast searching.
  • 4. seQUentiaL searChseQUentiaL searCh 01/31/18 BY MS. SHAISTA QADIR 4  The sequential search (also called the Linear Search) is the simplest search algorithm.  It is also the least efficient.  It simply examines each element sequentially, starting with the first element, until it finds the  key element or it reaches the end of the array.  Application: To search a person in the train
  • 5. SEQUENTIAL SEARCH ExAmpLESEQUENTIAL SEARCH ExAmpLE 01/31/18 BY MS. SHAISTA QADIR 5  Example:  Consider an array with the following numbers:
  • 6. SEQUENTIAL SEARCHSEQUENTIAL SEARCH ALGORITHmALGORITHm 01/31/18 BY MS. SHAISTA QADIR 6  ALGORITHM: (Postcondition: either the index i is returned where si = x, or –1 is returned.) 1. Repeat steps 2–3, for i = 0 to n – 1. 2. If si = x, return i . 3. Return –1.
  • 7. SEQUENTIAL SEARCH pROGRAmSEQUENTIAL SEARCH pROGRAm LOGICLOGIC 01/31/18 BY MS. SHAISTA QADIR 7  PROGRAM LOGIC: public int seqsearch(int [ ]arr, int x) { for(int i=0; i< arr.length; i++) if(arr [ i ] == x) return i; return -1; }  Time Complexity of Sequential search algorithm is: O(n)3.
  • 8. BINARY SEARCHBINARY SEARCH 01/31/18 BY MS. SHAISTA QADIR 8  The binary search is the standard algorithm for searching through a sorted sequence.  It is much more efficient than the sequential search.  It repeatedly divides the sequence in two, each time restricting the search to the half that would contain the element  Application: Binary search is used to search a word in a dictionary.
  • 9. BINARY SEARCH ExAmplEBINARY SEARCH ExAmplE 01/31/18 BY MS. SHAISTA QADIR 9  Example: Condition : The array must be sorted.  Consider an array with the following numbers:  Divide-and-Conquer Strategy  Search for the number 16.  Calculate: mid=(First + last)/2
  • 10. BINARY SEARCH ExAmplEBINARY SEARCH ExAmplE 01/31/18 BY MS. SHAISTA QADIR 10  Example: Condition : The array must be sorted.  Return the position of 16 which is 3
  • 11. BINARY SEARCH AlGORITHmBINARY SEARCH AlGORITHm 01/31/18 BY MS. SHAISTA QADIR 11  ALGORITHM:  (Precondition:1. s={s0, s1, . . ., sn–1} is a sorted sequence of n values of the same type as x.either the index i is returned where si = x, or –1 is returned.) 1. Let ss be a subsequence of the sequence s, initially set equal to s. 2. If the subsequence ss is empty, return –1. 3. Let si be the middle element of ss. 4. If si = x, return its index i . 5. If si < x, repeat steps 2–6on the subsequence that lies above si. 6. Repeat st
  • 12. BINARY SEARCH pROGRAmBINARY SEARCH pROGRAm lOGIClOGIC 01/31/18 BY MS. SHAISTA QADIR 12  PROGRAM LOGIC: public static int binarysearch(int[ ] a, int x) { int lo = 0; int hi = a.length; while (lo < hi) { int i = (lo + hi) / 2; if (a[i] == x) return i; else if (a[i] < x) lo = i+1; else hi = I; } return -1; }  Time Complexity of binary search algorithm is: O(logn)
  • 13. 01/31/18 BY MS. SHAISTA QADIR 13 THANK YOUTHANK YOU