Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3939668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:19:37+00:00 2026-05-20T00:19:37+00:00

import math def BinarySearch( A , val , low , high ): if high

  • 0
import math 

def BinarySearch( A , val , low , high ):
    if high < low :
        return -1 #not found 
    mid = low + (high - low ) /2 
    if A[mid] > val:
        return BinarySearch(A,val , low , high )
    if A[mid] < val :
        return BinarySearch(A,val,low,high)
    else: 
        return mid #found 


A = [ 12 , 23 , 2 , 33 , 123 , 4 , 5 , 2 , 54 , 555 , 21 ]
BinarySearch( A , 0 , 0, 10)

I tried to do Binary Search without using the bisect Module . But it gives an error such as this

 File "doubtrob.py", line 8, in BinarySearch
    return BinarySearch(A,val , low , high )
RuntimeError: maximum recursion depth exceeded
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:19:38+00:00Added an answer on May 20, 2026 at 12:19 am

    You are using exactly the same search space on each iteration. Also, you need to stop when high – low < 2, otherwise mid will eventually equal low, and you might still be stuck in an infinite loop.

    As an aside, you can get mid more simply: (low + high)/2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it,
I wrote the following program to prime factorize a number: import math def prime_factorize(x,li=[]):
Any help? I have the following: import math def cosine (a): x = (a
When I run the following sample: def a(): exec('import math') b() def b(): print
so I have def gcd(a,b): if a == 0: return b while b !=
I have read the answer to my question about scala.math.Integral but I do not
I've written this basic program in Scala : import scala.collection.mutable.HashMap object HelloWorld { val
import sys words = { 1 : 'one', 2 : 'two', 3 : 'three',
I need to import a csv file into Firebird and I've spent a couple
How can you import a foxpro DBF file in SQL Server?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.