GVK CHINMAYA VIDYALAYA
SENIOR SECONDARY SCHOOL
Kothuru, Indukurupet, SPS Nellore
Binary Search
Class: 12 Subject: Python Teacher: C Vijaya Kumar
B.Tech,MBA
2 3 4 10 40
high>=low:
4>=0
TRUE
mid=2
LOW HIGHMID
2 3 4 10 40
If arr[mid]==10:
arr[2]==10:
4 = 10
FALSE
LOW HIGHMID
2 3 4 10 40
Elif arr[mid]>x:
arr[2]>10:
4>10:
FALSE
LOW HIGHMID
2 3 4 10 40
binary(arr,3,4,10)
LOW HIGH
2 3 4 10 40
binary(arr,3,4,10)
If high>=low:
4>=3:
TRUE
mid=3
LOW,MID HIGH
2 3 4 10 40
arr[3]==10
TRUE
LOW and MID HIGH
2 3 4 10 40
Mid value is
returned here
LOW and MID HIGH
2 3 4 10 40
result=3
LOW and MID HIGH
2 3 4 10 40
If 3 not equal to -1:
Item found
LOW and MID HIGH
Lets us see the flow of execution of item not found in the same binary search
2 3 4 10 40
HIGHLOW
def binary(arr,0,4,41):
2 3 4 10 40
HIGHLOW
If 4>=0:
TRUE
mid=2
MID
2 3 4 10 40
HIGHLOW
If 4==41:
False
MID
2 3 4 10 40
HIGHLOW
elif 4 > 41:
False
MID
2 3 4 10 40
HIGHLOW
binary(arr,3,4,41):
MID
2 3 4 10 40
HIGHLOW
binary(arr,3,4,41):
2 3 4 10 40
HIGHLOW and MID
If 4 > 3:
TRUE
mid=3
2 3 4 10 40
HIGHLOW and MID
elif 10 > 41:
FALSE
2 3 4 10 40
HIGHLOW and MID
binary(arr,4,4,41)
2 3 4 10 40
LOW and HIGH
binary(arr,4,4,41)
2 3 4 10 40
MID,LOW and HIGH
If 4 >= 4:
TRUE
Mid = 4
2 3 4 10 40
MID,LOW and HIGH
if 40 == 41:
FALSE
2 3 4 10 40
MID,LOW and HIGH
elif 40 > 41:
FALSE
2 3 4 10 40
MID,LOW and HIGH
binary (arr,5,4,41):
2 3 4 10 40
HIGH
binary (arr,5,4,41):
Low = 5
High = 4
X = 41
2 3 4 10 40
HIGH
If 4>=5:
FALSE
2 3 4 10 40
HIGH
Return -1
2 3 4 10 40
HIGH
Return -1 (Third Recursive Call)
2 3 4 10 40
HIGH
Return -1 (Second recursive call)
2 3 4 10 40
HIGH
Return -1 (First recursive call)
2 3 4 10 40
HIGH
Result = -1
2 3 4 10 40
HIGH
If False:
Else
print(“element not present in array”)

More Related Content

PPTX
1.2 order of operations part 1
PDF
Lesson 1 student notes
PPTX
Integers
PPTX
Integers Class 7
PPTX
Integer operations
PDF
Integers best ppt
PPTX
Integers
PPTX
1.2 order of operations part 1
Lesson 1 student notes
Integers
Integers Class 7
Integer operations
Integers best ppt
Integers

What's hot (13)

PPTX
squares and square roots
PPT
Chapter 3 Solving By Graph
PPT
PPT
Chapter 2
ODP
Integers slideshow
PPT
Multipying integers
PPT
Add-subtract of integers
PPTX
Integers and Operation of Integers
PPTX
Integers
PPTX
Integers
PPT
PPT
Squaring of numbers
PPTX
squares and square roots
Chapter 3 Solving By Graph
Chapter 2
Integers slideshow
Multipying integers
Add-subtract of integers
Integers and Operation of Integers
Integers
Integers
Squaring of numbers
Ad

More from chinthala Vijaya Kumar (11)

PDF
GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...
PDF
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
PDF
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
PDF
Inserting an element in a sorted array using traditional algorithm
PDF
Linear search python CBSE Class 12
PDF
Data visualization pyplot
PDF
Data handling CBSE PYTHON CLASS 11
PDF
PDF
Python Fundamentals Class 11
PDF
File handling CBSE CLASS 12
PDF
Recursion CBSE Class 12
GVKCV Computer Science(083) Pre board sample paper 2 Class 12 (20-21) with so...
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
Inserting an element in a sorted array using traditional algorithm
Linear search python CBSE Class 12
Data visualization pyplot
Data handling CBSE PYTHON CLASS 11
Python Fundamentals Class 11
File handling CBSE CLASS 12
Recursion CBSE Class 12
Ad

Recently uploaded (20)

PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
Virtual and Augmented Reality in Current Scenario
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Empowerment Technology for Senior High School Guide
PDF
International_Financial_Reporting_Standa.pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Trump Administration's workforce development strategy
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Virtual and Augmented Reality in Current Scenario
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
History, Philosophy and sociology of education (1).pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Environmental Education MCQ BD2EE - Share Source.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Weekly quiz Compilation Jan -July 25.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Empowerment Technology for Senior High School Guide
International_Financial_Reporting_Standa.pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Trump Administration's workforce development strategy
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf

Binary search in Python using recursion

  • 1. GVK CHINMAYA VIDYALAYA SENIOR SECONDARY SCHOOL Kothuru, Indukurupet, SPS Nellore Binary Search Class: 12 Subject: Python Teacher: C Vijaya Kumar B.Tech,MBA
  • 2. 2 3 4 10 40 high>=low: 4>=0 TRUE mid=2 LOW HIGHMID
  • 3. 2 3 4 10 40 If arr[mid]==10: arr[2]==10: 4 = 10 FALSE LOW HIGHMID
  • 4. 2 3 4 10 40 Elif arr[mid]>x: arr[2]>10: 4>10: FALSE LOW HIGHMID
  • 5. 2 3 4 10 40 binary(arr,3,4,10) LOW HIGH
  • 6. 2 3 4 10 40 binary(arr,3,4,10) If high>=low: 4>=3: TRUE mid=3 LOW,MID HIGH
  • 7. 2 3 4 10 40 arr[3]==10 TRUE LOW and MID HIGH
  • 8. 2 3 4 10 40 Mid value is returned here LOW and MID HIGH
  • 9. 2 3 4 10 40 result=3 LOW and MID HIGH
  • 10. 2 3 4 10 40 If 3 not equal to -1: Item found LOW and MID HIGH
  • 11. Lets us see the flow of execution of item not found in the same binary search
  • 12. 2 3 4 10 40 HIGHLOW def binary(arr,0,4,41):
  • 13. 2 3 4 10 40 HIGHLOW If 4>=0: TRUE mid=2 MID
  • 14. 2 3 4 10 40 HIGHLOW If 4==41: False MID
  • 15. 2 3 4 10 40 HIGHLOW elif 4 > 41: False MID
  • 16. 2 3 4 10 40 HIGHLOW binary(arr,3,4,41): MID
  • 17. 2 3 4 10 40 HIGHLOW binary(arr,3,4,41):
  • 18. 2 3 4 10 40 HIGHLOW and MID If 4 > 3: TRUE mid=3
  • 19. 2 3 4 10 40 HIGHLOW and MID elif 10 > 41: FALSE
  • 20. 2 3 4 10 40 HIGHLOW and MID binary(arr,4,4,41)
  • 21. 2 3 4 10 40 LOW and HIGH binary(arr,4,4,41)
  • 22. 2 3 4 10 40 MID,LOW and HIGH If 4 >= 4: TRUE Mid = 4
  • 23. 2 3 4 10 40 MID,LOW and HIGH if 40 == 41: FALSE
  • 24. 2 3 4 10 40 MID,LOW and HIGH elif 40 > 41: FALSE
  • 25. 2 3 4 10 40 MID,LOW and HIGH binary (arr,5,4,41):
  • 26. 2 3 4 10 40 HIGH binary (arr,5,4,41): Low = 5 High = 4 X = 41
  • 27. 2 3 4 10 40 HIGH If 4>=5: FALSE
  • 28. 2 3 4 10 40 HIGH Return -1
  • 29. 2 3 4 10 40 HIGH Return -1 (Third Recursive Call)
  • 30. 2 3 4 10 40 HIGH Return -1 (Second recursive call)
  • 31. 2 3 4 10 40 HIGH Return -1 (First recursive call)
  • 32. 2 3 4 10 40 HIGH Result = -1
  • 33. 2 3 4 10 40 HIGH If False: Else print(“element not present in array”)