1 / 33

Binary search in Python using recursion

Board: CBSE<br>Class: 12<br>Concept: Binary Search using recursion in Python<br>Subject : Python

Download Presentation

Binary search in Python using recursion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GVK CHINMAYA VIDYALAYA GVK CHINMAYA VIDYALAYA SENIOR SECONDARY SCHOOL SENIOR SECONDARY SCHOOL Kothuru, Indukurupet, SPS Nellore Binary Search Class: 12 Subject: Python Teacher: C Vijaya Kumar B.Tech,MBA

  2. MID HIGH LOW 2 3 4 10 40 high>=low: 4>=0 TRUE mid=2

  3. MID LOW HIGH 2 3 4 10 40 If arr[mid]==10: arr[2]==10: 4 = 10 FALSE

  4. LOW HIGH MID 2 3 4 10 40 Elif arr[mid]>x: arr[2]>10: 4>10: FALSE

  5. LOW HIGH 2 3 4 10 40 binary(arr,3,4,10)

  6. HIGH LOW,MID 2 3 4 10 40 binary(arr,3,4,10) If high>=low: 4>=3: TRUE mid=3

  7. LOW and MID HIGH 2 3 4 10 40 arr[3]==10 TRUE

  8. LOW and MID HIGH 2 3 4 10 40 Mid value is returned here

  9. LOW and MID HIGH 2 3 4 10 40 result=3

  10. LOW and MID HIGH 2 3 4 10 40 If 3 not equal to -1: Item found

  11. Lets us see the flow of execution of item not found in the same binary search

  12. HIGH LOW 2 3 4 10 40 def binary(arr,0,4,41):

  13. HIGH MID LOW 2 3 4 10 40 If 4>=0: TRUE mid=2

  14. HIGH MID LOW 2 3 4 10 40 If 4==41: False

  15. HIGH MID LOW 2 3 4 10 40 elif 4 > 41: False

  16. HIGH MID LOW 2 3 4 10 40 binary(arr,3,4,41):

  17. HIGH LOW 2 3 4 10 40 binary(arr,3,4,41):

  18. HIGH LOW and MID 2 3 4 10 40 If 4 > 3: TRUE mid=3

  19. HIGH LOW and MID 2 3 4 10 40 elif 10 > 41: FALSE

  20. HIGH LOW and MID 2 3 4 10 40 binary(arr,4,4,41)

  21. LOW and HIGH 2 3 4 10 40 binary(arr,4,4,41)

  22. MID,LOW and HIGH 2 3 4 10 40 If 4 >= 4: TRUE Mid = 4

  23. MID,LOW and HIGH 2 3 4 10 40 if 40 == 41: FALSE

  24. MID,LOW and HIGH 2 3 4 10 40 elif 40 > 41: FALSE

  25. MID,LOW and HIGH 2 3 4 10 40 binary (arr,5,4,41):

  26. HIGH 2 3 4 10 40 binary (arr,5,4,41): Low = 5 High = 4 X = 41

  27. HIGH 2 3 4 10 40 If 4>=5: FALSE

  28. HIGH 2 3 4 10 40 Return -1

  29. HIGH 2 3 4 10 40 Return -1 (Third Recursive Call)

  30. HIGH 2 3 4 10 40 Return -1 (Second recursive call)

  31. HIGH 2 3 4 10 40 Return -1 (First recursive call)

  32. HIGH 2 3 4 10 40 Result = -1

  33. HIGH 2 3 4 10 40 If False: Else print(“element not present in array”)

More Related