2 Replies - 2129 Views - Last Post: 05 February 2012 - 03:38 PM

#1 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,235
  • Joined: 14-September 07

Recursive Binary Sort (Python)

Posted 20 July 2008 - 12:40 PM

Description: Implement within a script to find values inside a sorted list.Traverses a sorted list to find values
# Recursive Binary Search
# KYA
# 7-20-08

def binarySearch(theList, value, low, high):
    if high < low:
        return -1
    mid = (low + high)/2
    if theList[mid] > value:
        return binarySearch(theList, value, low, mid-1)
    elif theList[mid] < value:
        return binarySearch(theList, value, mid+1, high)
    else:
        return 1


Is This A Good Question/Topic? 0
  • +

Replies To: Recursive Binary Sort (Python)

#2 sptcunited   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 22-January 11

Re: Recursive Binary Sort (Python)

Posted 05 February 2012 - 02:31 PM

could someone show an example output of this?
Was This Post Helpful? 0
  • +
  • -

#3 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,235
  • Joined: 14-September 07

Re: Recursive Binary Sort (Python)

Posted 05 February 2012 - 03:38 PM

1: found -1: not found
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1