SlideShare a Scribd company logo
1 of 9
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
Binary Search
lo
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
hi
Binary Search
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
lo hi
mid
Binary Search
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
lo hi
Binary Search
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
lo mid hi
Binary Search
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
lo hi
Binary Search
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
lo hi
mid
Binary Search
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
lo
hi
Binary Search
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
lo
hi
mid
Binary Search
Binary search. Given value and sorted array a[], find index i
such that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo]  value  a[hi].
Ex. Binary search for 33.
8
2
1 3 4 6
5 7 10
9 11 12 14
13
0
64
14
13 25 33 51
43 53 84
72 93 95 97
96
6
lo
hi
mid

More Related Content

Similar to demo-bsearch.ppt mission Sk it depertment

Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
Hashing in DS
Hashing in DSHashing in DS
Hashing in DSAnu Asima
 
06 Analysis of Algorithms: Sorting in Linear Time
06 Analysis of Algorithms:  Sorting in Linear Time06 Analysis of Algorithms:  Sorting in Linear Time
06 Analysis of Algorithms: Sorting in Linear TimeAndres Mendez-Vazquez
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32ecomputernotes
 
Data Structure Searching.pptx
Data Structure Searching.pptxData Structure Searching.pptx
Data Structure Searching.pptxSourabhTaneja4
 

Similar to demo-bsearch.ppt mission Sk it depertment (8)

Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Hashing in DS
Hashing in DSHashing in DS
Hashing in DS
 
06 Analysis of Algorithms: Sorting in Linear Time
06 Analysis of Algorithms:  Sorting in Linear Time06 Analysis of Algorithms:  Sorting in Linear Time
06 Analysis of Algorithms: Sorting in Linear Time
 
Search techniques and Hashing
Search techniques and HashingSearch techniques and Hashing
Search techniques and Hashing
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
 
Data Structure Searching.pptx
Data Structure Searching.pptxData Structure Searching.pptx
Data Structure Searching.pptx
 

Recently uploaded

100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Onlineanilsa9823
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxfirstjob4
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Delhi Call girls
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girlCall Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girlkumarajju5765
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...shambhavirathore45
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 

Recently uploaded (20)

100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girlCall Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 

demo-bsearch.ppt mission Sk it depertment

  • 1. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 Binary Search lo Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. hi
  • 2. Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 lo hi mid
  • 3. Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 lo hi
  • 4. Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 lo mid hi
  • 5. Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 lo hi
  • 6. Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 lo hi mid
  • 7. Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 lo hi
  • 8. Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 lo hi mid
  • 9. Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant. Algorithm maintains a[lo]  value  a[hi]. Ex. Binary search for 33. 8 2 1 3 4 6 5 7 10 9 11 12 14 13 0 64 14 13 25 33 51 43 53 84 72 93 95 97 96 6 lo hi mid